mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-05 12:43:09 +02:00
upd: change resolving of _request.files
This commit is contained in:
parent
be7d3859c3
commit
d942d4d0d0
1 changed files with 13 additions and 9 deletions
|
@ -258,14 +258,19 @@ export class MastodonApiServerService {
|
||||||
try {
|
try {
|
||||||
if (_request.files.length > 0 && accessTokens) {
|
if (_request.files.length > 0 && accessTokens) {
|
||||||
const tokeninfo = await this.accessTokensRepository.findOneBy({ token: accessTokens.replace('Bearer ', '') });
|
const tokeninfo = await this.accessTokensRepository.findOneBy({ token: accessTokens.replace('Bearer ', '') });
|
||||||
console.error(_request.files);
|
const avatar = (_request.files as any).find((obj: any) => {
|
||||||
if (tokeninfo && (_request.files as any)['avatar']) {
|
return obj.fieldname === 'avatar';
|
||||||
|
});
|
||||||
|
const header = (_request.files as any).find((obj: any) => {
|
||||||
|
return obj.fieldname === 'header';
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tokeninfo && avatar) {
|
||||||
console.error('avatar');
|
console.error('avatar');
|
||||||
const file = toSingleLast((_request.files as any)['avatar']);
|
|
||||||
const upload = await this.driveService.addFile({
|
const upload = await this.driveService.addFile({
|
||||||
user: { id: tokeninfo.userId, host: null },
|
user: { id: tokeninfo.userId, host: null },
|
||||||
path: file.path,
|
path: avatar.path,
|
||||||
name: file.originalname !== null && file.originalname !== 'file' ? file.originalname : undefined,
|
name: avatar.originalname !== null && avatar.originalname !== 'file' ? avatar.originalname : undefined,
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
});
|
});
|
||||||
console.error(upload);
|
console.error(upload);
|
||||||
|
@ -274,11 +279,10 @@ export class MastodonApiServerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tokeninfo && (_request.files as any)['header']) {
|
if (tokeninfo && (_request.files as any)['header']) {
|
||||||
const file = toSingleLast((_request.files as any)['header']);
|
|
||||||
const upload = await this.driveService.addFile({
|
const upload = await this.driveService.addFile({
|
||||||
user: { id: tokeninfo.userId, host: null },
|
user: { id: tokeninfo.userId, host: null },
|
||||||
path: file.path,
|
path: header.path,
|
||||||
name: file.originalname !== null && file.originalname !== 'file' ? file.originalname : undefined,
|
name: header.originalname !== null && header.originalname !== 'file' ? header.originalname : undefined,
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
});
|
});
|
||||||
if (upload.type.startsWith('image/')) {
|
if (upload.type.startsWith('image/')) {
|
||||||
|
|
Loading…
Reference in a new issue