diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index 29cfbf93c0..9e8c458868 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -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); diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index c3bbfb746f..97b17a0d61 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -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> { + public async uploadMedia(file: any, options?: { description?: string; focus?: string }): Promise> { 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('/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> { const res = await this.client.post('/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('/api/drive/files/update', params)