upd: change resolving of _request.files

This commit is contained in:
Mar0xy 2023-10-30 00:57:12 +01:00
parent be7d3859c3
commit d942d4d0d0
No known key found for this signature in database
GPG Key ID: 56569BBE47D2C828
1 changed files with 13 additions and 9 deletions

View File

@ -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);
@ -274,11 +279,10 @@ export class MastodonApiServerService {
}
}
if (tokeninfo && (_request.files as any)['header']) {
const file = toSingleLast((_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/')) {