diff --git a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts index 664e5a9b4..0878faf89 100644 --- a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts +++ b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts @@ -800,13 +800,14 @@ export class MastodonApiServerService { const accessTokens = _request.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - const data = await client.updateMedia(convertId(_request.params.id, IdType.SharkeyId), _request.body as any); + const data = await client.updateMedia(convertId(_request.params.id, IdType.SharkeyId), _request.body!); reply.send(convertAttachment(data.data)); } catch (e: any) { /* console.error(e); */ reply.code(401).send(e.response.data); } }); + NoteEndpoint.updateStatus(); // DELETE Endpoint NoteEndpoint.deleteStatus(); diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index b2c4266fa..a6538ddcf 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -212,6 +212,21 @@ export class ApiStatusMastodon { }); } + public async updateStatus() { + this.fastify.put<{ Params: { id: string } }>('/v1/statuses/:id', 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.editStatus(convertId(_request.params.id, IdType.SharkeyId), _request.body!); + reply.send(convertStatus(data.data)); + } catch (e: any) { + console.error(e); + reply.code(_request.is404 ? 404 : 401).send(e.response.data); + } + }); + } + public async addFavourite() { this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/favourite', async (_request, reply) => { const BASE_URL = `${_request.protocol}://${_request.hostname}`; diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index c4374adcb..6024f2bf9 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1147,12 +1147,53 @@ export default class Misskey implements MegalodonInterface { sensitive?: boolean media_ids?: Array poll?: { options?: Array; expires_in?: number; multiple?: boolean; hide_totals?: boolean } + visibility?: "public" | "unlisted" | "private" | "direct" } ): Promise> { - return new Promise((_, reject) => { - const err = new NoImplementedError('misskey does not support') - reject(err) - }) + let params = { + editId: _id, + text: _options.status + } + if (_options) { + if (_options.media_ids) { + params = Object.assign(params, { + fileIds: _options.media_ids + }) + } + if (_options.poll) { + let pollParam = { + choices: _options.poll.options, + expiresAt: null, + expiredAfter: _options.poll.expires_in + } + if (_options.poll.multiple !== undefined) { + pollParam = Object.assign(pollParam, { + multiple: _options.poll.multiple + }) + } + params = Object.assign(params, { + poll: pollParam + }) + } + if (_options.sensitive) { + params = Object.assign(params, { + cw: '' + }) + } + if (_options.spoiler_text) { + params = Object.assign(params, { + cw: _options.spoiler_text + }) + } + if (_options.visibility) { + params = Object.assign(params, { + visibility: MisskeyAPI.Converter.encodeVisibility(_options.visibility) + }) + } + } + return this.client + .post('/api/notes/edit', params) + .then(res => ({ ...res, data: MisskeyAPI.Converter.note(res.data.createdNote, this.baseUrl) })) } /**