diff --git a/packages/backend/src/services/drive/add-file.ts b/packages/backend/src/services/drive/add-file.ts index 9de4465eb..c117fe910 100644 --- a/packages/backend/src/services/drive/add-file.ts +++ b/packages/backend/src/services/drive/add-file.ts @@ -178,6 +178,7 @@ export async function generateAlts(path: string, type: string, generateWeb: bool } let img: sharp.Sharp | null = null; + let webpublicNeeded: boolean; try { img = sharp(path); @@ -191,6 +192,9 @@ export async function generateAlts(path: string, type: string, generateWeb: bool thumbnail: null, }; } + + webpublicNeeded = !!metadata.exif || !!metadata.icc || !!metadata.iptc || !!metadata.xmp || !!metadata.tifftagPhotoshop + || !metadata.width || metadata.width > 2048 || !metadata.height || metadata.height > 2048; } catch (e) { logger.warn(`sharp failed: ${e}`); return { @@ -206,11 +210,13 @@ export async function generateAlts(path: string, type: string, generateWeb: bool logger.info(`creating web image`); try { - if (['image/jpeg'].includes(type)) { + if (['image/jpeg'].includes(type) && webpublicNeeded) { webpublic = await convertSharpToJpeg(img, 2048, 2048); - } else if (['image/webp'].includes(type)) { + } else if (['image/webp'].includes(type) && webpublicNeeded) { webpublic = await convertSharpToWebp(img, 2048, 2048); - } else if (['image/png', 'image/svg+xml'].includes(type)) { + } else if (['image/png'].includes(type) && webpublicNeeded) { + webpublic = await convertSharpToPng(img, 2048, 2048); + } else if (['image/svg+xml'].includes(type)) { webpublic = await convertSharpToPng(img, 2048, 2048); } else { logger.debug(`web image not created (not an required image)`); diff --git a/packages/client/package.json b/packages/client/package.json index 6c4cf764d..19a1fb5a6 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -45,6 +45,7 @@ "autwh": "0.1.0", "blurhash": "1.1.4", "broadcast-channel": "4.9.0", + "browser-image-resizer": "2.2.1", "chart.js": "3.7.0", "chartjs-adapter-date-fns": "2.0.0", "chartjs-plugin-zoom": "1.2.0", diff --git a/packages/client/src/os.ts b/packages/client/src/os.ts index 378523e1b..6e8a93822 100644 --- a/packages/client/src/os.ts +++ b/packages/client/src/os.ts @@ -9,6 +9,7 @@ import MkPostFormDialog from '@/components/post-form-dialog.vue'; import MkWaitingDialog from '@/components/waiting-dialog.vue'; import { resolve } from '@/router'; import { $i } from '@/account'; +import { readAndCompressImage } from 'browser-image-resizer'; export const pendingApiRequestsCount = ref(0); @@ -548,7 +549,7 @@ export function upload(file: File, folder?: any, name?: string): Promise { + reader.onload = async (e) => { const ctx = reactive({ id: id, name: name || file.name || 'untitled', @@ -557,12 +558,24 @@ export function upload(file: File, folder?: any, name?: string): Promise