mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-23 13:23:09 +02:00
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,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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue