From adb265794cc557114639e801c4f18c6023f3fa24 Mon Sep 17 00:00:00 2001
From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com>
Date: Thu, 9 Feb 2023 17:08:19 +0100
Subject: [PATCH] feat(web): allow uploading more file types (#1570)
* feat(web): allow uploading more file types
* fix(web): make filename extension lowercase
---
.../upload-asset-preview.svelte | 69 +++++++++++++++
.../shared-components/upload-panel.svelte | 84 +------------------
web/src/lib/utils/asset-utils.ts | 35 ++++++++
web/src/lib/utils/file-uploader.ts | 24 ++++--
4 files changed, 123 insertions(+), 89 deletions(-)
create mode 100644 web/src/lib/components/shared-components/upload-asset-preview.svelte
diff --git a/web/src/lib/components/shared-components/upload-asset-preview.svelte b/web/src/lib/components/shared-components/upload-asset-preview.svelte
new file mode 100644
index 0000000000..21dfd304bf
--- /dev/null
+++ b/web/src/lib/components/shared-components/upload-asset-preview.svelte
@@ -0,0 +1,69 @@
+
+
+
+
+ {#if showFallbackImage}
+
+ {:else}
+
{
+ URL.revokeObjectURL(previewURL);
+ }}
+ on:error={() => {
+ URL.revokeObjectURL(previewURL);
+ showFallbackImage = true;
+ }}
+ src={previewURL}
+ alt="Preview of asset"
+ class="h-[70px] w-[70px] object-cover rounded-tl-lg rounded-bl-lg"
+ draggable="false"
+ />
+ {/if}
+
+
+
+ .{uploadAsset.fileExtension}
+
+
+
+
+
+
+
+
+
+
+ {uploadAsset.progress}/100
+
+
+
+
diff --git a/web/src/lib/components/shared-components/upload-panel.svelte b/web/src/lib/components/shared-components/upload-panel.svelte
index 7e24627d8d..74753437bd 100644
--- a/web/src/lib/components/shared-components/upload-panel.svelte
+++ b/web/src/lib/components/shared-components/upload-panel.svelte
@@ -4,55 +4,20 @@
import { uploadAssetsStore } from '$lib/stores/upload';
import CloudUploadOutline from 'svelte-material-icons/CloudUploadOutline.svelte';
import WindowMinimize from 'svelte-material-icons/WindowMinimize.svelte';
- import type { UploadAsset } from '$lib/models/upload-asset';
import { notificationController, NotificationType } from './notification/notification';
- import { asByteUnitString } from '$lib/utils/byte-units';
+ import UploadAssetPreview from './upload-asset-preview.svelte';
let showDetail = true;
-
let uploadLength = 0;
+ let isUploading = false;
- const showUploadImageThumbnail = async (a: UploadAsset) => {
- const extension = a.fileExtension.toLowerCase();
-
- if (extension == 'jpeg' || extension == 'jpg' || extension == 'png') {
- try {
- const imgData = await a.file.arrayBuffer();
- const arrayBufferView = new Uint8Array(imgData);
- const blob = new Blob([arrayBufferView], { type: 'image/jpeg' });
- const urlCreator = window.URL || window.webkitURL;
- const imageUrl = urlCreator.createObjectURL(blob);
- // TODO: There is probably a cleaner way of doing this
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- const img: any = document.getElementById(`${a.id}`);
- img.src = imageUrl;
- } catch {
- // Do nothing?
- }
- }
- };
-
- // Reactive action to get thumbnail image of upload asset whenever there is a new one added to the list
+ // Reactive action to update asset uploadLength whenever there is a new one added to the list
$: {
if ($uploadAssetsStore.length != uploadLength) {
- $uploadAssetsStore.map((asset) => {
- showUploadImageThumbnail(asset);
- });
-
uploadLength = $uploadAssetsStore.length;
}
}
- $: {
- if (showDetail) {
- $uploadAssetsStore.map((asset) => {
- showUploadImageThumbnail(asset);
- });
- }
- }
-
- let isUploading = false;
-
uploadAssetsStore.isUploading.subscribe((value) => {
isUploading = value;
});
@@ -88,48 +53,7 @@