Masto API meta

This commit is contained in:
ThatOneCalculator 2023-02-18 11:58:02 -08:00
parent 77eb5c984d
commit 8f2ae33511
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
3 changed files with 21 additions and 18 deletions

View File

@ -54,7 +54,7 @@ export function apiMastodonCompatible(router: Router): void {
// displayed without being logged in
try {
const data = await client.getInstance();
ctx.body = getInstance(data.data);
ctx.body = await getInstance(data.data);
} catch (e: any) {
console.error(e);
ctx.status = 401;

View File

@ -1,6 +1,9 @@
import { Entity } from "@calckey/megalodon";
import { fetchMeta } from "@/misc/fetch-meta.js";
// TODO: add calckey features
export function getInstance(response: Entity.Instance) {
export async function getInstance(response: Entity.Instance) {
const meta = await fetchMeta(true);
return {
uri: response.uri,
title: response.title || "",
@ -11,8 +14,8 @@ export function getInstance(response: Entity.Instance) {
urls: response.urls,
stats: response.stats,
thumbnail: response.thumbnail || "",
languages: ["en", "de", "ja"],
registrations: response.registrations,
languages: meta.langs,
registrations: !meta.disableRegistration || response.registrations,
approval_required: !response.registrations,
invites_enabled: response.registrations,
configuration: {
@ -77,17 +80,17 @@ export function getInstance(response: Entity.Instance) {
bot: true,
discoverable: false,
group: false,
created_at: "1971-01-01T00:00:00.000Z",
note: "",
url: "https://http.cat/404",
avatar: "https://http.cat/404",
avatar_static: "https://http.cat/404",
created_at: Math.floor(new Date().getTime() / 1000),
note: "Please refer to the original instance for the actual admin contact.",
url: "/",
avatar: "/static-assets/badges/info.png",
avatar_static: "/static-assets/badges/info.png",
header: "https://http.cat/404",
header_static: "https://http.cat/404",
followers_count: -1,
following_count: 0,
statuses_count: 0,
last_status_at: "1971-01-01T00:00:00.000Z",
last_status_at: Math.floor(new Date().getTime() / 1000),
noindex: true,
emojis: [],
fields: [],

View File

@ -404,7 +404,7 @@ async function getFirstReaction(
) {
const accessTokenArr = accessTokens?.split(" ") ?? [null];
const accessToken = accessTokenArr[accessTokenArr.length - 1];
let react = "👍";
let react = "";
try {
const api = await axios.post(`${BASE_URL}/api/i/registry/get-unsecure`, {
scope: ["client", "base"],
@ -412,7 +412,7 @@ async function getFirstReaction(
i: accessToken,
});
const reactRaw = api.data;
react = Array.isArray(reactRaw) ? api.data[0] : "👍";
react = Array.isArray(reactRaw) ? api.data[0] : "";
console.log(api.data);
return react;
} catch (e) {
@ -426,16 +426,16 @@ export function statusModel(
emojis: MastodonEntity.Emoji[],
content: string,
) {
const now = "1970-01-02T00:00:00.000Z";
const now = Math.floor(new Date().getTime() / 1000);
return {
id: "9atm5frjhb",
uri: "https://http.cat/404", // ""
url: "https://http.cat/404", // "",
account: {
id: "9arzuvv0sw",
username: "ReactionBot",
acct: "ReactionBot",
display_name: "ReactionsToThisPost",
username: "Reactions",
acct: "Reactions",
display_name: "Reactions to this post",
locked: false,
created_at: now,
followers_count: 0,
@ -443,8 +443,8 @@ export function statusModel(
statuses_count: 0,
note: "",
url: "https://http.cat/404",
avatar: "https://http.cat/404",
avatar_static: "https://http.cat/404",
avatar: "/static-assets/badges/info.png",
avatar_static: "/static-assets/badges/info.png",
header: "https://http.cat/404", // ""
header_static: "https://http.cat/404", // ""
emojis: [],