Merge branch 'fields' into 'main'

Instruct Soapbox to use up to 10 custom profile fields

See merge request soapbox-pub/ditto!592
This commit is contained in:
Alex Gleason 2024-11-20 17:01:26 +00:00
commit c25fd366a9
3 changed files with 29 additions and 1 deletions

View file

@ -350,6 +350,17 @@ class Conf {
};
},
};
static profileFields = {
get maxFields(): number {
return Number(Deno.env.get('PROFILE_FIELDS_MAX_FIELDS') || 10);
},
get nameLength(): number {
return Number(Deno.env.get('PROFILE_FIELDS_NAME_LENGTH') || 255);
},
get valueLength(): number {
return Number(Deno.env.get('PROFILE_FIELDS_VALUE_LENGTH') || 2047);
},
};
}
const optionalBooleanSchema = z

View file

@ -49,6 +49,11 @@ const instanceV1Controller: AppController = async (c) => {
pleroma: {
metadata: {
features,
fields_limits: {
max_fields: Conf.profileFields.maxFields,
name_length: Conf.profileFields.nameLength,
value_length: Conf.profileFields.valueLength,
},
},
},
languages: ['en'],
@ -141,6 +146,11 @@ const instanceV2Controller: AppController = async (c) => {
pleroma: {
metadata: {
features,
fields_limits: {
max_fields: Conf.profileFields.maxFields,
name_length: Conf.profileFields.nameLength,
value_length: Conf.profileFields.valueLength,
},
},
},
registrations: {

View file

@ -60,7 +60,14 @@ async function renderAccount(
}
}
const { html } = parseNoteContent(about || '', []);
const fields = _fields?.map(([name, value]) => ({ name, value, verified_at: null })) ?? [];
const fields = _fields
?.slice(0, Conf.profileFields.maxFields)
.map(([name, value]) => ({
name: name.slice(0, Conf.profileFields.nameLength),
value: value.slice(0, Conf.profileFields.valueLength),
verified_at: null,
})) ?? [];
return {
id: pubkey,