[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; ctx.status = 401;
return; return;
} }
const data = await client.uploadMedia(multipartData); const data = await client.uploadMedia(multipartData, ctx.request.body);
ctx.body = convertAttachment(data.data as Entity.Attachment); ctx.body = convertAttachment(data.data as Entity.Attachment);
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);

View File

@ -1643,12 +1643,21 @@ export default class Misskey implements MegalodonInterface {
/** /**
* POST /api/drive/files/create * 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() const formData = new FormData()
formData.append('file', fs.createReadStream(file.path), { formData.append('file', fs.createReadStream(file.path), {
contentType: file.mimetype, contentType: file.mimetype,
filename: file.originalname, 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 } = {} let headers: { [key: string]: string } = {}
if (typeof formData.getHeaders === 'function') { if (typeof formData.getHeaders === 'function') {
headers = formData.getHeaders() headers = formData.getHeaders()
@ -1684,6 +1693,12 @@ export default class Misskey implements MegalodonInterface {
isSensitive: options.is_sensitive isSensitive: options.is_sensitive
}) })
} }
if (options.description !== undefined) {
params = Object.assign(params, {
comment: options.description
})
}
} }
return this.client return this.client
.post<MisskeyAPI.Entity.File>('/api/drive/files/update', params) .post<MisskeyAPI.Entity.File>('/api/drive/files/update', params)