Migrate HTML file and basic API functionality

This commit is contained in:
Nikita Karamov 2023-03-17 21:29:49 +01:00
parent 1ba204644b
commit 6031d959ea
No known key found for this signature in database
GPG key ID: 41D6F71EE78E77CD
4 changed files with 28 additions and 5 deletions

View file

@ -26,8 +26,6 @@
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
*/ */
import "./scss/style.scss";
const INSTANCE_LIST_URL = "https://api.joinmastodon.org/servers"; const INSTANCE_LIST_URL = "https://api.joinmastodon.org/servers";
const LOCAL_STORAGE_KEY = "recentInstances"; const LOCAL_STORAGE_KEY = "recentInstances";
const RECENT_INSTANCES_SIZE = 5; const RECENT_INSTANCES_SIZE = 5;

16
src/pages/api/share.ts Normal file
View file

@ -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);
};

View file

@ -1,5 +1,9 @@
---
import "../styles/main.scss";
---
<!-- <!--
@source: https://github.com/kytta/share2fedi/blob/main/index.html @source: https://github.com/kytta/share2fedi/blob/main/src/pages/index.astro
share2fedi - Instance-agnostic share page for the Fediverse. share2fedi - Instance-agnostic share page for the Fediverse.
Copyright (C) 2020-2023 Nikita Karamov <me@kytta.dev> Copyright (C) 2020-2023 Nikita Karamov <me@kytta.dev>
@ -40,7 +44,7 @@
href="https://s2f.kytta.dev/" href="https://s2f.kytta.dev/"
/> />
<script <!-- <script
type="module" type="module"
src="/lib/main.js" src="/lib/main.js"
async async
@ -51,7 +55,7 @@
src="/lib/count.js" src="/lib/count.js"
async async
defer defer
></script> ></script> -->
<link <link
rel="icon" rel="icon"
@ -71,6 +75,11 @@
rel="manifest" rel="manifest"
href="/manifest.webmanifest" href="/manifest.webmanifest"
/> />
<meta
name="generator"
content="{Astro.generator}"
/>
</head> </head>
<body> <body>
<header> <header>