From 42860fa15985401825d8d51e73ec497fe5876710 Mon Sep 17 00:00:00 2001 From: Melonai Date: Wed, 24 Mar 2021 09:51:36 +0100 Subject: Update SvelteKit to public beta --- client/src/actions/shorten.ts | 50 ------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 client/src/actions/shorten.ts (limited to 'client/src/actions/shorten.ts') diff --git a/client/src/actions/shorten.ts b/client/src/actions/shorten.ts deleted file mode 100644 index ca685c5..0000000 --- a/client/src/actions/shorten.ts +++ /dev/null @@ -1,50 +0,0 @@ -interface ShortenResponse { - hash: string; -} - -export interface ShortenRequest { - url: string; - nonce: string; - response: Promise; -} - -async function makeRequest(url: string): Promise { - let body; - - try { - const response = await fetch("/", { - headers: { - Accept: "application/json", - "Content-Type": "application/json", - }, - method: "post", - body: JSON.stringify({ url }), - }); - - body = await response.json(); - } catch (err) { - throw { - error: "Error!", - }; - } - - if (body.hash) { - return { - hash: body.hash, - }; - } else { - throw { - message: body.error || "Error!", - }; - } -} - -export default function shorten(url: string): ShortenRequest { - const nonce = Math.random().toString(36).substr(2, 5); - - return { - url, - nonce, - response: makeRequest(url), - }; -} -- cgit 1.4.1