From 4dfe43918ff30ff612a48bebd833df6da3f19894 Mon Sep 17 00:00:00 2001 From: Nikita Karamov Date: Sat, 18 Mar 2023 04:44:48 +0100 Subject: [PATCH] Add Misskey (untested) --- src/pages/api/detect/[host].ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/pages/api/detect/[host].ts b/src/pages/api/detect/[host].ts index ec90055..c012ac4 100644 --- a/src/pages/api/detect/[host].ts +++ b/src/pages/api/detect/[host].ts @@ -89,6 +89,33 @@ const PROJECTS: Map = new Map([ }, }, ], + [ + "misskey", + { + check: async (url: string): Promise => { + const response = await fetch(new URL("/api/meta", url), { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify({ + detail: false, + }), + }); + const metadata = await response.json(); + if (metadata.version) { + return "misskey"; + } + throw new Error(`${url} doesn't host Misskey`); + }, + checkUrl: "/", + publishEndpoint: "share", + params: { + text: "text", + }, + }, + ], ]); const checkProjectUrl = ( @@ -113,7 +140,7 @@ const checkProjectUrl = ( export const get: APIRoute = async ({ params }) => { const host = params.host as string; - const promises = Object.entries(PROJECTS).map(([service, project]) => { + const promises = [...PROJECTS.entries()].map(([service, project]) => { const url = normalizeURL(host); if (project.check !== undefined) { return project.check(url);