diff --git a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts index bdf3af0588..55e4615b91 100644 --- a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts +++ b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts @@ -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) { diff --git a/packages/backend/src/server/api/mastodon/endpoints/account.ts b/packages/backend/src/server/api/mastodon/endpoints/account.ts index 39da0e4a53..694879764b 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/account.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/account.ts @@ -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 = { - note: acct.note, - fields: acct.fields, - privacy: '', - sensitive: false, - language: '', - }; - console.log(acct); - return acct; + 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(newAcct); + return newAcct; } catch (e: any) { /* console.error(e); console.error(e.response.data); */ diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index b81fb77a6b..a0b222c230 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -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