[mastodon-client] media caption support
This commit is contained in:
parent
2446822680
commit
12d7246bf3
2 changed files with 23 additions and 8 deletions
|
@ -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);
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue