added 404 page
This commit is contained in:
parent
a4593c9d5c
commit
981d63c6df
@ -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,20 +28,29 @@
|
|||||||
}
|
}
|
||||||
filename = match[1];
|
filename = match[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return getComponentForShare(contentType,filename);
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="dl">
|
{#if !notFound}
|
||||||
|
<div class="dl">
|
||||||
<a href="/s/{slug}">Download</a>
|
<a href="/s/{slug}">Download</a>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
<main>
|
<main>
|
||||||
{#await getFileHeadAndComponent()}
|
{#await getFileHead()}
|
||||||
Loading data...
|
Loading data...
|
||||||
{:then v }
|
{:then}
|
||||||
|
|
||||||
|
{#if notFound}
|
||||||
|
<NotFound />
|
||||||
|
{:else}
|
||||||
|
{#await getComponentForShare(contentType, filename)}
|
||||||
|
Loading component...
|
||||||
|
{:then v}
|
||||||
<svelte:component this={v.default} slug={slug} contentType={contentType} filename={filename} />
|
<svelte:component this={v.default} slug={slug} contentType={contentType} filename={filename} />
|
||||||
{/await}
|
{/await}
|
||||||
|
{/if}
|
||||||
|
{/await}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
12
web/NotFound.svelte
Normal file
12
web/NotFound.svelte
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>Share not found</p>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
p{
|
||||||
|
color: var(--color-secondary);
|
||||||
|
font-size: 3rem;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Reference in New Issue
Block a user