Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit aa4e32d

Browse files
committed
fix: use exact parameter instead of first during manga match
1 parent b7bd37f commit aa4e32d

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

src/server/utils/mangal.ts

+34-28
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export const getMangaPath = (libraryPath: string, title: string) => path.resolve
7676

7777
export const getAvailableSources = async () => {
7878
try {
79-
const { stdout, command } = await execa('mangal', ['sources', 'list', '-r']);
80-
logger.info(`Get available sources with following command: ${command}`);
79+
const { stdout, escapedCommand } = await execa('mangal', ['sources', 'list', '-r']);
80+
logger.info(`Get available sources with following command: ${escapedCommand}`);
8181
return stdout
8282
.split('\n')
8383
.map((s) => s.trim())
@@ -112,6 +112,7 @@ const excludedConfigs = [
112112
'downloader.create_volume_dir',
113113
'downloader.default_sources',
114114
'downloader.path',
115+
'downloader.stop_on_error',
115116
'metadata.comic_info_xml',
116117
'metadata.fetch_anilist',
117118
'metadata.series_json',
@@ -120,8 +121,8 @@ const excludedConfigs = [
120121

121122
export const getMangalConfig = async (): Promise<MangalConfig[]> => {
122123
try {
123-
const { stdout, command } = await execa('mangal', ['config', 'info', '-j']);
124-
logger.info(`Getting mangal config with following command: ${command}`);
124+
const { stdout, escapedCommand } = await execa('mangal', ['config', 'info', '-j']);
125+
logger.info(`Getting mangal config with following command: ${escapedCommand}`);
125126
const result = JSON.parse(stdout) as MangalConfig[];
126127

127128
return result.filter((item) => !excludedConfigs.includes(item.key) && item.type !== '[]string');
@@ -134,40 +135,40 @@ export const getMangalConfig = async (): Promise<MangalConfig[]> => {
134135

135136
export const setMangalConfig = async (key: string, value: string | boolean | number | string[]) => {
136137
try {
137-
const { command } = await execa('mangal', ['config', 'set', '--key', key, '--value', `${value}`]);
138-
logger.info(`set mangal config with following command: ${command}`);
138+
const { escapedCommand } = await execa('mangal', ['config', 'set', '--key', key, '--value', `${value}`]);
139+
logger.info(`set mangal config with following command: ${escapedCommand}`);
139140
} catch (err) {
140141
logger.error(`Failed to set mangal config. err: ${err}`);
141142
}
142143
};
143144

144145
export const bindTitleToAnilistId = async (title: string, anilistId: string) => {
145146
try {
146-
const { command } = await execa('mangal', ['inline', 'anilist', 'set', '--name', title, '--id', anilistId]);
147-
logger.info(`Bind manga to anilist id with following command: ${command}`);
147+
const { escapedCommand } = await execa('mangal', ['inline', 'anilist', 'set', '--name', title, '--id', anilistId]);
148+
logger.info(`Bind manga to anilist id with following command: ${escapedCommand}`);
148149
} catch (err) {
149150
logger.error(`Failed to bind manga to anilist id. err: ${err}`);
150151
}
151152
};
152153

153154
export const updateExistingMangaMetadata = async (libraryPath: string, title: string) => {
154155
try {
155-
const { command } = await execa('mangal', [
156+
const { escapedCommand } = await execa('mangal', [
156157
'inline',
157158
'anilist',
158159
'update',
159160
'--path',
160161
getMangaPath(libraryPath, title),
161162
]);
162-
logger.info(`Updated existing manga metadata: ${command}`);
163+
logger.info(`Updated existing manga metadata: ${escapedCommand}`);
163164
} catch (err) {
164165
logger.error(`Failed to update existing manga metadata. err: ${err}`);
165166
}
166167
};
167168

168169
export const search = async (source: string, keyword: string): Promise<IOutput> => {
169170
try {
170-
const { stdout, command } = await execa('mangal', [
171+
const { stdout, escapedCommand } = await execa('mangal', [
171172
'inline',
172173
'--source',
173174
source,
@@ -176,7 +177,7 @@ export const search = async (source: string, keyword: string): Promise<IOutput>
176177
keyword,
177178
'-j',
178179
]);
179-
logger.info(`Search manga with following command: ${command}`);
180+
logger.info(`Search manga with following command: ${escapedCommand}`);
180181
return JSON.parse(stdout);
181182
} catch (err) {
182183
logger.error(`Failed to search manga. err: ${err}`);
@@ -189,19 +190,19 @@ export const search = async (source: string, keyword: string): Promise<IOutput>
189190

190191
export const getChaptersFromRemote = async (source: string, title: string): Promise<number[]> => {
191192
try {
192-
const { stdout, command } = await execa('mangal', [
193+
const { stdout, escapedCommand } = await execa('mangal', [
193194
'inline',
194195
'--source',
195196
source,
196197
'--query',
197198
title,
198199
'--manga',
199-
'first',
200+
'exact',
200201
'--chapters',
201202
'all',
202203
'-j',
203204
]);
204-
logger.info(`Get chapters with following command: ${command}`);
205+
logger.info(`Get chapters with following command: ${escapedCommand}`);
205206
const output: IOutput = JSON.parse(stdout);
206207
if (
207208
output &&
@@ -220,20 +221,20 @@ export const getChaptersFromRemote = async (source: string, title: string): Prom
220221

221222
export const getMangaDetail = async (source: string, title: string): Promise<Mangal | undefined> => {
222223
try {
223-
const { stdout, command } = await execa('mangal', [
224+
const { stdout, escapedCommand } = await execa('mangal', [
224225
'inline',
225226
'--source',
226227
source,
227228
'--include-anilist-manga',
228229
'--query',
229230
title,
230231
'--manga',
231-
'first',
232+
'exact',
232233
'--chapters',
233234
'all',
234235
'-j',
235236
]);
236-
logger.info(`Get manga detail with following command: ${command}`);
237+
logger.info(`Get manga detail with following command: ${escapedCommand}`);
237238
const output: IOutput = JSON.parse(stdout);
238239
if (output && output.result.length === 1) {
239240
return output.result[0].mangal;
@@ -253,15 +254,15 @@ export const downloadChapter = async (
253254
): Promise<string> => {
254255
try {
255256
logger.info(`Downloading chapter #${chapterIndex} for ${title} from ${source}`);
256-
const { stdout, stderr, command } = await execa(
257+
const { stdout, stderr, escapedCommand } = await execa(
257258
'mangal',
258-
['inline', '--source', source, '--query', title, '--manga', 'first', '--chapters', `${chapterIndex}`, '-d'],
259+
['inline', '--source', source, '--query', title, '--manga', 'exact', '--chapters', `${chapterIndex}`, '-d'],
259260
{
260261
cwd: libraryPath,
261262
},
262263
);
263264

264-
logger.info(`Download chapter with following command: ${command}`);
265+
logger.info(`Download chapter with following command: ${escapedCommand}`);
265266

266267
if (stderr) {
267268
logger.error(`Failed to download the chapter #${chapterIndex} for ${title}. Err:\n${stderr}`);
@@ -290,13 +291,18 @@ const shouldIncludeFile = (chapterFile: string) => {
290291
};
291292

292293
export const getChapterFromLocal = async (chapterFile: string) => {
293-
const stat = await fs.stat(chapterFile);
294-
return {
295-
index: getChapterIndexFromFile(chapterFile)!,
296-
size: stat.size,
297-
createdAt: stat.birthtime,
298-
fileName: path.basename(chapterFile),
299-
};
294+
try {
295+
const stat = await fs.stat(chapterFile);
296+
return {
297+
index: getChapterIndexFromFile(chapterFile)!,
298+
size: stat.size,
299+
createdAt: stat.birthtime,
300+
fileName: path.basename(chapterFile),
301+
};
302+
} catch (err) {
303+
logger.error(`Error occurred while getting stat from ${chapterFile}: ${err}`);
304+
throw err;
305+
}
300306
};
301307

302308
export const getChaptersFromLocal = async (mangaDir: string): Promise<ChapterFile[]> => {

0 commit comments

Comments
 (0)