mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-24 00:39:32 +09:00
Update add-file.ts
This commit is contained in:
parent
148d6737cc
commit
ba0fe83b54
@ -80,6 +80,11 @@ async function save(path: string, name: string, type: string, hash: string, size
|
|||||||
|
|
||||||
webpublicExt = 'png';
|
webpublicExt = 'png';
|
||||||
webpublicType = 'image/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 {
|
} else {
|
||||||
log(`web image not created (not an image)`);
|
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()
|
.png()
|
||||||
.toBuffer();
|
.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';
|
thumbnailExt = 'png';
|
||||||
thumbnailType = 'image/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') {
|
if (config.drive && config.drive.storage == 'minio') {
|
||||||
let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']);
|
let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']);
|
||||||
|
const [primaryType] = type.split('+');
|
||||||
|
|
||||||
if (ext === '') {
|
if (ext === '') {
|
||||||
if (type === 'image/jpeg') ext = '.jpg';
|
if (primaryType === 'image/jpeg') ext = '.jpg';
|
||||||
if (type === 'image/png') ext = '.png';
|
if (primaryType === 'image/png') ext = '.png';
|
||||||
if (type === 'image/webp') ext = '.webp';
|
if (primaryType === 'image/webp') ext = '.webp';
|
||||||
|
if (primaryType === 'image/svg') ext = '.svg';
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = `${config.drive.prefix}/${uuid.v4()}${ext}`;
|
const key = `${config.drive.prefix}/${uuid.v4()}${ext}`;
|
||||||
|
Loading…
Reference in New Issue
Block a user