Update add-file.ts

This commit is contained in:
Acid Chicken (硫酸鶏) 2019-01-12 19:15:19 +09:00 committed by GitHub
parent 148d6737cc
commit ba0fe83b54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,6 +80,11 @@ async function save(path: string, name: string, type: string, hash: string, size
webpublicExt = 'png';
webpublicType = 'image/png';
} else if (['image/svg', 'image/svg+xml'].includes(type)) {
webpublic = await fs.readFile(path);
webpublicExt = 'svg';
webpublicType = 'image/svg+xml';
} else {
log(`web image not created (not an image)`);
}
@ -115,6 +120,18 @@ async function save(path: string, name: string, type: string, hash: string, size
.png()
.toBuffer();
thumbnailExt = 'png';
thumbnailType = 'image/png';
} else if (['image/svg', 'image/svg+xml'].includes(type)) {
thumbnail = await fs.readFile(path).then(x => sharp()
.resize(498, 280, {
fit: 'inside',
withoutEnlargement: true
})
.overlayWith(x, { cutout: true })
.png()
.toBuffer());
thumbnailExt = 'png';
thumbnailType = 'image/png';
}
@ -122,11 +139,13 @@ async function save(path: string, name: string, type: string, hash: string, size
if (config.drive && config.drive.storage == 'minio') {
let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']);
const [primaryType] = type.split('+');
if (ext === '') {
if (type === 'image/jpeg') ext = '.jpg';
if (type === 'image/png') ext = '.png';
if (type === 'image/webp') ext = '.webp';
if (primaryType === 'image/jpeg') ext = '.jpg';
if (primaryType === 'image/png') ext = '.png';
if (primaryType === 'image/webp') ext = '.webp';
if (primaryType === 'image/svg') ext = '.svg';
}
const key = `${config.drive.prefix}/${uuid.v4()}${ext}`;