forked from woem.men/forkey
Compare commits
3 commits
bd88c5261e
...
61db718bae
Author | SHA1 | Date | |
---|---|---|---|
61db718bae | |||
9443b99399 | |||
04c1c0e1e6 |
6 changed files with 48 additions and 28 deletions
|
@ -2243,6 +2243,7 @@ _permissions:
|
|||
"read:clip-favorite": "View favorited clips"
|
||||
"read:federation": "Get federation data"
|
||||
"write:report-abuse": "Report violation"
|
||||
"write:push-notification": "Receive push notifications"
|
||||
_auth:
|
||||
shareAccessTitle: "Granting application permissions"
|
||||
shareAccess: "Would you like to authorize \"{name}\" to access this account?"
|
||||
|
|
|
@ -72,7 +72,7 @@ export function build() {
|
|||
.reduce((a, [k, v]) => (a[k] = (() => {
|
||||
const [lang] = k.split('-');
|
||||
switch (k) {
|
||||
case 'ja-JP': return v;
|
||||
case 'ja-JP': return merge(locales['en-US'], v);
|
||||
case 'ja-KS':
|
||||
case 'en-US': return merge(locales['ja-JP'], v);
|
||||
default: return merge(
|
||||
|
|
|
@ -3,6 +3,7 @@ import { permissions } from 'misskey-js';
|
|||
const mastodonToMisskeyScopes: Map<string, (typeof permissions)[number][]> = new Map([
|
||||
['profile', ['read:account']],
|
||||
['follow', ['read:following', 'write:following', 'read:blocks', 'write:blocks', 'read:mutes', 'write:mutes']],
|
||||
['push', ['write:push-notification']],
|
||||
['read:accounts', ['read:account']],
|
||||
['read:blocks', ['read:blocks']],
|
||||
['read:bookmarks', ['read:favorites']],
|
||||
|
|
|
@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||
import cors from '@fastify/cors';
|
||||
import multipart from '@fastify/multipart';
|
||||
import fastifyCookie from '@fastify/cookie';
|
||||
import fastifyFormbody from '@fastify/formbody';
|
||||
import { ModuleRef } from '@nestjs/core';
|
||||
import type { Config } from '@/config.js';
|
||||
import type { InstancesRepository, AccessTokensRepository } from '@/models/_.js';
|
||||
|
@ -63,6 +64,13 @@ export class ApiServerService {
|
|||
done();
|
||||
});
|
||||
|
||||
fastify.register(this.createMisskeyServer);
|
||||
fastify.register(this.createMastodonServer);
|
||||
done();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createMisskeyServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
|
||||
for (const endpoint of endpoints) {
|
||||
const ep = {
|
||||
name: endpoint.name,
|
||||
|
@ -106,32 +114,6 @@ export class ApiServerService {
|
|||
}
|
||||
}
|
||||
|
||||
const createEndpoint = (endpoint: IMastodonEndpoint): IMastodonEndpoint & { exec: any } => ({
|
||||
name: endpoint.name,
|
||||
method: endpoint.method,
|
||||
meta: endpoint.meta,
|
||||
params: endpoint.params,
|
||||
exec: this.moduleRef.get(`mep:${endpoint.method}:${endpoint.name}`, { strict: false }).exec,
|
||||
});
|
||||
const groupedMastodonEndpoints = Array.from(Map.groupBy(mastodonEndpoints.map(createEndpoint), endpoint => endpoint.name))
|
||||
.map(([name, endpoints]) => ({ name, endpoints: new Map(endpoints.map(endpoint => [endpoint.method, endpoint])) }));
|
||||
for (const { name, endpoints } of groupedMastodonEndpoints) {
|
||||
fastify.all<{
|
||||
Params: { endpoint: string; },
|
||||
Body: Record<string, unknown>,
|
||||
Querystring: Record<string, unknown>,
|
||||
}>('/' + name, async (request, reply) => {
|
||||
const ep = endpoints.get(request.method);
|
||||
if (!ep) {
|
||||
reply.code(405);
|
||||
reply.send();
|
||||
return;
|
||||
}
|
||||
await this.apiCallService.handleMastodonRequest(ep, request, reply);
|
||||
return reply;
|
||||
});
|
||||
}
|
||||
|
||||
fastify.post<{
|
||||
Body: {
|
||||
username: string;
|
||||
|
@ -212,4 +194,39 @@ export class ApiServerService {
|
|||
|
||||
done();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createMastodonServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
|
||||
fastify.register(fastifyFormbody);
|
||||
|
||||
const createEndpoint = (endpoint: IMastodonEndpoint): IMastodonEndpoint & { exec: any } => ({
|
||||
name: endpoint.name,
|
||||
method: endpoint.method,
|
||||
meta: endpoint.meta,
|
||||
params: endpoint.params,
|
||||
exec: this.moduleRef.get(`mep:${endpoint.method}:${endpoint.name}`, { strict: false }).exec,
|
||||
});
|
||||
|
||||
const groupedMastodonEndpoints = Array.from(Map.groupBy(mastodonEndpoints.map(createEndpoint), endpoint => endpoint.name))
|
||||
.map(([name, endpoints]) => ({ name, endpoints: new Map(endpoints.map(endpoint => [endpoint.method, endpoint])) }));
|
||||
|
||||
for (const { name, endpoints } of groupedMastodonEndpoints) {
|
||||
fastify.all<{
|
||||
Params: { endpoint: string; },
|
||||
Body: Record<string, unknown>,
|
||||
Querystring: Record<string, unknown>,
|
||||
}>('/' + name, async (request, reply) => {
|
||||
const ep = endpoints.get(request.method);
|
||||
if (!ep) {
|
||||
reply.code(405);
|
||||
reply.send();
|
||||
return;
|
||||
}
|
||||
await this.apiCallService.handleMastodonRequest(ep, request, reply);
|
||||
return reply;
|
||||
});
|
||||
}
|
||||
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ export default class extends MastodonEndpoint<typeof meta, typeof paramDef> { //
|
|||
id: clientId,
|
||||
userId: me ? me.id : null,
|
||||
name: ps.client_name,
|
||||
description: ps.website,
|
||||
description: ps.website ?? '',
|
||||
permission: scopes,
|
||||
callbackUrl: null,
|
||||
secret: secret,
|
||||
|
|
|
@ -103,6 +103,7 @@ export const permissions = [
|
|||
'read:clip-favorite',
|
||||
'read:federation',
|
||||
'write:report-abuse',
|
||||
'write:push-notification', // Mastodon permission
|
||||
] as const;
|
||||
|
||||
export const moderationLogTypes = [
|
||||
|
|
Loading…
Reference in a new issue