mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 08:53:48 +01:00
[mastodon-client] GET /accounts/:id/lists
This commit is contained in:
parent
239fef3e71
commit
4fe62e62c3
@ -9,6 +9,7 @@ import authenticate from "@/server/api/authenticate.js";
|
|||||||
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
||||||
import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
||||||
import { PaginationHelpers } from "@/server/api/mastodon/helpers/pagination.js";
|
import { PaginationHelpers } from "@/server/api/mastodon/helpers/pagination.js";
|
||||||
|
import { ListHelpers } from "@/server/api/mastodon/helpers/list.js";
|
||||||
|
|
||||||
export function setupEndpointsAccount(router: Router): void {
|
export function setupEndpointsAccount(router: Router): void {
|
||||||
router.get("/v1/accounts/verify_credentials", async (ctx) => {
|
router.get("/v1/accounts/verify_credentials", async (ctx) => {
|
||||||
@ -194,19 +195,21 @@ export function setupEndpointsAccount(router: Router): void {
|
|||||||
router.get<{ Params: { id: string } }>(
|
router.get<{ Params: { id: string } }>(
|
||||||
"/v1/accounts/:id/lists",
|
"/v1/accounts/:id/lists",
|
||||||
async (ctx) => {
|
async (ctx) => {
|
||||||
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
|
||||||
const accessTokens = ctx.headers.authorization;
|
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
|
||||||
try {
|
try {
|
||||||
const data = await client.getAccountLists(
|
const auth = await authenticate(ctx.headers.authorization, null);
|
||||||
convertId(ctx.params.id, IdType.IceshrimpId),
|
const user = auth[0] ?? null;
|
||||||
);
|
|
||||||
ctx.body = data.data.map((list) => convertList(list));
|
if (!user) {
|
||||||
} catch (e: any) {
|
|
||||||
console.error(e);
|
|
||||||
console.error(e.response.data);
|
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
ctx.body = e.response.data;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const member = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
|
const results = await ListHelpers.getListsByMember(user, member);
|
||||||
|
ctx.body = results.map(p => convertList(p));
|
||||||
|
} catch (e: any) {
|
||||||
|
ctx.status = 400;
|
||||||
|
ctx.body = { error: e.message };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -123,4 +123,22 @@ export class ListHelpers {
|
|||||||
title: result.name
|
title: result.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async getListsByMember(user: ILocalUser, member: User): Promise<MastodonEntity.List[]> {
|
||||||
|
const joinQuery = UserListJoinings.createQueryBuilder('member')
|
||||||
|
.select("member.userListId")
|
||||||
|
.where("member.userId = :memberId");
|
||||||
|
const query = UserLists.createQueryBuilder('list')
|
||||||
|
.where("list.userId = :userId", {userId: user.id})
|
||||||
|
.andWhere(`list.id IN (${joinQuery.getQuery()})`)
|
||||||
|
.setParameters({memberId: member.id});
|
||||||
|
|
||||||
|
return query.getMany()
|
||||||
|
.then(results => results.map(result => {
|
||||||
|
return {
|
||||||
|
id: result.id,
|
||||||
|
title: result.name
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user