@@ -12,7 +12,7 @@ const parseEbookMetadata = require('../utils/parsers/parseEbookMetadata')
12
12
const CacheManager = require ( '../managers/CacheManager' )
13
13
14
14
class CoverManager {
15
- constructor ( ) { }
15
+ constructor ( ) { }
16
16
17
17
getCoverDirectory ( libraryItem ) {
18
18
if ( global . ServerSettings . storeCoverWithItem && ! libraryItem . isFile ) {
@@ -93,10 +93,13 @@ class CoverManager {
93
93
const coverFullPath = Path . posix . join ( coverDirPath , `cover${ extname } ` )
94
94
95
95
// Move cover from temp upload dir to destination
96
- const success = await coverFile . mv ( coverFullPath ) . then ( ( ) => true ) . catch ( ( error ) => {
97
- Logger . error ( '[CoverManager] Failed to move cover file' , path , error )
98
- return false
99
- } )
96
+ const success = await coverFile
97
+ . mv ( coverFullPath )
98
+ . then ( ( ) => true )
99
+ . catch ( ( error ) => {
100
+ Logger . error ( '[CoverManager] Failed to move cover file' , coverFullPath , error )
101
+ return false
102
+ } )
100
103
101
104
if ( ! success ) {
102
105
return {
@@ -124,11 +127,13 @@ class CoverManager {
124
127
var temppath = Path . posix . join ( coverDirPath , 'cover' )
125
128
126
129
let errorMsg = ''
127
- let success = await downloadImageFile ( url , temppath ) . then ( ( ) => true ) . catch ( ( err ) => {
128
- errorMsg = err . message || 'Unknown error'
129
- Logger . error ( `[CoverManager] Download image file failed for "${ url } "` , errorMsg )
130
- return false
131
- } )
130
+ let success = await downloadImageFile ( url , temppath )
131
+ . then ( ( ) => true )
132
+ . catch ( ( err ) => {
133
+ errorMsg = err . message || 'Unknown error'
134
+ Logger . error ( `[CoverManager] Download image file failed for "${ url } "` , errorMsg )
135
+ return false
136
+ } )
132
137
if ( ! success ) {
133
138
return {
134
139
error : 'Failed to download image from url: ' + errorMsg
@@ -180,15 +185,15 @@ class CoverManager {
180
185
}
181
186
182
187
// Cover path does not exist
183
- if ( ! await fs . pathExists ( coverPath ) ) {
188
+ if ( ! ( await fs . pathExists ( coverPath ) ) ) {
184
189
Logger . error ( `[CoverManager] validate cover path does not exist "${ coverPath } "` )
185
190
return {
186
191
error : 'Cover path does not exist'
187
192
}
188
193
}
189
194
190
195
// Cover path is not a file
191
- if ( ! await checkPathIsFile ( coverPath ) ) {
196
+ if ( ! ( await checkPathIsFile ( coverPath ) ) ) {
192
197
Logger . error ( `[CoverManager] validate cover path is not a file "${ coverPath } "` )
193
198
return {
194
199
error : 'Cover path is not a file'
@@ -211,10 +216,13 @@ class CoverManager {
211
216
var newCoverPath = Path . posix . join ( coverDirPath , coverFilename )
212
217
Logger . debug ( `[CoverManager] validate cover path copy cover from "${ coverPath } " to "${ newCoverPath } "` )
213
218
214
- var copySuccess = await fs . copy ( coverPath , newCoverPath , { overwrite : true } ) . then ( ( ) => true ) . catch ( ( error ) => {
215
- Logger . error ( `[CoverManager] validate cover path failed to copy cover` , error )
216
- return false
217
- } )
219
+ var copySuccess = await fs
220
+ . copy ( coverPath , newCoverPath , { overwrite : true } )
221
+ . then ( ( ) => true )
222
+ . catch ( ( error ) => {
223
+ Logger . error ( `[CoverManager] validate cover path failed to copy cover` , error )
224
+ return false
225
+ } )
218
226
if ( ! copySuccess ) {
219
227
return {
220
228
error : 'Failed to copy cover to dir'
@@ -236,14 +244,14 @@ class CoverManager {
236
244
237
245
/**
238
246
* Extract cover art from audio file and save for library item
239
- *
240
- * @param {import('../models/Book').AudioFileObject[] } audioFiles
241
- * @param {string } libraryItemId
242
- * @param {string } [libraryItemPath] null for isFile library items
247
+ *
248
+ * @param {import('../models/Book').AudioFileObject[] } audioFiles
249
+ * @param {string } libraryItemId
250
+ * @param {string } [libraryItemPath] null for isFile library items
243
251
* @returns {Promise<string> } returns cover path
244
252
*/
245
253
async saveEmbeddedCoverArt ( audioFiles , libraryItemId , libraryItemPath ) {
246
- let audioFileWithCover = audioFiles . find ( af => af . embeddedCoverArt )
254
+ let audioFileWithCover = audioFiles . find ( ( af ) => af . embeddedCoverArt )
247
255
if ( ! audioFileWithCover ) return null
248
256
249
257
let coverDirPath = null
@@ -273,10 +281,10 @@ class CoverManager {
273
281
274
282
/**
275
283
* Extract cover art from ebook and save for library item
276
- *
277
- * @param {import('../utils/parsers/parseEbookMetadata').EBookFileScanData } ebookFileScanData
278
- * @param {string } libraryItemId
279
- * @param {string } [libraryItemPath] null for isFile library items
284
+ *
285
+ * @param {import('../utils/parsers/parseEbookMetadata').EBookFileScanData } ebookFileScanData
286
+ * @param {string } libraryItemId
287
+ * @param {string } [libraryItemPath] null for isFile library items
280
288
* @returns {Promise<string> } returns cover path
281
289
*/
282
290
async saveEbookCoverArt ( ebookFileScanData , libraryItemId , libraryItemPath ) {
@@ -310,9 +318,9 @@ class CoverManager {
310
318
}
311
319
312
320
/**
313
- *
314
- * @param {string } url
315
- * @param {string } libraryItemId
321
+ *
322
+ * @param {string } url
323
+ * @param {string } libraryItemId
316
324
* @param {string } [libraryItemPath] null if library item isFile or is from adding new podcast
317
325
* @returns {Promise<{error:string}|{cover:string}> }
318
326
*/
@@ -328,10 +336,12 @@ class CoverManager {
328
336
await fs . ensureDir ( coverDirPath )
329
337
330
338
const temppath = Path . posix . join ( coverDirPath , 'cover' )
331
- const success = await downloadImageFile ( url , temppath ) . then ( ( ) => true ) . catch ( ( err ) => {
332
- Logger . error ( `[CoverManager] Download image file failed for "${ url } "` , err )
333
- return false
334
- } )
339
+ const success = await downloadImageFile ( url , temppath )
340
+ . then ( ( ) => true )
341
+ . catch ( ( err ) => {
342
+ Logger . error ( `[CoverManager] Download image file failed for "${ url } "` , err )
343
+ return false
344
+ } )
335
345
if ( ! success ) {
336
346
return {
337
347
error : 'Failed to download image from url'
@@ -361,4 +371,4 @@ class CoverManager {
361
371
}
362
372
}
363
373
}
364
- module . exports = new CoverManager ( )
374
+ module . exports = new CoverManager ( )
0 commit comments