Skip to content

Commit

Permalink
fix(web): use server api media types (#3687)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 authored Aug 15, 2023
1 parent 67bac9f commit 079aa13
Showing 1 changed file with 13 additions and 49 deletions.
62 changes: 13 additions & 49 deletions web/src/lib/utils/file-uploader.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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](),

Expand Down

0 comments on commit 079aa13

Please sign in to comment.