aboutsummaryrefslogtreecommitdiff
path: root/client/src/actions
diff options
context:
space:
mode:
authorMelonai <einebeere@gmail.com>2021-03-24 09:51:36 +0100
committerMelonai <einebeere@gmail.com>2021-03-24 09:51:36 +0100
commit42860fa15985401825d8d51e73ec497fe5876710 (patch)
treedaa43dd5f4ac77e46dbdd78b1a07811fa5db755c /client/src/actions
parent5dde1f55d818a74e838afa37b0e20217b1549a83 (diff)
downloadshorest-42860fa15985401825d8d51e73ec497fe5876710.tar.zst
shorest-42860fa15985401825d8d51e73ec497fe5876710.zip
Update SvelteKit to public beta
Diffstat (limited to 'client/src/actions')
-rw-r--r--client/src/actions/shorten.ts50
1 files changed, 0 insertions, 50 deletions
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<ShortenResponse>;
-}
-
-async function makeRequest(url: string): Promise<ShortenResponse> {
- 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),
- };
-}