1
0
mirror of https://github.com/NickKaramoff/toot synced 2025-01-30 00:55:08 +01:00

Add a proper user agent for API requests (#80)

This commit is contained in:
Nikita Karamov 2025-01-24 19:06:54 +01:00 committed by GitHub
commit 804455db04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 8 deletions

View File

@ -16,11 +16,17 @@ and this project adheres to
## [Unreleased]
### Added
- Share2Fedi now adds a proper user agent header with project information
### Changed
- (POTENTIALLY BREAKING) Node.js version fixed to either 18 or 20.
- this (temporarily) drops (non-existent) support for Node.js 22
- by default, Share₂Fedi now assumes and prefers Node.js 20
- GraphQL requests now use variables (instead of string interpolation)
- proxy cache (`s-maxage`) increased from 1 day to 1 week
- updated dependencies
## [3.1.0] - 2024-02-12

View File

@ -7,6 +7,10 @@
*/
import { supportedProjects } from "./project";
import {
version,
repository,
} from "../../package.json" assert { type: "json" };
interface Instance {
domain: string;
@ -19,15 +23,19 @@ const getInstancesForProject = async (
project: keyof typeof supportedProjects,
): Promise<Instance[]> => {
let instances: Instance[];
const headers = new Headers();
headers.set("Accept", "application/graphql-response+json; charset=utf-8");
headers.append("Accept", "application/json; charset=utf-8");
headers.set("Content-Type", "application/json");
headers.set("User-Agent", `Share2Fedi/${version} (+${repository.url})`);
try {
const response = await fetch("https://api.fediverse.observer/", {
headers: {
Accept: "*/*",
"Accept-Language": "en;q=1.0",
"Content-Type": "application/json",
},
headers,
body: JSON.stringify({
query: `{nodes(status:"UP",softwarename:"${project}"){domain score active_users_monthly total_users}}`,
query: `query($project:String!){nodes(status:"UP",softwarename:$project){domain score active_users_monthly total_users}}`,
variables: { project },
}),
method: "POST",
});

View File

@ -37,7 +37,7 @@ export const GET: APIRoute = async ({ params }) => {
},
200,
{
"Cache-Control": "public, s-maxage=86400, max-age=604800",
"Cache-Control": "public, s-maxage=604800, max-age=604800",
},
);
};

View File

@ -16,7 +16,7 @@ export const GET: APIRoute = async () => {
return json(popularInstanceDomains, 200, {
"Cache-Control":
popularInstanceDomains.length > 0
? "public, s-maxage=86400, max-age=604800"
? "public, s-maxage=604800, max-age=604800"
: "public, s-maxage=60, max-age=3600",
});
};