Adds import from URL

This commit is contained in:
Christian Beutel
2025-02-01 20:36:39 +01:00
parent 0cf17cbd86
commit 3ab591177a
17 changed files with 208 additions and 41 deletions

View File

@@ -0,0 +1,21 @@
import { handleError } from "$lib/util/api_util";
import { type RequestEvent } from "@sveltejs/kit";
export async function POST(event: RequestEvent) {
const data = await event.request.json();
try {
const response = await event.fetch(data.url);
const blob = await response.blob();
const contentType = 'determine the content type here';
return new Response(blob, {
headers: {
'Content-Type': contentType,
},
});
} catch (e) {
throw handleError(e)
}
}

View File

@@ -38,37 +38,6 @@
handleFileSelection(e.dataTransfer?.files);
}
function mockUpload(f: File, onProgess?: (progress: number) => void) {
return new Promise((resolve, reject) => {
console.log("here");
setTimeout(() => {
onProgess?.(10);
}, 400);
setTimeout(() => {
onProgess?.(30);
}, 500);
setTimeout(() => {
onProgess?.(50);
}, 800);
setTimeout(() => {
onProgess?.(70);
}, 1200);
setTimeout(() => {
onProgess?.(99);
}, 1300);
setTimeout(() => {
onProgess?.(100);
const random = Math.random();
if (random < 0.5) {
reject(false);
} else {
resolve(true);
}
}, 10000);
});
}
async function handleFileSelection(files?: FileList | null) {
if (!files) {
files = (document.getElementById("file-input") as HTMLInputElement)