mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-25 10:19:06 +01:00
[mastodon-client] POST /statuses/:id/react/:name, /statuses/:id/unreact/:name
This commit is contained in:
parent
93a4db4418
commit
3dffaf5594
@ -466,15 +466,26 @@ export function apiStatusMastodon(router: Router): void {
|
|||||||
router.post<{ Params: { id: string; name: string } }>(
|
router.post<{ Params: { id: string; name: string } }>(
|
||||||
"/v1/statuses/:id/react/:name",
|
"/v1/statuses/:id/react/:name",
|
||||||
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.reactStatus(
|
const auth = await authenticate(ctx.headers.authorization, null);
|
||||||
convertId(ctx.params.id, IdType.IceshrimpId),
|
const user = auth[0] ?? null;
|
||||||
ctx.params.name,
|
|
||||||
);
|
if (!user) {
|
||||||
ctx.body = convertStatus(data.data);
|
ctx.status = 401;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = convertId(ctx.params.id, IdType.IceshrimpId);
|
||||||
|
const note = await getNote(id, user).catch(_ => null);
|
||||||
|
|
||||||
|
if (note === null) {
|
||||||
|
ctx.status = 404;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.body = await NoteHelpers.reactToNote(note, user, ctx.params.name)
|
||||||
|
.then(p => NoteConverter.encode(p, user))
|
||||||
|
.then(p => convertStatus(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
@ -486,15 +497,26 @@ export function apiStatusMastodon(router: Router): void {
|
|||||||
router.post<{ Params: { id: string; name: string } }>(
|
router.post<{ Params: { id: string; name: string } }>(
|
||||||
"/v1/statuses/:id/unreact/:name",
|
"/v1/statuses/:id/unreact/:name",
|
||||||
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.unreactStatus(
|
const auth = await authenticate(ctx.headers.authorization, null);
|
||||||
convertId(ctx.params.id, IdType.IceshrimpId),
|
const user = auth[0] ?? null;
|
||||||
ctx.params.name,
|
|
||||||
);
|
if (!user) {
|
||||||
ctx.body = convertStatus(data.data);
|
ctx.status = 401;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = convertId(ctx.params.id, IdType.IceshrimpId);
|
||||||
|
const note = await getNote(id, user).catch(_ => null);
|
||||||
|
|
||||||
|
if (note === null) {
|
||||||
|
ctx.status = 404;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.body = await NoteHelpers.removeReactFromNote(note, user)
|
||||||
|
.then(p => NoteConverter.encode(p, user))
|
||||||
|
.then(p => convertStatus(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
Loading…
Reference in New Issue
Block a user