mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
normalize mastodon BAD_REQUEST errors
This commit is contained in:
parent
67e57ab50a
commit
4a1dd7165e
9 changed files with 73 additions and 71 deletions
|
@ -110,7 +110,7 @@ export class MastodonApiServerService {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Body: { id?: string } }>('/v1/announcements/:id/dismiss', async (_request, reply) => {
|
fastify.post<{ Body: { id?: string } }>('/v1/announcements/:id/dismiss', async (_request, reply) => {
|
||||||
if (!_request.body.id) return reply.code(400).send({ error: 'Missing required payload "id"' });
|
if (!_request.body.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.dismissInstanceAnnouncement(_request.body.id);
|
const data = await client.dismissInstanceAnnouncement(_request.body.id);
|
||||||
|
@ -222,7 +222,7 @@ export class MastodonApiServerService {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Querystring: TimelineArgs, Params: { id?: string } }>('/v1/follow_requests/:id/authorize', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<{ Querystring: TimelineArgs, Params: { id?: string } }>('/v1/follow_requests/:id/authorize', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.acceptFollowRequest(_request.params.id);
|
const data = await client.acceptFollowRequest(_request.params.id);
|
||||||
|
@ -232,7 +232,7 @@ export class MastodonApiServerService {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Querystring: TimelineArgs, Params: { id?: string } }>('/v1/follow_requests/:id/reject', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<{ Querystring: TimelineArgs, Params: { id?: string } }>('/v1/follow_requests/:id/reject', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.rejectFollowRequest(_request.params.id);
|
const data = await client.rejectFollowRequest(_request.params.id);
|
||||||
|
@ -253,7 +253,7 @@ export class MastodonApiServerService {
|
||||||
is_sensitive?: string,
|
is_sensitive?: string,
|
||||||
},
|
},
|
||||||
}>('/v1/media/:id', { preHandler: upload.none() }, async (_request, reply) => {
|
}>('/v1/media/:id', { preHandler: upload.none() }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
..._request.body,
|
..._request.body,
|
||||||
|
|
|
@ -143,7 +143,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Querystring: { acct?: string }}>('/v1/accounts/lookup', async (_request, reply) => {
|
fastify.get<{ Querystring: { acct?: string }}>('/v1/accounts/lookup', async (_request, reply) => {
|
||||||
if (!_request.query.acct) return reply.code(400).send({ error: 'Missing required property "acct"' });
|
if (!_request.query.acct) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required property "acct"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.search(_request.query.acct, { type: 'accounts' });
|
const data = await client.search(_request.query.acct, { type: 'accounts' });
|
||||||
|
@ -168,7 +168,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/accounts/:id', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/accounts/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getAccount(_request.params.id);
|
const data = await client.getAccount(_request.params.id);
|
||||||
|
@ -178,17 +178,18 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/statuses', async (_request, reply) => {
|
fastify.get<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/statuses', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.getAccountStatuses(_request.params.id, parseTimelineArgs(_request.query));
|
const args = parseTimelineArgs(_request.query);
|
||||||
|
const data = await client.getAccountStatuses(_request.params.id, args);
|
||||||
const response = await Promise.all(data.data.map(async (status) => await this.mastoConverters.convertStatus(status, me)));
|
const response = await Promise.all(data.data.map(async (status) => await this.mastoConverters.convertStatus(status, me)));
|
||||||
|
|
||||||
reply.send(response);
|
reply.send(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/accounts/:id/featured_tags', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/accounts/:id/featured_tags', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getFeaturedTags();
|
const data = await client.getFeaturedTags();
|
||||||
|
@ -198,7 +199,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/followers', async (_request, reply) => {
|
fastify.get<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/followers', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getAccountFollowers(
|
const data = await client.getAccountFollowers(
|
||||||
|
@ -211,7 +212,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/following', async (_request, reply) => {
|
fastify.get<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/following', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getAccountFollowing(
|
const data = await client.getAccountFollowing(
|
||||||
|
@ -224,7 +225,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/accounts/:id/lists', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/accounts/:id/lists', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getAccountLists(_request.params.id);
|
const data = await client.getAccountLists(_request.params.id);
|
||||||
|
@ -234,7 +235,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/follow', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/follow', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.followAccount(_request.params.id);
|
const data = await client.followAccount(_request.params.id);
|
||||||
|
@ -245,7 +246,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/unfollow', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/unfollow', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.unfollowAccount(_request.params.id);
|
const data = await client.unfollowAccount(_request.params.id);
|
||||||
|
@ -256,7 +257,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/block', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/block', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.blockAccount(_request.params.id);
|
const data = await client.blockAccount(_request.params.id);
|
||||||
|
@ -266,7 +267,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/unblock', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/unblock', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.unblockAccount(_request.params.id);
|
const data = await client.unblockAccount(_request.params.id);
|
||||||
|
@ -276,7 +277,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/mute', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/mute', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.muteAccount(
|
const data = await client.muteAccount(
|
||||||
|
@ -289,7 +290,7 @@ export class ApiAccountMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/unmute', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<ApiAccountMastodonRoute & { Params: { id?: string } }>('/v1/accounts/:id/unmute', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.unmuteAccount(_request.params.id);
|
const data = await client.unmuteAccount(_request.params.id);
|
||||||
|
|
|
@ -65,9 +65,9 @@ export class ApiAppsMastodon {
|
||||||
public register(fastify: FastifyInstance, upload: ReturnType<typeof multer>): void {
|
public register(fastify: FastifyInstance, upload: ReturnType<typeof multer>): void {
|
||||||
fastify.post<AuthMastodonRoute>('/v1/apps', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<AuthMastodonRoute>('/v1/apps', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
const body = _request.body ?? _request.query;
|
const body = _request.body ?? _request.query;
|
||||||
if (!body.scopes) return reply.code(400).send({ error: 'Missing required payload "scopes"' });
|
if (!body.scopes) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "scopes"' });
|
||||||
if (!body.redirect_uris) return reply.code(400).send({ error: 'Missing required payload "redirect_uris"' });
|
if (!body.redirect_uris) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "redirect_uris"' });
|
||||||
if (!body.client_name) return reply.code(400).send({ error: 'Missing required payload "client_name"' });
|
if (!body.client_name) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "client_name"' });
|
||||||
|
|
||||||
let scope = body.scopes;
|
let scope = body.scopes;
|
||||||
if (typeof scope === 'string') {
|
if (typeof scope === 'string') {
|
||||||
|
|
|
@ -40,7 +40,7 @@ export class ApiFilterMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<ApiFilterMastodonRoute & { Params: { id?: string } }>('/v1/filters/:id', async (_request, reply) => {
|
fastify.get<ApiFilterMastodonRoute & { Params: { id?: string } }>('/v1/filters/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getFilter(_request.params.id);
|
const data = await client.getFilter(_request.params.id);
|
||||||
|
@ -50,8 +50,8 @@ export class ApiFilterMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<ApiFilterMastodonRoute>('/v1/filters', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<ApiFilterMastodonRoute>('/v1/filters', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.body.phrase) return reply.code(400).send({ error: 'Missing required payload "phrase"' });
|
if (!_request.body.phrase) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "phrase"' });
|
||||||
if (!_request.body.context) return reply.code(400).send({ error: 'Missing required payload "context"' });
|
if (!_request.body.context) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "context"' });
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
phrase: _request.body.phrase,
|
phrase: _request.body.phrase,
|
||||||
|
@ -69,9 +69,9 @@ export class ApiFilterMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<ApiFilterMastodonRoute & { Params: { id?: string } }>('/v1/filters/:id', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<ApiFilterMastodonRoute & { Params: { id?: string } }>('/v1/filters/:id', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
if (!_request.body.phrase) return reply.code(400).send({ error: 'Missing required payload "phrase"' });
|
if (!_request.body.phrase) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "phrase"' });
|
||||||
if (!_request.body.context) return reply.code(400).send({ error: 'Missing required payload "context"' });
|
if (!_request.body.context) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "context"' });
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
phrase: _request.body.phrase,
|
phrase: _request.body.phrase,
|
||||||
|
@ -89,7 +89,7 @@ export class ApiFilterMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.delete<ApiFilterMastodonRoute & { Params: { id?: string } }>('/v1/filters/:id', async (_request, reply) => {
|
fastify.delete<ApiFilterMastodonRoute & { Params: { id?: string } }>('/v1/filters/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.deleteFilter(_request.params.id);
|
const data = await client.deleteFilter(_request.params.id);
|
||||||
|
|
|
@ -40,7 +40,7 @@ export class ApiNotificationsMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<ApiNotifyMastodonRoute & { Params: { id?: string } }>('/v1/notification/:id', async (_request, reply) => {
|
fastify.get<ApiNotifyMastodonRoute & { Params: { id?: string } }>('/v1/notification/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.getNotification(_request.params.id);
|
const data = await client.getNotification(_request.params.id);
|
||||||
|
@ -53,7 +53,7 @@ export class ApiNotificationsMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<ApiNotifyMastodonRoute & { Params: { id?: string } }>('/v1/notification/:id/dismiss', { preHandler: upload.single('none') }, async (_request, reply) => {
|
fastify.post<ApiNotifyMastodonRoute & { Params: { id?: string } }>('/v1/notification/:id/dismiss', { preHandler: upload.single('none') }, async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.dismissNotification(_request.params.id);
|
const data = await client.dismissNotification(_request.params.id);
|
||||||
|
|
|
@ -27,7 +27,8 @@ export class ApiSearchMastodon {
|
||||||
|
|
||||||
public register(fastify: FastifyInstance): void {
|
public register(fastify: FastifyInstance): void {
|
||||||
fastify.get<ApiSearchMastodonRoute>('/v1/search', async (_request, reply) => {
|
fastify.get<ApiSearchMastodonRoute>('/v1/search', async (_request, reply) => {
|
||||||
if (!_request.query.q) return reply.code(400).send({ error: 'Missing required property "q"' });
|
if (!_request.query.q) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required property "q"' });
|
||||||
|
if (!_request.query.type) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required property "type"' });
|
||||||
|
|
||||||
const query = parseTimelineArgs(_request.query);
|
const query = parseTimelineArgs(_request.query);
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
|
@ -37,7 +38,7 @@ export class ApiSearchMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<ApiSearchMastodonRoute>('/v2/search', async (_request, reply) => {
|
fastify.get<ApiSearchMastodonRoute>('/v2/search', async (_request, reply) => {
|
||||||
if (!_request.query.q) return reply.code(400).send({ error: 'Missing required property "q"' });
|
if (!_request.query.q) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required property "q"' });
|
||||||
|
|
||||||
const query = parseTimelineArgs(_request.query);
|
const query = parseTimelineArgs(_request.query);
|
||||||
const type = _request.query.type;
|
const type = _request.query.type;
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class ApiStatusMastodon {
|
||||||
|
|
||||||
public register(fastify: FastifyInstance): void {
|
public register(fastify: FastifyInstance): void {
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.getStatus(_request.params.id);
|
const data = await client.getStatus(_request.params.id);
|
||||||
|
@ -36,7 +36,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id/source', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id/source', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getStatusSource(_request.params.id);
|
const data = await client.getStatusSource(_request.params.id);
|
||||||
|
@ -45,7 +45,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string }, Querystring: TimelineArgs }>('/v1/statuses/:id/context', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string }, Querystring: TimelineArgs }>('/v1/statuses/:id/context', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const { data } = await client.getStatusContext(_request.params.id, parseTimelineArgs(_request.query));
|
const { data } = await client.getStatusContext(_request.params.id, parseTimelineArgs(_request.query));
|
||||||
|
@ -57,7 +57,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id/history', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id/history', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const user = await this.clientService.getAuth(_request);
|
const user = await this.clientService.getAuth(_request);
|
||||||
const edits = await this.mastoConverters.getEdits(_request.params.id, user);
|
const edits = await this.mastoConverters.getEdits(_request.params.id, user);
|
||||||
|
@ -66,7 +66,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id/reblogged_by', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id/reblogged_by', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getStatusRebloggedBy(_request.params.id);
|
const data = await client.getStatusRebloggedBy(_request.params.id);
|
||||||
|
@ -76,7 +76,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id/favourited_by', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/statuses/:id/favourited_by', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getStatusFavouritedBy(_request.params.id);
|
const data = await client.getStatusFavouritedBy(_request.params.id);
|
||||||
|
@ -86,7 +86,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/media/:id', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/media/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getMedia(_request.params.id);
|
const data = await client.getMedia(_request.params.id);
|
||||||
|
@ -96,7 +96,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/polls/:id', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/polls/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getPoll(_request.params.id);
|
const data = await client.getPoll(_request.params.id);
|
||||||
|
@ -106,8 +106,8 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string }, Body: { choices?: number[] } }>('/v1/polls/:id/votes', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string }, Body: { choices?: number[] } }>('/v1/polls/:id/votes', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
if (!_request.body.choices) return reply.code(400).send({ error: 'Missing required payload "choices"' });
|
if (!_request.body.choices) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "choices"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.votePoll(_request.params.id, _request.body.choices);
|
const data = await client.votePoll(_request.params.id, _request.body.choices);
|
||||||
|
@ -168,10 +168,10 @@ export class ApiStatusMastodon {
|
||||||
if (body.media_ids && !body.media_ids.length) body.media_ids = undefined;
|
if (body.media_ids && !body.media_ids.length) body.media_ids = undefined;
|
||||||
|
|
||||||
if (body.poll && !body.poll.options) {
|
if (body.poll && !body.poll.options) {
|
||||||
return reply.code(400).send({ error: 'Missing required payload "poll.options"' });
|
return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "poll.options"' });
|
||||||
}
|
}
|
||||||
if (body.poll && !body.poll.expires_in) {
|
if (body.poll && !body.poll.expires_in) {
|
||||||
return reply.code(400).send({ error: 'Missing required payload "poll.expires_in"' });
|
return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "poll.expires_in"' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -231,7 +231,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/favourite', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/favourite', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.createEmojiReaction(_request.params.id, '❤');
|
const data = await client.createEmojiReaction(_request.params.id, '❤');
|
||||||
|
@ -241,7 +241,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/unfavourite', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/unfavourite', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.deleteEmojiReaction(_request.params.id, '❤');
|
const data = await client.deleteEmojiReaction(_request.params.id, '❤');
|
||||||
|
@ -251,7 +251,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/reblog', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/reblog', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.reblogStatus(_request.params.id);
|
const data = await client.reblogStatus(_request.params.id);
|
||||||
|
@ -261,7 +261,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/unreblog', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/unreblog', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.unreblogStatus(_request.params.id);
|
const data = await client.unreblogStatus(_request.params.id);
|
||||||
|
@ -271,7 +271,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/bookmark', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/bookmark', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.bookmarkStatus(_request.params.id);
|
const data = await client.bookmarkStatus(_request.params.id);
|
||||||
|
@ -281,7 +281,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/unbookmark', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/unbookmark', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.unbookmarkStatus(_request.params.id);
|
const data = await client.unbookmarkStatus(_request.params.id);
|
||||||
|
@ -290,7 +290,7 @@ export class ApiStatusMastodon {
|
||||||
reply.send(response);
|
reply.send(response);
|
||||||
});
|
});
|
||||||
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/pin', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/pin', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.pinStatus(_request.params.id);
|
const data = await client.pinStatus(_request.params.id);
|
||||||
|
@ -300,7 +300,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/unpin', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string } }>('/v1/statuses/:id/unpin', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.unpinStatus(_request.params.id);
|
const data = await client.unpinStatus(_request.params.id);
|
||||||
|
@ -310,8 +310,8 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string, name?: string } }>('/v1/statuses/:id/react/:name', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string, name?: string } }>('/v1/statuses/:id/react/:name', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
if (!_request.params.name) return reply.code(400).send({ error: 'Missing required parameter "name"' });
|
if (!_request.params.name) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "name"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.createEmojiReaction(_request.params.id, _request.params.name);
|
const data = await client.createEmojiReaction(_request.params.id, _request.params.name);
|
||||||
|
@ -321,8 +321,8 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string, name?: string } }>('/v1/statuses/:id/unreact/:name', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string, name?: string } }>('/v1/statuses/:id/unreact/:name', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
if (!_request.params.name) return reply.code(400).send({ error: 'Missing required parameter "name"' });
|
if (!_request.params.name) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "name"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const data = await client.deleteEmojiReaction(_request.params.id, _request.params.name);
|
const data = await client.deleteEmojiReaction(_request.params.id, _request.params.name);
|
||||||
|
@ -332,7 +332,7 @@ export class ApiStatusMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.delete<{ Params: { id?: string } }>('/v1/statuses/:id', async (_request, reply) => {
|
fastify.delete<{ Params: { id?: string } }>('/v1/statuses/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.deleteStatus(_request.params.id);
|
const data = await client.deleteStatus(_request.params.id);
|
||||||
|
|
|
@ -39,7 +39,7 @@ export class ApiTimelineMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { hashtag?: string }, Querystring: TimelineArgs }>('/v1/timelines/tag/:hashtag', async (_request, reply) => {
|
fastify.get<{ Params: { hashtag?: string }, Querystring: TimelineArgs }>('/v1/timelines/tag/:hashtag', async (_request, reply) => {
|
||||||
if (!_request.params.hashtag) return reply.code(400).send({ error: 'Missing required parameter "hashtag"' });
|
if (!_request.params.hashtag) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "hashtag"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const query = parseTimelineArgs(_request.query);
|
const query = parseTimelineArgs(_request.query);
|
||||||
|
@ -50,7 +50,7 @@ export class ApiTimelineMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string }, Querystring: TimelineArgs }>('/v1/timelines/list/:id', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string }, Querystring: TimelineArgs }>('/v1/timelines/list/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||||
const query = parseTimelineArgs(_request.query);
|
const query = parseTimelineArgs(_request.query);
|
||||||
|
@ -70,7 +70,7 @@ export class ApiTimelineMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string } }>('/v1/lists/:id', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string } }>('/v1/lists/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getList(_request.params.id);
|
const data = await client.getList(_request.params.id);
|
||||||
|
@ -88,7 +88,7 @@ export class ApiTimelineMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get<{ Params: { id?: string }, Querystring: { limit?: number, max_id?: string, since_id?: string } }>('/v1/lists/:id/accounts', async (_request, reply) => {
|
fastify.get<{ Params: { id?: string }, Querystring: { limit?: number, max_id?: string, since_id?: string } }>('/v1/lists/:id/accounts', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.getAccountsInList(_request.params.id, _request.query);
|
const data = await client.getAccountsInList(_request.params.id, _request.query);
|
||||||
|
@ -98,8 +98,8 @@ export class ApiTimelineMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Params: { id?: string }, Querystring: { accounts_id?: string[] } }>('/v1/lists/:id/accounts', async (_request, reply) => {
|
fastify.post<{ Params: { id?: string }, Querystring: { accounts_id?: string[] } }>('/v1/lists/:id/accounts', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
if (!_request.query.accounts_id) return reply.code(400).send({ error: 'Missing required property "accounts_id"' });
|
if (!_request.query.accounts_id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required property "accounts_id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.addAccountsToList(_request.params.id, _request.query.accounts_id);
|
const data = await client.addAccountsToList(_request.params.id, _request.query.accounts_id);
|
||||||
|
@ -108,8 +108,8 @@ export class ApiTimelineMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.delete<{ Params: { id?: string }, Querystring: { accounts_id?: string[] } }>('/v1/lists/:id/accounts', async (_request, reply) => {
|
fastify.delete<{ Params: { id?: string }, Querystring: { accounts_id?: string[] } }>('/v1/lists/:id/accounts', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
if (!_request.query.accounts_id) return reply.code(400).send({ error: 'Missing required property "accounts_id"' });
|
if (!_request.query.accounts_id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required property "accounts_id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.deleteAccountsFromList(_request.params.id, _request.query.accounts_id);
|
const data = await client.deleteAccountsFromList(_request.params.id, _request.query.accounts_id);
|
||||||
|
@ -118,7 +118,7 @@ export class ApiTimelineMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.post<{ Body: { title?: string } }>('/v1/lists', async (_request, reply) => {
|
fastify.post<{ Body: { title?: string } }>('/v1/lists', async (_request, reply) => {
|
||||||
if (!_request.body.title) return reply.code(400).send({ error: 'Missing required payload "title"' });
|
if (!_request.body.title) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "title"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.createList(_request.body.title);
|
const data = await client.createList(_request.body.title);
|
||||||
|
@ -128,8 +128,8 @@ export class ApiTimelineMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.put<{ Params: { id?: string }, Body: { title?: string } }>('/v1/lists/:id', async (_request, reply) => {
|
fastify.put<{ Params: { id?: string }, Body: { title?: string } }>('/v1/lists/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
if (!_request.body.title) return reply.code(400).send({ error: 'Missing required payload "title"' });
|
if (!_request.body.title) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required payload "title"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
const data = await client.updateList(_request.params.id, _request.body.title);
|
const data = await client.updateList(_request.params.id, _request.body.title);
|
||||||
|
@ -139,7 +139,7 @@ export class ApiTimelineMastodon {
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.delete<{ Params: { id?: string } }>('/v1/lists/:id', async (_request, reply) => {
|
fastify.delete<{ Params: { id?: string } }>('/v1/lists/:id', async (_request, reply) => {
|
||||||
if (!_request.params.id) return reply.code(400).send({ error: 'Missing required parameter "id"' });
|
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
|
||||||
|
|
||||||
const client = this.clientService.getClient(_request);
|
const client = this.clientService.getClient(_request);
|
||||||
await client.deleteList(_request.params.id);
|
await client.deleteList(_request.params.id);
|
||||||
|
|
|
@ -128,7 +128,7 @@ export class OAuth2ProviderService {
|
||||||
|
|
||||||
for (const url of ['/authorize', '/authorize/']) {
|
for (const url of ['/authorize', '/authorize/']) {
|
||||||
fastify.get<{ Querystring: Record<string, string | string[] | undefined> }>(url, async (request, reply) => {
|
fastify.get<{ Querystring: Record<string, string | string[] | undefined> }>(url, async (request, reply) => {
|
||||||
if (typeof(request.query.client_id) !== 'string') return reply.code(400).send({ error: 'Missing required query "client_id"' });
|
if (typeof(request.query.client_id) !== 'string') return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required query "client_id"' });
|
||||||
|
|
||||||
const redirectUri = new URL(Buffer.from(request.query.client_id, 'base64').toString());
|
const redirectUri = new URL(Buffer.from(request.query.client_id, 'base64').toString());
|
||||||
redirectUri.searchParams.set('mastodon', 'true');
|
redirectUri.searchParams.set('mastodon', 'true');
|
||||||
|
@ -153,7 +153,7 @@ export class OAuth2ProviderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!body.client_secret) return reply.code(400).send({ error: 'Missing required query "client_secret"' });
|
if (!body.client_secret) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required query "client_secret"' });
|
||||||
|
|
||||||
const clientId = body.client_id ? String(body.clientId) : null;
|
const clientId = body.client_id ? String(body.clientId) : null;
|
||||||
const secret = String(body.client_secret);
|
const secret = String(body.client_secret);
|
||||||
|
|
Loading…
Add table
Reference in a new issue