upd: attempt to accept file during update

This commit is contained in:
Mar0xy 2023-09-25 22:02:33 +02:00
parent 8b55fc7917
commit 0fe5e8738c
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
3 changed files with 72 additions and 36 deletions

View file

@ -236,14 +236,20 @@ export class MastodonApiServerService {
}
});
fastify.patch('/v1/accounts/update_credentials', { preHandler: upload.none() }, async (_request, reply) => {
fastify.patch('/v1/accounts/update_credentials', { preHandler: upload.single('file') }, async (_request, reply) => {
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
const accessTokens = _request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); // we are using this here, because in private mode some info isnt
// displayed without being logged in
try {
const data = await client.updateCredentials(_request.body!);
reply.send(convertAccount(data.data));
const multipartData = await _request.file;
if (!multipartData) {
const data = await client.updateCredentials(_request.body!);
reply.send(convertAccount(data.data));
} else {
const data = await client.updateCredentials(_request.body!, multipartData);
reply.send(convertAccount(data.data));
}
} catch (e: any) {
/* console.error(e); */
reply.code(401).send(e.response.data);