Let field limits be configurable

This commit is contained in:
Alex Gleason 2024-11-20 10:58:21 -06:00
parent 39cb1ec0c9
commit 81780bec72
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 25 additions and 3 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

@ -50,7 +50,9 @@ const instanceV1Controller: AppController = async (c) => {
metadata: {
features,
fields_limits: {
max_fields: 10,
max_fields: Conf.profileFields.maxFields,
name_length: Conf.profileFields.nameLength,
value_length: Conf.profileFields.valueLength,
},
},
},
@ -145,7 +147,9 @@ const instanceV2Controller: AppController = async (c) => {
metadata: {
features,
fields_limits: {
max_fields: 10,
max_fields: Conf.profileFields.maxFields,
name_length: Conf.profileFields.nameLength,
value_length: Conf.profileFields.valueLength,
},
},
},

View file

@ -60,7 +60,14 @@ async function renderAccount(
}
}
const { html } = parseNoteContent(about || '', []);
const fields = _fields?.slice(0, 10).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,