upd: add multipart support to oauth/token

This commit is contained in:
Mar0xy 2023-11-16 20:04:19 +01:00
parent 6ca27b48cf
commit 2fae63fe15
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828

View file

@ -10,6 +10,7 @@ import { v4 as uuid } from 'uuid';
/* import { kinds } from '@/misc/api-permissions.js';
import type { Config } from '@/config.js';
import { DI } from '@/di-symbols.js'; */
import multer from 'fastify-multer';
import { bindThis } from '@/decorators.js';
import type { FastifyInstance } from 'fastify';
@ -24,8 +25,8 @@ function getClient(BASE_URL: string, authorization: string | undefined): Megalod
@Injectable()
export class OAuth2ProviderService {
constructor(
/* @Inject(DI.config)
private config: Config, */
@Inject(DI.config)
private config: Config,
) { }
@bindThis
@ -46,6 +47,14 @@ export class OAuth2ProviderService {
});
}); */
const upload = multer({
storage: multer.diskStorage({}),
limits: {
fileSize: this.config.maxFileSize || 262144000,
files: 1,
},
});
fastify.addHook('onRequest', (request, reply, done) => {
reply.header('Access-Control-Allow-Origin', '*');
done();
@ -89,7 +98,7 @@ export class OAuth2ProviderService {
);
});
fastify.post('/oauth/token', async (request, reply) => {
fastify.post('/oauth/token', { preHandler: upload.none() }, async (request, reply) => {
const body: any = request.body || request.query;
if (body.grant_type === "client_credentials") {
const ret = {