From 3be478b8ceef16bfd549c31f5bf73330871b2c8e Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 30 Oct 2023 12:50:11 -0700 Subject: [PATCH] edit-meta: fail fast for forbidden mimes Signed-off-by: Varun Patil --- lib/Exif.php | 2 +- src/components/modal/EditMetadataModal.vue | 12 ++++++++++++ src/services/utils/const.ts | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/Exif.php b/lib/Exif.php index 0c4e5e80..1d085e66 100644 --- a/lib/Exif.php +++ b/lib/Exif.php @@ -10,7 +10,7 @@ use OCP\Files\File; class Exif { - private const FORBIDDEN_EDIT_MIMES = ['image/bmp', 'image/x-dcraw', 'video/MP2T']; + private const FORBIDDEN_EDIT_MIMES = ['image/bmp', 'image/x-dcraw', 'video/MP2T']; // also update const.ts private const EXIFTOOL_TIMEOUT = 30000; private const EXIFTOOL_ARGS = ['-api', 'QuickTimeUTC=1', '-n', '-json']; diff --git a/src/components/modal/EditMetadataModal.vue b/src/components/modal/EditMetadataModal.vue index 58e0c267..9cd5459b 100644 --- a/src/components/modal/EditMetadataModal.vue +++ b/src/components/modal/EditMetadataModal.vue @@ -124,6 +124,18 @@ export default defineComponent({ let done = 0; this.progress = 0; + // Filter out forbidden MIME types + photos = photos.filter((p) => { + if (this.c.FORBIDDEN_EDIT_MIMES.includes(p.mimetype ?? String())) { + showWarning( + this.t('memories', 'Cannot edit {name} of type {type}', { name: p.basename!, type: p.mimetype! }), + ); + return false; + } + + return true; + }); + // Load metadata for all photos const calls = photos.map((p) => async () => { try { diff --git a/src/services/utils/const.ts b/src/services/utils/const.ts index 0d913434..7c96a1a2 100644 --- a/src/services/utils/const.ts +++ b/src/services/utils/const.ts @@ -3,7 +3,6 @@ import type { IPhoto } from '@typings'; /** Global constants */ export const constants = Object.freeze({ - // Flags for photos FLAG_PLACEHOLDER: 1 << 0, FLAG_LOAD_FAIL: 1 << 1, FLAG_IS_VIDEO: 1 << 2, @@ -12,9 +11,10 @@ export const constants = Object.freeze({ FLAG_LEAVING: 1 << 5, FLAG_IS_LOCAL: 1 << 6, - // Special strings FACE_NULL: 'NULL', + MIME_RAW: 'image/x-dcraw', + FORBIDDEN_EDIT_MIMES: ['image/bmp', 'image/x-dcraw', 'video/MP2T'], // Exif.php }); /**