s3-share/web/App.svelte

47 lines
973 B
Svelte
Raw Normal View History

2022-05-09 18:01:31 +00:00
<script lang="ts">
2022-05-10 14:01:07 +00:00
import { onMount } from "svelte";
import getComponentForShare from "./contentType";
2022-05-09 18:01:31 +00:00
const slug = window.location.pathname.split("/").pop();
2022-05-10 14:01:07 +00:00
let component = null;
2022-05-09 18:01:31 +00:00
onMount(async () => {
2022-05-10 14:01:07 +00:00
const regex = /filename="(.*)"/gm;
2022-05-09 18:01:31 +00:00
const res = await fetch(`/s/${slug}`);
2022-05-10 14:01:07 +00:00
const contentType: string = res.headers.get("Content-Type");
let filename: string;
let m;
while ((m = regex.exec(res.headers.get("Content-Disposition"))) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
filename = m[1];
}
document.title = filename;
component = getComponentForShare(contentType,filename);
});
2022-05-09 18:01:31 +00:00
</script>
<main>
2022-05-10 14:01:07 +00:00
<div>{slug}</div>
2022-05-09 18:01:31 +00:00
<div>
2022-05-10 14:01:07 +00:00
{#if component === null}
Loading data...
{:else}
{#await component}
Loading data...
{:then v }
<svelte:component this={v.default} />
{/await}
{/if}
2022-05-09 18:01:31 +00:00
</div>
</main>
<style>
2022-05-10 14:01:07 +00:00
</style>