instanceSchema: support legacy Pleroma configuration
This commit is contained in:
parent
0986055222
commit
814b220da0
|
@ -25,14 +25,14 @@ const configurationSchema = coerceObject({
|
||||||
video_size_limit: z.number().optional().catch(undefined),
|
video_size_limit: z.number().optional().catch(undefined),
|
||||||
}),
|
}),
|
||||||
polls: coerceObject({
|
polls: coerceObject({
|
||||||
max_characters_per_option: z.number().catch(25),
|
max_characters_per_option: z.number().optional().catch(undefined),
|
||||||
max_expiration: z.number().catch(2629746),
|
max_expiration: z.number().optional().catch(undefined),
|
||||||
max_options: z.number().catch(4),
|
max_options: z.number().optional().catch(undefined),
|
||||||
min_expiration: z.number().catch(300),
|
min_expiration: z.number().optional().catch(undefined),
|
||||||
}),
|
}),
|
||||||
statuses: coerceObject({
|
statuses: coerceObject({
|
||||||
max_characters: z.number().optional().catch(undefined),
|
max_characters: z.number().optional().catch(undefined),
|
||||||
max_media_attachments: z.number().catch(4),
|
max_media_attachments: z.number().optional().catch(undefined),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -86,6 +86,13 @@ const pleromaSchema = coerceObject({
|
||||||
vapid_public_key: z.string().catch(''),
|
vapid_public_key: z.string().catch(''),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const pleromaPollLimitsSchema = coerceObject({
|
||||||
|
max_expiration: z.number().optional().catch(undefined),
|
||||||
|
max_option_chars: z.number().optional().catch(undefined),
|
||||||
|
max_options: z.number().optional().catch(undefined),
|
||||||
|
min_expiration: z.number().optional().catch(undefined),
|
||||||
|
});
|
||||||
|
|
||||||
const statsSchema = coerceObject({
|
const statsSchema = coerceObject({
|
||||||
domain_count: z.number().catch(0),
|
domain_count: z.number().catch(0),
|
||||||
status_count: z.number().catch(0),
|
status_count: z.number().catch(0),
|
||||||
|
@ -112,9 +119,11 @@ const instanceSchema = coerceObject({
|
||||||
feature_quote: z.boolean().catch(false),
|
feature_quote: z.boolean().catch(false),
|
||||||
fedibird_capabilities: z.array(z.string()).catch([]),
|
fedibird_capabilities: z.array(z.string()).catch([]),
|
||||||
languages: z.string().array().catch([]),
|
languages: z.string().array().catch([]),
|
||||||
|
max_media_attachments: z.number().optional().catch(undefined),
|
||||||
max_toot_chars: z.number().optional().catch(undefined),
|
max_toot_chars: z.number().optional().catch(undefined),
|
||||||
nostr: nostrSchema.optional().catch(undefined),
|
nostr: nostrSchema.optional().catch(undefined),
|
||||||
pleroma: pleromaSchema,
|
pleroma: pleromaSchema,
|
||||||
|
poll_limits: pleromaPollLimitsSchema,
|
||||||
registrations: z.boolean().catch(false),
|
registrations: z.boolean().catch(false),
|
||||||
rules: filteredArray(ruleSchema),
|
rules: filteredArray(ruleSchema),
|
||||||
short_description: z.string().catch(''),
|
short_description: z.string().catch(''),
|
||||||
|
@ -124,18 +133,28 @@ const instanceSchema = coerceObject({
|
||||||
urls: urlsSchema,
|
urls: urlsSchema,
|
||||||
usage: usageSchema,
|
usage: usageSchema,
|
||||||
version: z.string().catch(''),
|
version: z.string().catch(''),
|
||||||
}).transform(({ max_toot_chars, ...instance }) => {
|
}).transform(({ max_media_attachments, max_toot_chars, poll_limits, ...instance }) => {
|
||||||
const { configuration } = instance;
|
const { configuration } = instance;
|
||||||
|
|
||||||
|
const polls = {
|
||||||
|
...configuration.polls,
|
||||||
|
max_characters_per_option: configuration.polls.max_characters_per_option ?? poll_limits.max_option_chars ?? 25,
|
||||||
|
max_expiration: configuration.polls.max_expiration ?? poll_limits.max_expiration ?? 2629746,
|
||||||
|
max_options: configuration.polls.max_options ?? poll_limits.max_options ?? 4,
|
||||||
|
min_expiration: configuration.polls.min_expiration ?? poll_limits.min_expiration ?? 300,
|
||||||
|
};
|
||||||
|
|
||||||
const statuses = {
|
const statuses = {
|
||||||
...configuration.statuses,
|
...configuration.statuses,
|
||||||
max_characters: configuration.statuses.max_characters ?? max_toot_chars ?? 500,
|
max_characters: configuration.statuses.max_characters ?? max_toot_chars ?? 500,
|
||||||
|
max_media_attachments: configuration.statuses.max_media_attachments ?? max_media_attachments ?? 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...instance,
|
...instance,
|
||||||
configuration: {
|
configuration: {
|
||||||
...instance.configuration,
|
...configuration,
|
||||||
|
polls,
|
||||||
statuses,
|
statuses,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue