mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 01:43:08 +02:00
add: source endpoint for editing through masto api
This commit is contained in:
parent
e32b03a048
commit
a12d1c52dd
5 changed files with 37 additions and 5 deletions
|
@ -773,6 +773,7 @@ export class MastodonApiServerService {
|
||||||
|
|
||||||
// GET Endpoints
|
// GET Endpoints
|
||||||
NoteEndpoint.getStatus();
|
NoteEndpoint.getStatus();
|
||||||
|
NoteEndpoint.getStatusSource();
|
||||||
NoteEndpoint.getContext();
|
NoteEndpoint.getContext();
|
||||||
NoteEndpoint.getHistory();
|
NoteEndpoint.getHistory();
|
||||||
NoteEndpoint.getReblogged();
|
NoteEndpoint.getReblogged();
|
||||||
|
|
|
@ -121,6 +121,10 @@ export function convertStatus(status: Entity.Status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function convertStatusSource(status: Entity.StatusSource) {
|
||||||
|
return simpleConvert(status);
|
||||||
|
}
|
||||||
|
|
||||||
export function convertConversation(conversation: Entity.Conversation) {
|
export function convertConversation(conversation: Entity.Conversation) {
|
||||||
conversation.id = convertId(conversation.id, IdConvertType.MastodonId);
|
conversation.id = convertId(conversation.id, IdConvertType.MastodonId);
|
||||||
conversation.accounts = conversation.accounts.map(convertAccount);
|
conversation.accounts = conversation.accounts.map(convertAccount);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import querystring from 'querystring';
|
import querystring from 'querystring';
|
||||||
import { emojiRegexAtStartToEnd } from '@/misc/emoji-regex.js';
|
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 { getClient } from '../MastodonApiServerService.js';
|
||||||
import { convertTimelinesArgsId, limitToInt } from './timeline.js';
|
import { convertTimelinesArgsId, limitToInt } from './timeline.js';
|
||||||
import type { Entity } from 'megalodon';
|
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() {
|
public async getContext() {
|
||||||
this.fastify.get<{ Params: { id: string } }>('/v1/statuses/:id/context', async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/statuses/:id/context', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
|
|
|
@ -1295,11 +1295,15 @@ export default class Misskey implements MegalodonInterface {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/notes/show
|
||||||
|
*/
|
||||||
public async getStatusSource(_id: string): Promise<Response<Entity.StatusSource>> {
|
public async getStatusSource(_id: string): Promise<Response<Entity.StatusSource>> {
|
||||||
return new Promise((_, reject) => {
|
return this.client
|
||||||
const err = new NoImplementedError('misskey does not support')
|
.post<MisskeyAPI.Entity.Note>('/api/notes/show', {
|
||||||
reject(err)
|
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> => {
|
const mapEmojis = (e: Array<Entity.Emoji> | { [key: string]: string }): Array<MegalodonEntity.Emoji> => {
|
||||||
if (Array.isArray(e)) {
|
if (Array.isArray(e)) {
|
||||||
return e.map(e => emoji(e))
|
return e.map(e => emoji(e))
|
||||||
|
|
Loading…
Reference in a new issue