mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-25 02:09:05 +01:00
[mastodon-client] GET /statuses/:id/source
This commit is contained in:
parent
ae91ffbb8a
commit
a7ce94fb29
@ -56,6 +56,9 @@ export function convertSearch(search: MastodonEntity.Search) {
|
|||||||
return search;
|
return search;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function convertStatusSource(statusSource: MastodonEntity.StatusSource) {
|
||||||
|
return simpleConvert(statusSource);
|
||||||
|
}
|
||||||
|
|
||||||
export function convertStatus(status: MastodonEntity.Status) {
|
export function convertStatus(status: MastodonEntity.Status) {
|
||||||
status.account = convertAccount(status.account);
|
status.account = convertAccount(status.account);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { convertId, IdType } from "../../index.js";
|
import { convertId, IdType } from "../../index.js";
|
||||||
import { convertAccount, convertPoll, convertStatus, convertStatusEdit, } from "../converters.js";
|
import { convertAccount, convertPoll, convertStatus, convertStatusEdit, convertStatusSource, } from "../converters.js";
|
||||||
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
||||||
import { getNote } from "@/server/api/common/getters.js";
|
import { getNote } from "@/server/api/common/getters.js";
|
||||||
import authenticate from "@/server/api/authenticate.js";
|
import authenticate from "@/server/api/authenticate.js";
|
||||||
@ -202,6 +202,30 @@ export function setupEndpointsStatus(router: Router): void {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
router.get<{ Params: { id: string } }>(
|
||||||
|
"/v1/statuses/:id/source",
|
||||||
|
async (ctx) => {
|
||||||
|
try {
|
||||||
|
const auth = await authenticate(ctx.headers.authorization, null);
|
||||||
|
const user = auth[0] ?? null;
|
||||||
|
|
||||||
|
const id = convertId(ctx.params.id, IdType.IceshrimpId);
|
||||||
|
const note = await getNote(id, user).catch(_ => null);
|
||||||
|
|
||||||
|
if (note === null) {
|
||||||
|
ctx.status = 404;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const src = NoteHelpers.getNoteSource(note);
|
||||||
|
ctx.body = convertStatusSource(src);
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error(e);
|
||||||
|
ctx.status = 401;
|
||||||
|
ctx.body = e.response.data;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
router.get<{ Params: { id: string } }>(
|
router.get<{ Params: { id: string } }>(
|
||||||
"/v1/statuses/:id/reblogged_by",
|
"/v1/statuses/:id/reblogged_by",
|
||||||
async (ctx) => {
|
async (ctx) => {
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace MastodonEntity {
|
||||||
|
export type StatusSource = {
|
||||||
|
id: string;
|
||||||
|
text: string;
|
||||||
|
spoiler_text: string;
|
||||||
|
};
|
||||||
|
}
|
@ -201,6 +201,14 @@ export class NoteHelpers {
|
|||||||
return Promise.all(history);
|
return Promise.all(history);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static getNoteSource(note: Note): MastodonEntity.StatusSource {
|
||||||
|
return {
|
||||||
|
id: note.id,
|
||||||
|
text: note.text ?? '',
|
||||||
|
spoiler_text: note.cw ?? ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async getNoteRebloggedBy(note: Note, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 40): Promise<LinkPaginationObject<User[]>> {
|
public static async getNoteRebloggedBy(note: Note, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 40): Promise<LinkPaginationObject<User[]>> {
|
||||||
if (limit > 80) limit = 80;
|
if (limit > 80) limit = 80;
|
||||||
const query = PaginationHelpers.makePaginationQuery(
|
const query = PaginationHelpers.makePaginationQuery(
|
||||||
|
Loading…
Reference in New Issue
Block a user