@@ -76,8 +76,8 @@ export const getMangaPath = (libraryPath: string, title: string) => path.resolve
76
76
77
77
export const getAvailableSources = async ( ) => {
78
78
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 } ` ) ;
81
81
return stdout
82
82
. split ( '\n' )
83
83
. map ( ( s ) => s . trim ( ) )
@@ -112,6 +112,7 @@ const excludedConfigs = [
112
112
'downloader.create_volume_dir' ,
113
113
'downloader.default_sources' ,
114
114
'downloader.path' ,
115
+ 'downloader.stop_on_error' ,
115
116
'metadata.comic_info_xml' ,
116
117
'metadata.fetch_anilist' ,
117
118
'metadata.series_json' ,
@@ -120,8 +121,8 @@ const excludedConfigs = [
120
121
121
122
export const getMangalConfig = async ( ) : Promise < MangalConfig [ ] > => {
122
123
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 } ` ) ;
125
126
const result = JSON . parse ( stdout ) as MangalConfig [ ] ;
126
127
127
128
return result . filter ( ( item ) => ! excludedConfigs . includes ( item . key ) && item . type !== '[]string' ) ;
@@ -134,40 +135,40 @@ export const getMangalConfig = async (): Promise<MangalConfig[]> => {
134
135
135
136
export const setMangalConfig = async ( key : string , value : string | boolean | number | string [ ] ) => {
136
137
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 } ` ) ;
139
140
} catch ( err ) {
140
141
logger . error ( `Failed to set mangal config. err: ${ err } ` ) ;
141
142
}
142
143
} ;
143
144
144
145
export const bindTitleToAnilistId = async ( title : string , anilistId : string ) => {
145
146
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 } ` ) ;
148
149
} catch ( err ) {
149
150
logger . error ( `Failed to bind manga to anilist id. err: ${ err } ` ) ;
150
151
}
151
152
} ;
152
153
153
154
export const updateExistingMangaMetadata = async ( libraryPath : string , title : string ) => {
154
155
try {
155
- const { command } = await execa ( 'mangal' , [
156
+ const { escapedCommand } = await execa ( 'mangal' , [
156
157
'inline' ,
157
158
'anilist' ,
158
159
'update' ,
159
160
'--path' ,
160
161
getMangaPath ( libraryPath , title ) ,
161
162
] ) ;
162
- logger . info ( `Updated existing manga metadata: ${ command } ` ) ;
163
+ logger . info ( `Updated existing manga metadata: ${ escapedCommand } ` ) ;
163
164
} catch ( err ) {
164
165
logger . error ( `Failed to update existing manga metadata. err: ${ err } ` ) ;
165
166
}
166
167
} ;
167
168
168
169
export const search = async ( source : string , keyword : string ) : Promise < IOutput > => {
169
170
try {
170
- const { stdout, command } = await execa ( 'mangal' , [
171
+ const { stdout, escapedCommand } = await execa ( 'mangal' , [
171
172
'inline' ,
172
173
'--source' ,
173
174
source ,
@@ -176,7 +177,7 @@ export const search = async (source: string, keyword: string): Promise<IOutput>
176
177
keyword ,
177
178
'-j' ,
178
179
] ) ;
179
- logger . info ( `Search manga with following command: ${ command } ` ) ;
180
+ logger . info ( `Search manga with following command: ${ escapedCommand } ` ) ;
180
181
return JSON . parse ( stdout ) ;
181
182
} catch ( err ) {
182
183
logger . error ( `Failed to search manga. err: ${ err } ` ) ;
@@ -189,19 +190,19 @@ export const search = async (source: string, keyword: string): Promise<IOutput>
189
190
190
191
export const getChaptersFromRemote = async ( source : string , title : string ) : Promise < number [ ] > => {
191
192
try {
192
- const { stdout, command } = await execa ( 'mangal' , [
193
+ const { stdout, escapedCommand } = await execa ( 'mangal' , [
193
194
'inline' ,
194
195
'--source' ,
195
196
source ,
196
197
'--query' ,
197
198
title ,
198
199
'--manga' ,
199
- 'first ' ,
200
+ 'exact ' ,
200
201
'--chapters' ,
201
202
'all' ,
202
203
'-j' ,
203
204
] ) ;
204
- logger . info ( `Get chapters with following command: ${ command } ` ) ;
205
+ logger . info ( `Get chapters with following command: ${ escapedCommand } ` ) ;
205
206
const output : IOutput = JSON . parse ( stdout ) ;
206
207
if (
207
208
output &&
@@ -220,20 +221,20 @@ export const getChaptersFromRemote = async (source: string, title: string): Prom
220
221
221
222
export const getMangaDetail = async ( source : string , title : string ) : Promise < Mangal | undefined > => {
222
223
try {
223
- const { stdout, command } = await execa ( 'mangal' , [
224
+ const { stdout, escapedCommand } = await execa ( 'mangal' , [
224
225
'inline' ,
225
226
'--source' ,
226
227
source ,
227
228
'--include-anilist-manga' ,
228
229
'--query' ,
229
230
title ,
230
231
'--manga' ,
231
- 'first ' ,
232
+ 'exact ' ,
232
233
'--chapters' ,
233
234
'all' ,
234
235
'-j' ,
235
236
] ) ;
236
- logger . info ( `Get manga detail with following command: ${ command } ` ) ;
237
+ logger . info ( `Get manga detail with following command: ${ escapedCommand } ` ) ;
237
238
const output : IOutput = JSON . parse ( stdout ) ;
238
239
if ( output && output . result . length === 1 ) {
239
240
return output . result [ 0 ] . mangal ;
@@ -253,15 +254,15 @@ export const downloadChapter = async (
253
254
) : Promise < string > => {
254
255
try {
255
256
logger . info ( `Downloading chapter #${ chapterIndex } for ${ title } from ${ source } ` ) ;
256
- const { stdout, stderr, command } = await execa (
257
+ const { stdout, stderr, escapedCommand } = await execa (
257
258
'mangal' ,
258
- [ 'inline' , '--source' , source , '--query' , title , '--manga' , 'first ' , '--chapters' , `${ chapterIndex } ` , '-d' ] ,
259
+ [ 'inline' , '--source' , source , '--query' , title , '--manga' , 'exact ' , '--chapters' , `${ chapterIndex } ` , '-d' ] ,
259
260
{
260
261
cwd : libraryPath ,
261
262
} ,
262
263
) ;
263
264
264
- logger . info ( `Download chapter with following command: ${ command } ` ) ;
265
+ logger . info ( `Download chapter with following command: ${ escapedCommand } ` ) ;
265
266
266
267
if ( stderr ) {
267
268
logger . error ( `Failed to download the chapter #${ chapterIndex } for ${ title } . Err:\n${ stderr } ` ) ;
@@ -290,13 +291,18 @@ const shouldIncludeFile = (chapterFile: string) => {
290
291
} ;
291
292
292
293
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
+ }
300
306
} ;
301
307
302
308
export const getChaptersFromLocal = async ( mangaDir : string ) : Promise < ChapterFile [ ] > => {
0 commit comments