diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts index 2ea8cdc3bd..00d2c3346c 100644 --- a/src/services/drive/add-file.ts +++ b/src/services/drive/add-file.ts @@ -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}`;