|
|
@ -4,8 +4,9 @@ import Router from "@koa/router";
|
|
|
|
import { FindOptionsWhere, IsNull } from "typeorm";
|
|
|
|
import { FindOptionsWhere, IsNull } from "typeorm";
|
|
|
|
import { getClient } from "../ApiMastodonCompatibleService.js";
|
|
|
|
import { getClient } from "../ApiMastodonCompatibleService.js";
|
|
|
|
import { argsToBools, limitToInt } from "./timeline.js";
|
|
|
|
import { argsToBools, limitToInt } from "./timeline.js";
|
|
|
|
|
|
|
|
import { convertId, IdType } from "../../index.js";
|
|
|
|
|
|
|
|
|
|
|
|
const relationshopModel = {
|
|
|
|
const relationshipModel = {
|
|
|
|
id: "",
|
|
|
|
id: "",
|
|
|
|
following: false,
|
|
|
|
following: false,
|
|
|
|
followed_by: false,
|
|
|
|
followed_by: false,
|
|
|
@ -29,7 +30,8 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.verifyAccountCredentials();
|
|
|
|
const data = await client.verifyAccountCredentials();
|
|
|
|
const acct = data.data;
|
|
|
|
let acct = data.data;
|
|
|
|
|
|
|
|
acct.id = convertId(acct.id, IdType.MastodonId);
|
|
|
|
acct.url = `${BASE_URL}/@${acct.url}`;
|
|
|
|
acct.url = `${BASE_URL}/@${acct.url}`;
|
|
|
|
acct.note = "";
|
|
|
|
acct.note = "";
|
|
|
|
acct.avatar_static = acct.avatar;
|
|
|
|
acct.avatar_static = acct.avatar;
|
|
|
@ -42,6 +44,7 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
sensitive: false,
|
|
|
|
sensitive: false,
|
|
|
|
language: "",
|
|
|
|
language: "",
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
console.log(acct);
|
|
|
|
ctx.body = acct;
|
|
|
|
ctx.body = acct;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
@ -58,7 +61,9 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const data = await client.updateCredentials(
|
|
|
|
const data = await client.updateCredentials(
|
|
|
|
(ctx.request as any).body as any,
|
|
|
|
(ctx.request as any).body as any,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
resp.id = convertId(resp.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -71,8 +76,10 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.search((request.query as any).acct, 'accounts');
|
|
|
|
const data = await client.search((ctx.request.query as any).acct, 'accounts');
|
|
|
|
ctx.body = data.data.accounts[0];
|
|
|
|
let resp = data.data.accounts[0];
|
|
|
|
|
|
|
|
resp.id = convertId(resp.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -87,8 +94,11 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.getAccount(ctx.params.id);
|
|
|
|
const calcId = convertId(ctx.params.id, IdType.CalckeyId);
|
|
|
|
ctx.body = data.data;
|
|
|
|
const data = await client.getAccount(calcId);
|
|
|
|
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
resp.id = convertId(resp.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -105,10 +115,20 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.getAccountStatuses(
|
|
|
|
const data = await client.getAccountStatuses(
|
|
|
|
ctx.params.id,
|
|
|
|
convertId(ctx.params.id, IdType.CalckeyId),
|
|
|
|
argsToBools(limitToInt(ctx.query as any)),
|
|
|
|
argsToBools(limitToInt(ctx.query as any)),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
for (let statIdx = 0; statIdx < resp.length; statIdx++) {
|
|
|
|
|
|
|
|
resp[statIdx].id = convertId(resp[statIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
resp[statIdx].in_reply_to_account_id = resp[statIdx].in_reply_to_account_id ? convertId(resp[statIdx].in_reply_to_account_id, IdType.MastodonId) : null;
|
|
|
|
|
|
|
|
resp[statIdx].in_reply_to_id = resp[statIdx].in_reply_to_id ? convertId(resp[statIdx].in_reply_to_id, IdType.MastodonId) : null;
|
|
|
|
|
|
|
|
let mentions = resp[statIdx].mentions
|
|
|
|
|
|
|
|
for (let mtnIdx = 0; mtnIdx < mentions.length; mtnIdx++) {
|
|
|
|
|
|
|
|
resp[statIdx].mentions[mtnIdx].id = convertId(mentions[mtnIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -125,10 +145,14 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.getAccountFollowers(
|
|
|
|
const data = await client.getAccountFollowers(
|
|
|
|
ctx.params.id,
|
|
|
|
convertId(ctx.params.id, IdType.CalckeyId),
|
|
|
|
ctx.query as any,
|
|
|
|
limitToInt(ctx.query as any),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
for (let acctIdx = 0; acctIdx < resp.length; acctIdx++) {
|
|
|
|
|
|
|
|
resp[acctIdx].id = convertId(resp[acctIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -145,10 +169,14 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.getAccountFollowing(
|
|
|
|
const data = await client.getAccountFollowing(
|
|
|
|
ctx.params.id,
|
|
|
|
convertId(ctx.params.id, IdType.CalckeyId),
|
|
|
|
ctx.query as any,
|
|
|
|
limitToInt(ctx.query as any),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
for (let acctIdx = 0; acctIdx < resp.length; acctIdx++) {
|
|
|
|
|
|
|
|
resp[acctIdx].id = convertId(resp[acctIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -181,10 +209,11 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.followAccount(ctx.params.id);
|
|
|
|
const data = await client.followAccount(convertId(ctx.params.id, IdType.CalckeyId));
|
|
|
|
const acct = data.data;
|
|
|
|
let acct = data.data;
|
|
|
|
acct.following = true;
|
|
|
|
acct.following = true;
|
|
|
|
ctx.body = data.data;
|
|
|
|
acct.id = convertId(acct.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = acct;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -200,10 +229,11 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.unfollowAccount(ctx.params.id);
|
|
|
|
const data = await client.unfollowAccount(convertId(ctx.params.id, IdType.CalckeyId));
|
|
|
|
const acct = data.data;
|
|
|
|
let acct = data.data;
|
|
|
|
|
|
|
|
acct.id = convertId(acct.id, IdType.MastodonId);
|
|
|
|
acct.following = false;
|
|
|
|
acct.following = false;
|
|
|
|
ctx.body = data.data;
|
|
|
|
ctx.body = acct;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -219,8 +249,10 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.blockAccount(ctx.params.id);
|
|
|
|
const data = await client.blockAccount(convertId(ctx.params.id, IdType.CalckeyId));
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
resp.id = convertId(resp.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -236,8 +268,10 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.unblockAccount(ctx.params.id);
|
|
|
|
const data = await client.unblockAccount(convertId(ctx.params.id, IdType.MastodonId));
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
resp.id = convertId(resp.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -254,10 +288,12 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.muteAccount(
|
|
|
|
const data = await client.muteAccount(
|
|
|
|
ctx.params.id,
|
|
|
|
convertId(ctx.params.id, IdType.CalckeyId),
|
|
|
|
(ctx.request as any).body as any,
|
|
|
|
(ctx.request as any).body as any,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
resp.id = convertId(resp.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -273,8 +309,10 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.unmuteAccount(ctx.params.id);
|
|
|
|
const data = await client.unmuteAccount(convertId(ctx.params.id, IdType.CalckeyId));
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
resp.id = convertId(resp.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -290,16 +328,23 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
let users;
|
|
|
|
let users;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// TODO: this should be body
|
|
|
|
// TODO: this should be body
|
|
|
|
const idsRaw = ctx.request.query ? ctx.request.query["id[]"] : null;
|
|
|
|
let ids = ctx.request.query ? ctx.request.query["id[]"] : null;
|
|
|
|
const ids = typeof idsRaw === "string" ? [idsRaw] : idsRaw;
|
|
|
|
if (typeof ids === "string") {
|
|
|
|
|
|
|
|
ids = [ids];
|
|
|
|
|
|
|
|
}
|
|
|
|
users = ids;
|
|
|
|
users = ids;
|
|
|
|
relationshopModel.id = idsRaw?.toString() || "1";
|
|
|
|
relationshipModel.id = ids?.toString() || "1";
|
|
|
|
if (!idsRaw) {
|
|
|
|
if (!ids) {
|
|
|
|
ctx.body = [relationshopModel];
|
|
|
|
ctx.body = [relationshipModel];
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = await client.getRelationships(ids);
|
|
|
|
const data = await client.getRelationships(ids);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
for (let acctIdx = 0; acctIdx < resp.length; acctIdx++) {
|
|
|
|
|
|
|
|
resp[acctIdx].id = convertId(resp[acctIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
let data = e.response.data;
|
|
|
|
let data = e.response.data;
|
|
|
@ -315,7 +360,17 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = (await client.getBookmarks(ctx.query as any)) as any;
|
|
|
|
const data = (await client.getBookmarks(ctx.query as any)) as any;
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
for (let statIdx = 0; statIdx < resp.length; statIdx++) {
|
|
|
|
|
|
|
|
resp[statIdx].id = convertId(resp[statIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
resp[statIdx].in_reply_to_account_id = resp[statIdx].in_reply_to_account_id ? convertId(resp[statIdx].in_reply_to_account_id, IdType.MastodonId) : null;
|
|
|
|
|
|
|
|
resp[statIdx].in_reply_to_id = resp[statIdx].in_reply_to_id ? convertId(resp[statIdx].in_reply_to_id, IdType.MastodonId) : null;
|
|
|
|
|
|
|
|
let mentions = resp[statIdx].mentions
|
|
|
|
|
|
|
|
for (let mtnIdx = 0; mtnIdx < mentions.length; mtnIdx++) {
|
|
|
|
|
|
|
|
resp[statIdx].mentions[mtnIdx].id = convertId(mentions[mtnIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -329,7 +384,17 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.getFavourites(ctx.query as any);
|
|
|
|
const data = await client.getFavourites(ctx.query as any);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
for (let statIdx = 0; statIdx < resp.length; statIdx++) {
|
|
|
|
|
|
|
|
resp[statIdx].id = convertId(resp[statIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
resp[statIdx].in_reply_to_account_id = resp[statIdx].in_reply_to_account_id ? convertId(resp[statIdx].in_reply_to_account_id, IdType.MastodonId) : null;
|
|
|
|
|
|
|
|
resp[statIdx].in_reply_to_id = resp[statIdx].in_reply_to_id ? convertId(resp[statIdx].in_reply_to_id, IdType.MastodonId) : null;
|
|
|
|
|
|
|
|
let mentions = resp[statIdx].mentions
|
|
|
|
|
|
|
|
for (let mtnIdx = 0; mtnIdx < mentions.length; mtnIdx++) {
|
|
|
|
|
|
|
|
resp[statIdx].mentions[mtnIdx].id = convertId(mentions[mtnIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -343,7 +408,11 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.getMutes(ctx.query as any);
|
|
|
|
const data = await client.getMutes(ctx.query as any);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
for (let acctIdx = 0; acctIdx < resp.length; acctIdx++) {
|
|
|
|
|
|
|
|
resp[acctIdx].id = convertId(resp[acctIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -357,7 +426,11 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.getBlocks(ctx.query as any);
|
|
|
|
const data = await client.getBlocks(ctx.query as any);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
for (let acctIdx = 0; acctIdx < resp.length; acctIdx++) {
|
|
|
|
|
|
|
|
resp[acctIdx].id = convertId(resp[acctIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -365,7 +438,7 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
ctx.body = e.response.data;
|
|
|
|
ctx.body = e.response.data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
router.get("/v1/follow_ctxs", async (ctx) => {
|
|
|
|
router.get("/v1/follow_requests", async (ctx) => {
|
|
|
|
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
|
|
|
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
@ -373,7 +446,11 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
const data = await client.getFollowRequests(
|
|
|
|
const data = await client.getFollowRequests(
|
|
|
|
((ctx.query as any) || { limit: 20 }).limit,
|
|
|
|
((ctx.query as any) || { limit: 20 }).limit,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
for (let acctIdx = 0; acctIdx < resp.length; acctIdx++) {
|
|
|
|
|
|
|
|
resp[acctIdx].id = convertId(resp[acctIdx].id, IdType.MastodonId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -382,14 +459,16 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
router.post<{ Params: { id: string } }>(
|
|
|
|
router.post<{ Params: { id: string } }>(
|
|
|
|
"/v1/follow_ctxs/:id/authorize",
|
|
|
|
"/v1/follow_requests/:id/authorize",
|
|
|
|
async (ctx) => {
|
|
|
|
async (ctx) => {
|
|
|
|
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
|
|
|
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.acceptFollowRequest(ctx.params.id);
|
|
|
|
const data = await client.acceptFollowRequest(convertId(ctx.params.id, IdType.CalckeyId));
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
resp.id = convertId(resp.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
@ -399,14 +478,16 @@ export function apiAccountMastodon(router: Router): void {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
router.post<{ Params: { id: string } }>(
|
|
|
|
router.post<{ Params: { id: string } }>(
|
|
|
|
"/v1/follow_ctxs/:id/reject",
|
|
|
|
"/v1/follow_requests/:id/reject",
|
|
|
|
async (ctx) => {
|
|
|
|
async (ctx) => {
|
|
|
|
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
|
|
|
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const accessTokens = ctx.headers.authorization;
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
const client = getClient(BASE_URL, accessTokens);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await client.rejectFollowRequest(ctx.params.id);
|
|
|
|
const data = await client.rejectFollowRequest(convertId(ctx.params.id, IdType.CalckeyId));
|
|
|
|
ctx.body = data.data;
|
|
|
|
let resp = data.data;
|
|
|
|
|
|
|
|
resp.id = convertId(resp.id, IdType.MastodonId);
|
|
|
|
|
|
|
|
ctx.body = resp;
|
|
|
|
} catch (e: any) {
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
console.error(e.response.data);
|
|
|
|
console.error(e.response.data);
|
|
|
|