From 079aa13edbc5edc4055466d88abdb26c8f265e98 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Mon, 14 Aug 2023 21:22:33 -0400 Subject: [PATCH] fix(web): use server api media types (#3687) --- web/src/lib/utils/file-uploader.ts | 62 +++++++----------------------- 1 file changed, 13 insertions(+), 49 deletions(-) diff --git a/web/src/lib/utils/file-uploader.ts b/web/src/lib/utils/file-uploader.ts index fad841c221..533ab372ef 100644 --- a/web/src/lib/utils/file-uploader.ts +++ b/web/src/lib/utils/file-uploader.ts @@ -1,62 +1,25 @@ import { uploadAssetsStore } from '$lib/stores/upload'; import { addAssetsToAlbum } from '$lib/utils/asset-utils'; -import type { AssetFileUploadResponseDto } from '@api'; +import { api, AssetFileUploadResponseDto } from '@api'; import axios from 'axios'; import { notificationController, NotificationType } from './../components/shared-components/notification/notification'; -const extensions = [ - '.3fr', - '.3gp', - '.ari', - '.arw', - '.avi', - '.avif', - '.cap', - '.cin', - '.cr2', - '.cr3', - '.crw', - '.dcr', - '.dng', - '.erf', - '.fff', - '.flv', - '.gif', - '.heic', - '.heif', - '.iiq', - '.jpeg', - '.jpg', - '.k25', - '.kdc', - '.mkv', - '.mov', - '.mp2t', - '.mp4', - '.mpeg', - '.mrw', - '.nef', - '.orf', - '.ori', - '.pef', - '.png', - '.raf', - '.raw', - '.rwl', - '.sr2', - '.srf', - '.srw', - '.tiff', - '.webm', - '.webp', - '.wmv', - '.x3f', -]; +let _extensions: string[]; + +const getExtensions = async () => { + if (!_extensions) { + const { data } = await api.serverInfoApi.getSupportedMediaTypes(); + _extensions = [...data.image, ...data.video]; + } + return _extensions; +}; export const openFileUploadDialog = async ( albumId: string | undefined = undefined, sharedKey: string | undefined = undefined, ) => { + const extensions = await getExtensions(); + return new Promise<(string | undefined)[]>((resolve, reject) => { try { const fileSelector = document.createElement('input'); @@ -87,6 +50,7 @@ export const fileUploadHandler = async ( albumId: string | undefined = undefined, sharedKey: string | undefined = undefined, ) => { + const extensions = await getExtensions(); const iterable = { files: files.filter((file) => extensions.some((ext) => file.name.toLowerCase().endsWith(ext)))[Symbol.iterator](),