upd: change handling of file on update

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

View file

@ -222,75 +222,75 @@ export default class Misskey implements MegalodonInterface {
fields_attributes?: Array<{ name: string; value: string }>
}, file?: any): Promise<Response<Entity.Account>> {
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<MisskeyAPI.Entity.File>('/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<MisskeyAPI.Entity.File>('/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<MisskeyAPI.Entity.UserDetail>('/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<MisskeyAPI.Entity.File>('/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<MisskeyAPI.Entity.UserDetail>('/api/i/update', params).then(res => {
return Object.assign(res, {
data: MisskeyAPI.Converter.userDetail(res.data)
})
})
}
return this.client.post<MisskeyAPI.Entity.UserDetail>('/api/i/update', params).then(res => {
return Object.assign(res, {
data: MisskeyAPI.Converter.userDetail(res.data)
})
})
}
/**