Masto API meta
This commit is contained in:
parent
77eb5c984d
commit
8f2ae33511
3 changed files with 21 additions and 18 deletions
|
@ -54,7 +54,7 @@ export function apiMastodonCompatible(router: Router): void {
|
||||||
// displayed without being logged in
|
// displayed without being logged in
|
||||||
try {
|
try {
|
||||||
const data = await client.getInstance();
|
const data = await client.getInstance();
|
||||||
ctx.body = getInstance(data.data);
|
ctx.body = await getInstance(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { Entity } from "@calckey/megalodon";
|
import { Entity } from "@calckey/megalodon";
|
||||||
|
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||||
|
|
||||||
// TODO: add calckey features
|
// TODO: add calckey features
|
||||||
export function getInstance(response: Entity.Instance) {
|
export async function getInstance(response: Entity.Instance) {
|
||||||
|
const meta = await fetchMeta(true);
|
||||||
return {
|
return {
|
||||||
uri: response.uri,
|
uri: response.uri,
|
||||||
title: response.title || "",
|
title: response.title || "",
|
||||||
|
@ -11,8 +14,8 @@ export function getInstance(response: Entity.Instance) {
|
||||||
urls: response.urls,
|
urls: response.urls,
|
||||||
stats: response.stats,
|
stats: response.stats,
|
||||||
thumbnail: response.thumbnail || "",
|
thumbnail: response.thumbnail || "",
|
||||||
languages: ["en", "de", "ja"],
|
languages: meta.langs,
|
||||||
registrations: response.registrations,
|
registrations: !meta.disableRegistration || response.registrations,
|
||||||
approval_required: !response.registrations,
|
approval_required: !response.registrations,
|
||||||
invites_enabled: response.registrations,
|
invites_enabled: response.registrations,
|
||||||
configuration: {
|
configuration: {
|
||||||
|
@ -77,17 +80,17 @@ export function getInstance(response: Entity.Instance) {
|
||||||
bot: true,
|
bot: true,
|
||||||
discoverable: false,
|
discoverable: false,
|
||||||
group: false,
|
group: false,
|
||||||
created_at: "1971-01-01T00:00:00.000Z",
|
created_at: Math.floor(new Date().getTime() / 1000),
|
||||||
note: "",
|
note: "Please refer to the original instance for the actual admin contact.",
|
||||||
url: "https://http.cat/404",
|
url: "/",
|
||||||
avatar: "https://http.cat/404",
|
avatar: "/static-assets/badges/info.png",
|
||||||
avatar_static: "https://http.cat/404",
|
avatar_static: "/static-assets/badges/info.png",
|
||||||
header: "https://http.cat/404",
|
header: "https://http.cat/404",
|
||||||
header_static: "https://http.cat/404",
|
header_static: "https://http.cat/404",
|
||||||
followers_count: -1,
|
followers_count: -1,
|
||||||
following_count: 0,
|
following_count: 0,
|
||||||
statuses_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,
|
noindex: true,
|
||||||
emojis: [],
|
emojis: [],
|
||||||
fields: [],
|
fields: [],
|
||||||
|
|
|
@ -404,7 +404,7 @@ async function getFirstReaction(
|
||||||
) {
|
) {
|
||||||
const accessTokenArr = accessTokens?.split(" ") ?? [null];
|
const accessTokenArr = accessTokens?.split(" ") ?? [null];
|
||||||
const accessToken = accessTokenArr[accessTokenArr.length - 1];
|
const accessToken = accessTokenArr[accessTokenArr.length - 1];
|
||||||
let react = "👍";
|
let react = "⭐";
|
||||||
try {
|
try {
|
||||||
const api = await axios.post(`${BASE_URL}/api/i/registry/get-unsecure`, {
|
const api = await axios.post(`${BASE_URL}/api/i/registry/get-unsecure`, {
|
||||||
scope: ["client", "base"],
|
scope: ["client", "base"],
|
||||||
|
@ -412,7 +412,7 @@ async function getFirstReaction(
|
||||||
i: accessToken,
|
i: accessToken,
|
||||||
});
|
});
|
||||||
const reactRaw = api.data;
|
const reactRaw = api.data;
|
||||||
react = Array.isArray(reactRaw) ? api.data[0] : "👍";
|
react = Array.isArray(reactRaw) ? api.data[0] : "⭐";
|
||||||
console.log(api.data);
|
console.log(api.data);
|
||||||
return react;
|
return react;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -426,16 +426,16 @@ export function statusModel(
|
||||||
emojis: MastodonEntity.Emoji[],
|
emojis: MastodonEntity.Emoji[],
|
||||||
content: string,
|
content: string,
|
||||||
) {
|
) {
|
||||||
const now = "1970-01-02T00:00:00.000Z";
|
const now = Math.floor(new Date().getTime() / 1000);
|
||||||
return {
|
return {
|
||||||
id: "9atm5frjhb",
|
id: "9atm5frjhb",
|
||||||
uri: "https://http.cat/404", // ""
|
uri: "https://http.cat/404", // ""
|
||||||
url: "https://http.cat/404", // "",
|
url: "https://http.cat/404", // "",
|
||||||
account: {
|
account: {
|
||||||
id: "9arzuvv0sw",
|
id: "9arzuvv0sw",
|
||||||
username: "ReactionBot",
|
username: "Reactions",
|
||||||
acct: "ReactionBot",
|
acct: "Reactions",
|
||||||
display_name: "ReactionsToThisPost",
|
display_name: "Reactions to this post",
|
||||||
locked: false,
|
locked: false,
|
||||||
created_at: now,
|
created_at: now,
|
||||||
followers_count: 0,
|
followers_count: 0,
|
||||||
|
@ -443,8 +443,8 @@ export function statusModel(
|
||||||
statuses_count: 0,
|
statuses_count: 0,
|
||||||
note: "",
|
note: "",
|
||||||
url: "https://http.cat/404",
|
url: "https://http.cat/404",
|
||||||
avatar: "https://http.cat/404",
|
avatar: "/static-assets/badges/info.png",
|
||||||
avatar_static: "https://http.cat/404",
|
avatar_static: "/static-assets/badges/info.png",
|
||||||
header: "https://http.cat/404", // ""
|
header: "https://http.cat/404", // ""
|
||||||
header_static: "https://http.cat/404", // ""
|
header_static: "https://http.cat/404", // ""
|
||||||
emojis: [],
|
emojis: [],
|
||||||
|
|
Loading…
Reference in a new issue