toot-script-condivisione-su.../src/pages/api/detect/[domain].ts

44 lines
1.1 KiB
TypeScript
Raw Normal View History

/*!
2023-09-02 16:17:15 +02:00
* This file is part of ShareFedi
* https://github.com/kytta/share2fedi
*
* SPDX-FileCopyrightText: © 2023 Nikita Karamov <me@kytta.dev>
* SPDX-License-Identifier: AGPL-3.0-only
*/
2023-09-02 17:53:16 +02:00
import { getSoftwareName } from "@lib/nodeinfo";
import { ProjectPublishConfig, supportedProjects } from "@lib/project";
import { error, json } from "@lib/response";
import type { APIRoute } from "astro";
2023-09-02 17:53:16 +02:00
export type Detection = {
domain: string;
project: keyof typeof supportedProjects;
} & ProjectPublishConfig;
export const get: APIRoute = async ({ params }) => {
const domain = params.domain as string;
2023-09-02 17:53:16 +02:00
const softwareName = await getSoftwareName(domain);
if (softwareName === undefined) {
return error("Could not detect software; NodeInfo not present.");
}
2023-09-02 17:53:16 +02:00
if (!(softwareName in supportedProjects)) {
return error(`"${softwareName}" is not supported yet.`);
}
2023-09-02 17:53:16 +02:00
const publishConfig = supportedProjects[softwareName] as ProjectPublishConfig;
return json(
{
domain,
project: softwareName,
...publishConfig,
},
200,
{
"Cache-Control": "public, s-maxage=86400, max-age=604800",
},
);
};