added 404 page

This commit is contained in:
Djeeberjr 2022-05-13 15:01:33 +02:00
parent a4593c9d5c
commit 981d63c6df
2 changed files with 38 additions and 10 deletions

View File

@ -1,16 +1,23 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte";
import getComponentForShare from "./contentType"; import getComponentForShare from "./contentType";
import NotFound from "./NotFound.svelte";
const regex = /filename="(.*)"/gm; const regex = /filename="(.*)"/gm;
const slug = window.location.pathname.split("/").pop(); const slug = window.location.pathname.split("/").pop();
let notFound = false;
let component = null; let component = null;
let contentType: string; let contentType: string;
let filename: string; let filename: string;
async function getFileHeadAndComponent() { async function getFileHead() {
const res = await fetch(`/s/${slug}`,{method:"HEAD"}); const res = await fetch(`/s/${slug}`,{method:"HEAD"});
if (res.status === 404){
notFound = true;
return;
}
contentType = res.headers.get("Content-Type"); contentType = res.headers.get("Content-Type");
let match; let match;
@ -21,19 +28,28 @@
} }
filename = match[1]; filename = match[1];
} }
return getComponentForShare(contentType,filename);
} }
</script> </script>
<div class="dl"> {#if !notFound}
<a href="/s/{slug}">Download</a> <div class="dl">
</div> <a href="/s/{slug}">Download</a>
</div>
{/if}
<main> <main>
{#await getFileHeadAndComponent()} {#await getFileHead()}
Loading data... Loading data...
{:then v } {:then}
<svelte:component this={v.default} slug={slug} contentType={contentType} filename={filename} />
{#if notFound}
<NotFound />
{:else}
{#await getComponentForShare(contentType, filename)}
Loading component...
{:then v}
<svelte:component this={v.default} slug={slug} contentType={contentType} filename={filename} />
{/await}
{/if}
{/await} {/await}
</main> </main>

12
web/NotFound.svelte Normal file
View File

@ -0,0 +1,12 @@
<script lang="ts">
</script>
<p>Share not found</p>
<style>
p{
color: var(--color-secondary);
font-size: 3rem;
}
</style>