upd: allow updating of fields
This commit is contained in:
parent
c88fbe843a
commit
81def9457b
@ -14,7 +14,6 @@ import { ApiAuthMastodon, ApiAccountMastodon, ApiFilterMastodon, ApiNotifyMastod
|
||||
import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { DriveService } from '@/core/DriveService.js';
|
||||
import { toSingleLast } from '@/misc/prelude/array.js';
|
||||
|
||||
export function getClient(BASE_URL: string, authorization: string | undefined): MegalodonInterface {
|
||||
const accessTokenArr = authorization?.split(' ') ?? [null];
|
||||
@ -256,6 +255,7 @@ export class MastodonApiServerService {
|
||||
const client = getClient(BASE_URL, accessTokens); // we are using this here, because in private mode some info isnt
|
||||
// displayed without being logged in
|
||||
try {
|
||||
// Check if there is an Header or Avatar being uploaded, if there is proceed to upload it to the drive of the user and then set it.
|
||||
if (_request.files.length > 0 && accessTokens) {
|
||||
const tokeninfo = await this.accessTokensRepository.findOneBy({ token: accessTokens.replace('Bearer ', '') });
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@ -291,6 +291,20 @@ export class MastodonApiServerService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((_request.body as any).fields_attributes) {
|
||||
const fields = (_request.body as any).fields_attributes.map((field: any) => {
|
||||
if (!(field.name.trim() === '' && field.value.trim() === '')) {
|
||||
if (field.name.trim() === '') return reply.code(400).send('Field name can not be empty');
|
||||
if (field.value.trim() === '') return reply.code(400).send('Field value can not be empty');
|
||||
}
|
||||
return {
|
||||
...field,
|
||||
};
|
||||
});
|
||||
(_request.body as any).fields_attributes = fields.filter((field: any) => field.name.trim().length > 0 && field.value.length > 0);
|
||||
}
|
||||
|
||||
const data = await client.updateCredentials(_request.body!);
|
||||
reply.send(await this.mastoConverter.convertAccount(data.data));
|
||||
} catch (e: any) {
|
||||
|
@ -39,22 +39,18 @@ export class ApiAccountMastodon {
|
||||
public async verifyCredentials() {
|
||||
try {
|
||||
const data = await this.client.verifyAccountCredentials();
|
||||
const acct = data.data;
|
||||
acct.display_name = acct.display_name || acct.username;
|
||||
acct.url = `${this.BASE_URL}/@${acct.url}`;
|
||||
acct.note = acct.note || '';
|
||||
acct.avatar_static = acct.avatar;
|
||||
acct.header = acct.header || '/static-assets/transparent.png';
|
||||
acct.header_static = acct.header || '/static-assets/transparent.png';
|
||||
acct.source = {
|
||||
const acct = await this.mastoconverter.convertAccount(data.data);
|
||||
const newAcct = Object.assign({}, acct, {
|
||||
source: {
|
||||
note: acct.note,
|
||||
fields: acct.fields,
|
||||
privacy: '',
|
||||
sensitive: false,
|
||||
language: '',
|
||||
};
|
||||
console.log(acct);
|
||||
return acct;
|
||||
},
|
||||
});
|
||||
console.log(newAcct);
|
||||
return newAcct;
|
||||
} catch (e: any) {
|
||||
/* console.error(e);
|
||||
console.error(e.response.data); */
|
||||
|
@ -248,6 +248,11 @@ export default class Misskey implements MegalodonInterface {
|
||||
bannerId: options.header
|
||||
})
|
||||
}
|
||||
if (options.fields_attributes) {
|
||||
params = Object.assign(params, {
|
||||
fields: options.fields_attributes
|
||||
})
|
||||
}
|
||||
if (options.locked !== undefined) {
|
||||
params = Object.assign(params, {
|
||||
isLocked: options.locked.toString() === 'true' ? true : false
|
||||
|
Loading…
Reference in New Issue
Block a user