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

17 lines
471 B
TypeScript
Raw Normal View History

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