upd: change handling of file on update
This commit is contained in:
parent
0fe5e8738c
commit
6a52509821
1 changed files with 61 additions and 61 deletions
|
@ -222,7 +222,6 @@ export default class Misskey implements MegalodonInterface {
|
||||||
fields_attributes?: Array<{ name: string; value: string }>
|
fields_attributes?: Array<{ name: string; value: string }>
|
||||||
}, file?: any): Promise<Response<Entity.Account>> {
|
}, file?: any): Promise<Response<Entity.Account>> {
|
||||||
let params = {}
|
let params = {}
|
||||||
if (!file) {
|
|
||||||
if (options) {
|
if (options) {
|
||||||
if (options.bot !== undefined) {
|
if (options.bot !== undefined) {
|
||||||
params = Object.assign(params, {
|
params = Object.assign(params, {
|
||||||
|
@ -234,6 +233,36 @@ export default class Misskey implements MegalodonInterface {
|
||||||
name: options.display_name
|
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) {
|
if (options.note) {
|
||||||
params = Object.assign(params, {
|
params = Object.assign(params, {
|
||||||
description: options.note
|
description: options.note
|
||||||
|
@ -262,35 +291,6 @@ export default class Misskey implements MegalodonInterface {
|
||||||
data: MisskeyAPI.Converter.userDetail(res.data)
|
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)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue