From d942d4d0d01505b1a532b502181704f6310226fb Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Mon, 30 Oct 2023 00:57:12 +0100 Subject: [PATCH] upd: change resolving of _request.files --- .../api/mastodon/MastodonApiServerService.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts index ac66d8d49..cc61a234d 100644 --- a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts +++ b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts @@ -258,14 +258,19 @@ export class MastodonApiServerService { try { if (_request.files.length > 0 && accessTokens) { const tokeninfo = await this.accessTokensRepository.findOneBy({ token: accessTokens.replace('Bearer ', '') }); - console.error(_request.files); - if (tokeninfo && (_request.files as any)['avatar']) { + const avatar = (_request.files as any).find((obj: any) => { + return obj.fieldname === 'avatar'; + }); + const header = (_request.files as any).find((obj: any) => { + return obj.fieldname === 'header'; + }); + + if (tokeninfo && avatar) { console.error('avatar'); - const file = toSingleLast((_request.files as any)['avatar']); const upload = await this.driveService.addFile({ user: { id: tokeninfo.userId, host: null }, - path: file.path, - name: file.originalname !== null && file.originalname !== 'file' ? file.originalname : undefined, + path: avatar.path, + name: avatar.originalname !== null && avatar.originalname !== 'file' ? avatar.originalname : undefined, sensitive: false, }); console.error(upload); @@ -273,12 +278,11 @@ export class MastodonApiServerService { (_request.body as any).avatar = upload.id; } } - if (tokeninfo && (_request.files as any)['header']) { - const file = toSingleLast((_request.files as any)['header']); + if (tokeninfo && (_request.files as any)['header']) { const upload = await this.driveService.addFile({ user: { id: tokeninfo.userId, host: null }, - path: file.path, - name: file.originalname !== null && file.originalname !== 'file' ? file.originalname : undefined, + path: header.path, + name: header.originalname !== null && header.originalname !== 'file' ? header.originalname : undefined, sensitive: false, }); if (upload.type.startsWith('image/')) {