Merge branch 'develop' of codeberg.org:calckey/calckey into develop

This commit is contained in:
ThatOneCalculator 2023-02-11 16:22:00 -08:00
commit cbdd09dd4a
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
3 changed files with 70 additions and 39 deletions

View File

@ -1,11 +1,26 @@
import megalodon, { MegalodonInterface } from "@cutls/megalodon";
import Router from "@koa/router";
import { koaBody } from "koa-body";
import { getClient } from "../ApiMastodonCompatibleService.js";
import { toLimitToInt } from "./timeline.js";
const relationshopModel = {
id: "",
following: false,
followed_by: false,
delivery_following: false,
blocking: false,
blocked_by: false,
muting: false,
muting_notifications: false,
requested: false,
domain_blocking: false,
showing_reblogs: false,
endorsed: false,
notifying: false,
note: "",
};
export function apiAccountMastodon(router: Router): void {
router.get("/v1/accounts/verify_credentials", async (ctx, next) => {
router.get("/v1/accounts/verify_credentials", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -48,9 +63,23 @@ export function apiAccountMastodon(router: Router): void {
ctx.body = e.response.data;
}
});
router.get<{ Params: { id: string } }>(
"/v1/accounts/:id",
async (ctx, next) => {
router.get("/v1/accounts/lookup", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.getAccount(
`@${(ctx.query.acct || "").toString()}`,
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
ctx.status = 401;
ctx.body = e.response.data;
}
});
router.get<{ Params: { id: string } }>("/v1/accounts/:id", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -63,11 +92,10 @@ export function apiAccountMastodon(router: Router): void {
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
});
router.get<{ Params: { id: string } }>(
"/v1/accounts/:id/statuses",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -87,7 +115,7 @@ export function apiAccountMastodon(router: Router): void {
);
router.get<{ Params: { id: string } }>(
"/v1/accounts/:id/followers",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -107,7 +135,7 @@ export function apiAccountMastodon(router: Router): void {
);
router.get<{ Params: { id: string } }>(
"/v1/accounts/:id/following",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -127,7 +155,7 @@ export function apiAccountMastodon(router: Router): void {
);
router.get<{ Params: { id: string } }>(
"/v1/accounts/:id/lists",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -144,7 +172,7 @@ export function apiAccountMastodon(router: Router): void {
);
router.post<{ Params: { id: string } }>(
"/v1/accounts/:id/follow",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -163,7 +191,7 @@ export function apiAccountMastodon(router: Router): void {
);
router.post<{ Params: { id: string } }>(
"/v1/accounts/:id/unfollow",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -182,7 +210,7 @@ export function apiAccountMastodon(router: Router): void {
);
router.post<{ Params: { id: string } }>(
"/v1/accounts/:id/block",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -199,7 +227,7 @@ export function apiAccountMastodon(router: Router): void {
);
router.post<{ Params: { id: string } }>(
"/v1/accounts/:id/unblock",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -236,7 +264,7 @@ export function apiAccountMastodon(router: Router): void {
);
router.post<{ Params: { id: string } }>(
"/v1/accounts/:id/unmute",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -251,13 +279,15 @@ export function apiAccountMastodon(router: Router): void {
}
},
);
router.get("/v1/accounts/relationships", async (ctx, next) => {
router.get("/v1/accounts/relationships", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const idsRaw = (ctx.query as any)["id[]"];
const ids = typeof idsRaw === "string" ? [idsRaw] : idsRaw;
relationshopModel.id = idsRaw || "1";
if (!idsRaw) return [relationshopModel];
const data = (await client.getRelationships(ids)) as any;
ctx.body = data.data;
} catch (e: any) {
@ -267,7 +297,7 @@ export function apiAccountMastodon(router: Router): void {
ctx.body = e.response.data;
}
});
router.get("/v1/bookmarks", async (ctx, next) => {
router.get("/v1/bookmarks", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -281,7 +311,7 @@ export function apiAccountMastodon(router: Router): void {
ctx.body = e.response.data;
}
});
router.get("/v1/favourites", async (ctx, next) => {
router.get("/v1/favourites", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -295,7 +325,7 @@ export function apiAccountMastodon(router: Router): void {
ctx.body = e.response.data;
}
});
router.get("/v1/mutes", async (ctx, next) => {
router.get("/v1/mutes", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -309,7 +339,7 @@ export function apiAccountMastodon(router: Router): void {
ctx.body = e.response.data;
}
});
router.get("/v1/blocks", async (ctx, next) => {
router.get("/v1/blocks", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -323,7 +353,7 @@ export function apiAccountMastodon(router: Router): void {
ctx.body = e.response.data;
}
});
router.get("/v1/follow_ctxs", async (ctx, next) => {
router.get("/v1/follow_ctxs", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -341,7 +371,7 @@ export function apiAccountMastodon(router: Router): void {
});
router.post<{ Params: { id: string } }>(
"/v1/follow_ctxs/:id/authorize",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
@ -358,7 +388,7 @@ export function apiAccountMastodon(router: Router): void {
);
router.post<{ Params: { id: string } }>(
"/v1/follow_ctxs/:id/reject",
async (ctx, next) => {
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);

View File

@ -435,7 +435,7 @@ export function statusModel(
id: "9arzuvv0sw",
username: "ReactionBot",
acct: "ReactionBot",
display_name: "ReactionOfThisPost",
display_name: "ReactionsToThisPost",
locked: false,
created_at: now,
followers_count: 0,

View File

@ -6,8 +6,9 @@ import Autolinker from "autolinker";
import { ParsedUrlQuery } from "querystring";
export function toLimitToInt(q: ParsedUrlQuery) {
let object: any = q;
if (q.limit)
if (typeof q.limit === "string") q.limit = parseInt(q.limit, 10).toString();
if (typeof q.limit === "string") object.limit = parseInt(q.limit, 10);
return q;
}