From 7c64dce1aded29169fc76d0183e2afbed992c153 Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Mon, 25 Sep 2023 22:22:29 +0200 Subject: [PATCH] upd: use uploadMedia function --- packages/megalodon/src/misskey.ts | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index 88ec3d2c82..69884bf60d 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -234,31 +234,13 @@ export default class Misskey implements MegalodonInterface { }) } if (options.avatar) { - 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() - } - const media = await this.client.post('/api/drive/files/create', formData, headers); + const media = await this.uploadMedia(file); params = Object.assign(params, { avatarId: media.data.id }) } if (options.header) { - 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() - } - const media = await this.client.post('/api/drive/files/create', formData, headers); + const media = await this.uploadMedia(file); params = Object.assign(params, { headerId: media.data.id })