implement '/v1/apps/verify_credentials'

This commit is contained in:
Hazelnoot 2025-05-06 23:19:23 -04:00
parent 5ec9be0b8c
commit b2ea03383c
14 changed files with 183 additions and 9 deletions

View file

@ -4,7 +4,7 @@
*/
import { Inject, Injectable } from '@nestjs/common';
import { Entity, MastodonEntity } from 'megalodon';
import { Entity, MastodonEntity, MisskeyEntity } from 'megalodon';
import mfm from '@transfem-org/sfm-js';
import { MastodonNotificationType } from 'megalodon/lib/src/mastodon/notification.js';
import { NotificationType } from 'megalodon/lib/src/notification.js';
@ -369,6 +369,15 @@ export class MastodonConverters {
type: convertNotificationType(notification.type as NotificationType),
};
}
public convertApplication(app: MisskeyEntity.App): MastodonEntity.Application {
return {
name: app.name,
scopes: app.permission,
redirect_uri: app.callbackUrl,
redirect_uris: [app.callbackUrl],
};
}
}
function simpleConvert<T>(data: T): T {
@ -459,4 +468,3 @@ export function convertRelationship(relationship: Partial<Entity.Relationship> &
note: relationship.note ?? '',
};
}

View file

@ -5,6 +5,7 @@
import { Injectable } from '@nestjs/common';
import { MastodonClientService } from '@/server/api/mastodon/MastodonClientService.js';
import { MastodonConverters } from '@/server/api/mastodon/MastodonConverters.js';
import type { FastifyInstance } from 'fastify';
const readScope = [
@ -59,6 +60,7 @@ type AuthMastodonRoute = { Body?: AuthPayload, Querystring: AuthPayload };
export class ApiAppsMastodon {
constructor(
private readonly clientService: MastodonClientService,
private readonly mastoConverters: MastodonConverters,
) {}
public register(fastify: FastifyInstance): void {
@ -108,6 +110,13 @@ export class ApiAppsMastodon {
return reply.send(response);
});
fastify.get('/v1/apps/verify_credentials', async (_request, reply) => {
const client = this.clientService.getClient(_request);
const data = await client.verifyAppCredentials();
const response = this.mastoConverters.convertApplication(data.data);
return reply.send(response);
});
}
}