add: source endpoint for editing through masto api
This commit is contained in:
parent
e32b03a048
commit
a12d1c52dd
@ -773,6 +773,7 @@ export class MastodonApiServerService {
|
||||
|
||||
// GET Endpoints
|
||||
NoteEndpoint.getStatus();
|
||||
NoteEndpoint.getStatusSource();
|
||||
NoteEndpoint.getContext();
|
||||
NoteEndpoint.getHistory();
|
||||
NoteEndpoint.getReblogged();
|
||||
|
@ -121,6 +121,10 @@ export function convertStatus(status: Entity.Status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
export function convertStatusSource(status: Entity.StatusSource) {
|
||||
return simpleConvert(status);
|
||||
}
|
||||
|
||||
export function convertConversation(conversation: Entity.Conversation) {
|
||||
conversation.id = convertId(conversation.id, IdConvertType.MastodonId);
|
||||
conversation.accounts = conversation.accounts.map(convertAccount);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import querystring from 'querystring';
|
||||
import { emojiRegexAtStartToEnd } from '@/misc/emoji-regex.js';
|
||||
import { convertId, IdConvertType as IdType, convertAccount, convertAttachment, convertPoll, convertStatus } from '../converters.js';
|
||||
import { convertId, IdConvertType as IdType, convertAccount, convertAttachment, convertPoll, convertStatus, convertStatusSource } from '../converters.js';
|
||||
import { getClient } from '../MastodonApiServerService.js';
|
||||
import { convertTimelinesArgsId, limitToInt } from './timeline.js';
|
||||
import type { Entity } from 'megalodon';
|
||||
@ -33,6 +33,21 @@ export class ApiStatusMastodon {
|
||||
});
|
||||
}
|
||||
|
||||
public async getStatusSource() {
|
||||
this.fastify.get<{ Params: { id: string } }>('/v1/statuses/:id/source', async (_request, reply) => {
|
||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||
const accessTokens = _request.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
try {
|
||||
const data = await client.getStatusSource(convertId(_request.params.id, IdType.SharkeyId));
|
||||
reply.send(convertStatusSource(data.data));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
reply.code(_request.is404 ? 404 : 401).send(e.response.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async getContext() {
|
||||
this.fastify.get<{ Params: { id: string } }>('/v1/statuses/:id/context', async (_request, reply) => {
|
||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||
|
@ -1295,11 +1295,15 @@ export default class Misskey implements MegalodonInterface {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/notes/show
|
||||
*/
|
||||
public async getStatusSource(_id: string): Promise<Response<Entity.StatusSource>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('misskey does not support')
|
||||
reject(err)
|
||||
})
|
||||
return this.client
|
||||
.post<MisskeyAPI.Entity.Note>('/api/notes/show', {
|
||||
noteId: _id
|
||||
})
|
||||
.then(res => ({ ...res, data: MisskeyAPI.Converter.notesource(res.data) }))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,6 +305,14 @@ namespace MisskeyAPI {
|
||||
}
|
||||
}
|
||||
|
||||
export const notesource = (n: Entity.Note): MegalodonEntity.StatusSource => {
|
||||
return {
|
||||
id: n.id,
|
||||
text: n.text ?? '',
|
||||
spoiler_text: n.cw ? n.cw : ''
|
||||
}
|
||||
}
|
||||
|
||||
const mapEmojis = (e: Array<Entity.Emoji> | { [key: string]: string }): Array<MegalodonEntity.Emoji> => {
|
||||
if (Array.isArray(e)) {
|
||||
return e.map(e => emoji(e))
|
||||
|
Loading…
Reference in New Issue
Block a user