サムネイル生成でエラーになってもファイルのアップロードを失敗しないように

#5050
This commit is contained in:
syuilo 2019-06-13 22:59:15 +09:00
parent fde9fc2891
commit e9dc54c4d9
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69

View file

@ -149,18 +149,22 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
if (generateWeb) { if (generateWeb) {
logger.info(`creating web image`); logger.info(`creating web image`);
if (['image/jpeg'].includes(type)) { try {
webpublic = await convertToJpeg(path, 2048, 2048); if (['image/jpeg'].includes(type)) {
} else if (['image/webp'].includes(type)) { webpublic = await convertToJpeg(path, 2048, 2048);
webpublic = await convertToWebp(path, 2048, 2048); } else if (['image/webp'].includes(type)) {
} else if (['image/png'].includes(type)) { webpublic = await convertToWebp(path, 2048, 2048);
webpublic = await convertToPng(path, 2048, 2048); } else if (['image/png'].includes(type)) {
} else if (['image/apng', 'image/vnd.mozilla.apng'].includes(type)) { webpublic = await convertToPng(path, 2048, 2048);
webpublic = await convertToApng(path); } else if (['image/apng', 'image/vnd.mozilla.apng'].includes(type)) {
} else if (['image/gif'].includes(type)) { webpublic = await convertToApng(path);
webpublic = await convertToGif(path); } else if (['image/gif'].includes(type)) {
} else { webpublic = await convertToGif(path);
logger.info(`web image not created (not an image)`); } else {
logger.info(`web image not created (not an image)`);
}
} catch (e) {
logger.warn(`web image not created (an error occured)`, e);
} }
} else { } else {
logger.info(`web image not created (from remote)`); logger.info(`web image not created (from remote)`);
@ -170,18 +174,22 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
// #region thumbnail // #region thumbnail
let thumbnail: IImage | null = null; let thumbnail: IImage | null = null;
if (['image/jpeg', 'image/webp'].includes(type)) { try {
thumbnail = await convertToJpeg(path, 498, 280); if (['image/jpeg', 'image/webp'].includes(type)) {
} else if (['image/png'].includes(type)) { thumbnail = await convertToJpeg(path, 498, 280);
thumbnail = await convertToPng(path, 498, 280); } else if (['image/png'].includes(type)) {
} else if (['image/gif'].includes(type)) { thumbnail = await convertToPng(path, 498, 280);
thumbnail = await convertToGif(path); } else if (['image/gif'].includes(type)) {
} else if (type.startsWith('video/')) { thumbnail = await convertToGif(path);
try { } else if (type.startsWith('video/')) {
thumbnail = await GenerateVideoThumbnail(path); try {
} catch (e) { thumbnail = await GenerateVideoThumbnail(path);
logger.error(`GenerateVideoThumbnail failed: ${e}`); } catch (e) {
logger.error(`GenerateVideoThumbnail failed: ${e}`);
}
} }
} catch (e) {
logger.warn(`thumbnail not created (an error occured)`, e);
} }
// #endregion thumbnail // #endregion thumbnail