display a text share

This commit is contained in:
2022-05-10 22:37:30 +02:00
parent ca2b2c661c
commit b5a326324f
4 changed files with 57 additions and 36 deletions

View File

@@ -4,14 +4,15 @@
const slug = window.location.pathname.split("/").pop();
let component = null;
let contentType: string;
let filename: string;
onMount(async () => {
const regex = /filename="(.*)"/gm;
const res = await fetch(`/s/${slug}`);
const res = await fetch(`/s/${slug}`,{method:"HEAD"});
const contentType: string = res.headers.get("Content-Type");
let filename: string;
contentType = res.headers.get("Content-Type");
let m;
while ((m = regex.exec(res.headers.get("Content-Disposition"))) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
@@ -36,7 +37,7 @@
{#await component}
Loading data...
{:then v }
<svelte:component this={v.default} />
<svelte:component this={v.default} slug={slug} contentType={contentType} filename={filename} />
{/await}
{/if}
</div>

View File

@@ -1,10 +1,9 @@
<script lang="ts">
export let contentType: string;
export let filename: string;
export let slug: string;
export let response: Response;
export let contentType: string;
export let filename: string;
export let slug: string;
</script>
<div>
Default opener
Default opener
</div>

View File

@@ -1,11 +1,18 @@
<script lang="ts">
export let contentType: string;
export let filename: string;
export let slug: string;
export let response: Response;
import { onMount } from "svelte";
export let contentType: string;
export let filename: string;
export let slug: string;
let content = "";
onMount(async () => {
const res = await fetch(`/s/${slug}`);
content = await res.text();
});
</script>
<div>
Text opener
Text opener
<pre><code>{ content }</code></pre>
</div>