Migrate HTML file and basic API functionality

This commit is contained in:
Nikita Karamov 2023-03-17 21:29:49 +01:00
parent 5af9e55943
commit e9bda963ac
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
*/
import "./scss/style.scss";
const INSTANCE_LIST_URL = "https://api.joinmastodon.org/servers";
const LOCAL_STORAGE_KEY = "recentInstances";
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.
Copyright (C) 2020-2023 Nikita Karamov <me@kytta.dev>
@ -40,7 +44,7 @@
href="https://s2f.kytta.dev/"
/>
<script
<!-- <script
type="module"
src="/lib/main.js"
async
@ -51,7 +55,7 @@
src="/lib/count.js"
async
defer
></script>
></script> -->
<link
rel="icon"
@ -71,6 +75,11 @@
rel="manifest"
href="/manifest.webmanifest"
/>
<meta
name="generator"
content="{Astro.generator}"
/>
</head>
<body>
<header>