mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 05:55:14 +00:00
upd: attempt to accept file during update
This commit is contained in:
parent
8b55fc7917
commit
0fe5e8738c
3 changed files with 72 additions and 36 deletions
|
@ -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 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);
|
||||
|
|
|
@ -149,7 +149,7 @@ export interface MegalodonInterface {
|
|||
language?: string
|
||||
}
|
||||
fields_attributes?: Array<{ name: string; value: string }>
|
||||
}): Promise<Response<Entity.Account>>
|
||||
}, file?: any): Promise<Response<Entity.Account>>
|
||||
/**
|
||||
* View information about a profile.
|
||||
*
|
||||
|
|
|
@ -220,8 +220,9 @@ export default class Misskey implements MegalodonInterface {
|
|||
language?: string
|
||||
} | null
|
||||
fields_attributes?: Array<{ name: string; value: string }>
|
||||
}): Promise<Response<Entity.Account>> {
|
||||
}, file?: any): Promise<Response<Entity.Account>> {
|
||||
let params = {}
|
||||
if (!file) {
|
||||
if (options) {
|
||||
if (options.bot !== undefined) {
|
||||
params = Object.assign(params, {
|
||||
|
@ -261,6 +262,35 @@ export default class Misskey implements MegalodonInterface {
|
|||
data: MisskeyAPI.Converter.userDetail(res.data)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
const formData = new FormData()
|
||||
formData.append('file', fs.createReadStream(file.path), {
|
||||
contentType: file.mimetype,
|
||||
});
|
||||
if (file.originalname != null && file.originalname !== "file") formData.append("name", file.originalname);
|
||||
let headers: { [key: string]: string } = {}
|
||||
if (typeof formData.getHeaders === 'function') {
|
||||
headers = formData.getHeaders()
|
||||
}
|
||||
await this.client
|
||||
.post<MisskeyAPI.Entity.File>('/api/drive/files/create', formData, headers)
|
||||
.then(res => {
|
||||
if (file.name === "header") {
|
||||
params = Object.assign(params, {
|
||||
bannerId: res.data.id
|
||||
})
|
||||
} else if (file.name === "avatar") {
|
||||
params = Object.assign(params, {
|
||||
avatarId: res.data.id
|
||||
})
|
||||
}
|
||||
})
|
||||
return this.client.post<MisskeyAPI.Entity.UserDetail>('/api/i/update', params).then(res => {
|
||||
return Object.assign(res, {
|
||||
data: MisskeyAPI.Converter.userDetail(res.data)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue