upd: use uploadMedia function

This commit is contained in:
Mar0xy 2023-09-25 22:22:29 +02:00
parent 6a52509821
commit 7c64dce1ad
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828

View file

@ -234,31 +234,13 @@ export default class Misskey implements MegalodonInterface {
}) })
} }
if (options.avatar) { if (options.avatar) {
const formData = new FormData() const media = await this.uploadMedia(file);
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<MisskeyAPI.Entity.File>('/api/drive/files/create', formData, headers);
params = Object.assign(params, { params = Object.assign(params, {
avatarId: media.data.id avatarId: media.data.id
}) })
} }
if (options.header) { if (options.header) {
const formData = new FormData() const media = await this.uploadMedia(file);
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<MisskeyAPI.Entity.File>('/api/drive/files/create', formData, headers);
params = Object.assign(params, { params = Object.assign(params, {
headerId: media.data.id headerId: media.data.id
}) })