diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index b800df04d5..88ec3d2c82 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -222,75 +222,75 @@ export default class Misskey implements MegalodonInterface { fields_attributes?: Array<{ name: string; value: string }> }, file?: any): Promise> { let params = {} - if (!file) { - if (options) { - if (options.bot !== undefined) { + if (options) { + if (options.bot !== undefined) { + params = Object.assign(params, { + isBot: options.bot + }) + } + if (options.display_name) { + params = Object.assign(params, { + name: options.display_name + }) + } + 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); + 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); + params = Object.assign(params, { + headerId: media.data.id + }) + } + if (options.note) { + params = Object.assign(params, { + description: options.note + }) + } + if (options.locked !== undefined) { + params = Object.assign(params, { + isLocked: options.locked + }) + } + if (options.source) { + if (options.source.language) { params = Object.assign(params, { - isBot: options.bot + lang: options.source.language }) } - if (options.display_name) { + if (options.source.sensitive) { params = Object.assign(params, { - name: options.display_name + alwaysMarkNsfw: options.source.sensitive }) } - if (options.note) { - params = Object.assign(params, { - description: options.note - }) - } - if (options.locked !== undefined) { - params = Object.assign(params, { - isLocked: options.locked - }) - } - if (options.source) { - if (options.source.language) { - params = Object.assign(params, { - lang: options.source.language - }) - } - if (options.source.sensitive) { - params = Object.assign(params, { - alwaysMarkNsfw: options.source.sensitive - }) - } - } } - return this.client.post('/api/i/update', params).then(res => { - return Object.assign(res, { - data: MisskeyAPI.Converter.userDetail(res.data) - }) - }) - } else { - 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() - } - await this.client - .post('/api/drive/files/create', formData, headers) - .then(res => { - if (file.name === "header") { - params = Object.assign(params, { - bannerId: res.data.id - }) - } else if (file.name === "avatar") { - params = Object.assign(params, { - avatarId: res.data.id - }) - } - }) - return this.client.post('/api/i/update', params).then(res => { - return Object.assign(res, { - data: MisskeyAPI.Converter.userDetail(res.data) - }) - }) } + return this.client.post('/api/i/update', params).then(res => { + return Object.assign(res, { + data: MisskeyAPI.Converter.userDetail(res.data) + }) + }) } /**