This repository has been archived on 2024-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
share2fedi/src/pages/api/share.ts
Nikita Karamov d3fb510bbb
Rewrite the instance selector
This commit adds a new '/api/instances' endpoint that returns
the domains of the available Mastodon instances. This also changes the
input field, making it accept a host rather than the full domain.
2023-09-02 21:56:43 +02:00

16 lines
471 B
TypeScript

import { APIRoute } from "astro";
export const post: APIRoute = async ({ redirect, request }) => {
const formData = await request.formData();
const text = (formData.get("text") as string) || "";
const instanceDomain =
(formData.get("instance") as string) || "mastodon.social";
const publishUrl = new URL("/share", `https://${instanceDomain}/`);
publishUrl.search = new URLSearchParams({
text,
}).toString();
return redirect(publishUrl.toString(), 303);
};