s3-share/web/contentType.ts
2022-06-08 12:02:09 +02:00

69 lines
1.5 KiB
TypeScript

export default function getComponentForShare(contentType: string, filename: string) {
if (contentType.startsWith("image/")) {
return import("./opener/Image.svelte");
}
if (contentType.startsWith("video/")) {
return import("./opener/Default.svelte");
}
if (contentType.startsWith("audio/")) {
return import("./opener/Default.svelte");
}
if (contentType.startsWith("application/pdf")) {
return import("./opener/PDF.svelte");
}
if (contentType.startsWith("text/")) {
return import("./opener/Text.svelte");
}
switch (contentType) {
case "application/json":
case "application/ld+json":
case "application/xhtml+xml":
case "application/xml":
return import("./opener/Text.svelte");
case "application/ogg":
return import("./opener/Default.svelte");
}
const extension = filename.split(".").pop();
if (extension === undefined) {
return import("./opener/Default.svelte");
}
switch (extension) {
case "png":
case "jpg":
case "jpeg":
case "gif":
return import("./opener/Image.svelte");
case "mp4":
case "mov":
case "avi":
case "mkv":
case "wmv":
case "flv":
case "mpg":
case "mpeg":
return import("./opener/Default.svelte");
case "mp3":
case "wav":
case "ogg":
case "flac":
return import("./opener/Default.svelte");
case "pdf":
return import("./opener/PDF.svelte");
case "txt":
case "md":
case "markdown":
return import("./opener/Default.svelte");
}
return import("./opener/Default.svelte");
}