From 6031d959ea6476d82a779bf8d7cde65829caa072 Mon Sep 17 00:00:00 2001 From: Nikita Karamov Date: Fri, 17 Mar 2023 21:29:49 +0100 Subject: [PATCH] Migrate HTML file and basic API functionality --- lib/main.js | 2 -- src/pages/api/share.ts | 16 ++++++++++++++++ index.html => src/pages/index.astro | 15 ++++++++++++--- lib/scss/style.scss => src/styles/main.scss | 0 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/pages/api/share.ts rename index.html => src/pages/index.astro (96%) rename lib/scss/style.scss => src/styles/main.scss (100%) diff --git a/lib/main.js b/lib/main.js index 67ae144..3a543e1 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,8 +26,6 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import "./scss/style.scss"; - const INSTANCE_LIST_URL = "https://api.joinmastodon.org/servers"; const LOCAL_STORAGE_KEY = "recentInstances"; const RECENT_INSTANCES_SIZE = 5; diff --git a/src/pages/api/share.ts b/src/pages/api/share.ts new file mode 100644 index 0000000..5a1cbfc --- /dev/null +++ b/src/pages/api/share.ts @@ -0,0 +1,16 @@ +import { APIRoute } from "astro"; + +export const post: APIRoute = async ({ redirect, request }) => { + const formData = await request.formData(); + + const text = (formData.get("text") as string) || ""; + const instanceURL = + (formData.get("instance") as string) || "https://mastodon.social"; + + const publishUrl = new URL("/share", instanceURL); + publishUrl.search = new URLSearchParams({ + text, + }).toString(); + + return redirect(publishUrl.toString(), 303); +}; diff --git a/index.html b/src/pages/index.astro similarity index 96% rename from index.html rename to src/pages/index.astro index 7f79490..b608e4a 100644 --- a/index.html +++ b/src/pages/index.astro @@ -1,5 +1,9 @@ +--- +import "../styles/main.scss"; +--- + + +
diff --git a/lib/scss/style.scss b/src/styles/main.scss similarity index 100% rename from lib/scss/style.scss rename to src/styles/main.scss