[mastodon-client] media caption support

This commit is contained in:
Laura Hausmann 2023-07-08 23:35:27 +02:00
parent 2446822680
commit 12d7246bf3
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 23 additions and 8 deletions

View File

@ -112,7 +112,7 @@ mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => {
ctx.status = 401;
return;
}
const data = await client.uploadMedia(multipartData);
const data = await client.uploadMedia(multipartData, ctx.request.body);
ctx.body = convertAttachment(data.data as Entity.Attachment);
} catch (e: any) {
console.error(e);

View File

@ -1643,20 +1643,29 @@ export default class Misskey implements MegalodonInterface {
/**
* POST /api/drive/files/create
*/
public async uploadMedia(file: any, _options?: { description?: string; focus?: string }): Promise<Response<Entity.Attachment>> {
public async uploadMedia(file: any, options?: { description?: string; focus?: string }): Promise<Response<Entity.Attachment>> {
const formData = new FormData()
formData.append('file', fs.createReadStream(file.path), {
contentType: file.mimetype,
filename: file.originalname,
})
formData.append('file', fs.createReadStream(file.path), {
contentType: file.mimetype,
filename: file.originalname
})
if (file.originalname != null) {
formData.append('name', file.originalname);
}
if (options?.description != null) {
formData.append('comment', options.description);
}
let headers: { [key: string]: string } = {}
if (typeof formData.getHeaders === 'function') {
headers = formData.getHeaders()
}
return this.client
.post<MisskeyAPI.Entity.File>('/api/drive/files/create', formData, headers)
.then(res => ({ ...res, data: this.converter.file(res.data) }))
}
.then(res => ({ ...res, data: this.converter.file(res.data) }))
}
public async getMedia(id: string): Promise<Response<Entity.Attachment>> {
const res = await this.client.post<MisskeyAPI.Entity.File>('/api/drive/files/show', { fileId: id })
@ -1684,6 +1693,12 @@ export default class Misskey implements MegalodonInterface {
isSensitive: options.is_sensitive
})
}
if (options.description !== undefined) {
params = Object.assign(params, {
comment: options.description
})
}
}
return this.client
.post<MisskeyAPI.Entity.File>('/api/drive/files/update', params)