Catching media store fail unlink error to prevent batch failure.
This commit is contained in:
14
src/media.js
14
src/media.js
@@ -426,11 +426,11 @@ async function writeImage(image, media, info, filepath, isProcessed) {
|
||||
|
||||
async function writeThumbnail(image, thumbpath) {
|
||||
return image
|
||||
.jpeg({ quality: config.media.thumbnailQuality })
|
||||
.resize({
|
||||
height: config.media.thumbnailSize,
|
||||
withoutEnlargement: true,
|
||||
})
|
||||
.jpeg({ quality: config.media.thumbnailQuality })
|
||||
.rotate()
|
||||
.toFile(path.join(config.media.path, thumbpath));
|
||||
}
|
||||
@@ -463,7 +463,7 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
|
||||
fsPromises.mkdir(path.join(config.media.path, lazydir), { recursive: true }),
|
||||
]);
|
||||
|
||||
const image = sharp(media.file.path, { pages: -1 });
|
||||
const image = sharp(media.file.path, { pages: ['trailer', 'teaser'].includes(media.role) ? -1 : 1 }); // don't store posters as animation
|
||||
const isProcessed = media.meta.subtype !== 'jpeg' || media.process;
|
||||
|
||||
const [info, stats] = await Promise.all([
|
||||
@@ -490,8 +490,8 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
|
||||
await writeImage(image, media, info, filepath, isProcessed);
|
||||
|
||||
await Promise.all([
|
||||
writeThumbnail(image, thumbpath),
|
||||
writeLazy(image, lazypath),
|
||||
writeThumbnail(image, thumbpath, info),
|
||||
writeLazy(image, lazypath, info),
|
||||
]);
|
||||
|
||||
/*
|
||||
@@ -603,7 +603,11 @@ async function storeFile(media, options) {
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to store ${media.src}: ${error.message}`);
|
||||
|
||||
await fsPromises.unlink(media.file.path);
|
||||
try {
|
||||
await fsPromises.unlink(media.file.path);
|
||||
} catch (unlinkError) {
|
||||
logger.warn(`Failed to unlink ${media.file.path} from ${media.src}: ${unlinkError.message}`);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user