s3-share/web/contentType.ts

69 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-05-10 14:01:07 +00:00
export default function getComponentForShare(contentType: string, filename: string) {
if (contentType.startsWith("image/")) {
2022-05-14 19:23:31 +00:00
return import("./opener/Image.svelte");
2022-05-10 14:01:07 +00:00
}
if (contentType.startsWith("video/")) {
return import("./opener/Default.svelte");
}
if (contentType.startsWith("audio/")) {
return import("./opener/Default.svelte");
}
if (contentType.startsWith("application/pdf")) {
2022-06-08 10:02:09 +00:00
return import("./opener/PDF.svelte");
2022-05-10 14:01:07 +00:00
}
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":
2022-06-08 10:02:09 +00:00
return import("./opener/Text.svelte");
2022-05-10 14:01:07 +00:00
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":
2022-05-14 19:23:31 +00:00
return import("./opener/Image.svelte");
2022-05-10 14:01:07 +00:00
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":
2022-06-08 10:02:09 +00:00
return import("./opener/PDF.svelte");
2022-05-10 14:01:07 +00:00
case "txt":
case "md":
case "markdown":
return import("./opener/Default.svelte");
}
2022-06-08 10:02:09 +00:00
return import("./opener/Default.svelte");
2022-05-10 14:01:07 +00:00
}