fix(restore): tolerate empty settings/feedback text and raise settings value cap
This commit is contained in:
+5
-2
@@ -10,6 +10,7 @@ const USER_SETTING_VALUE_MAX = {
|
|||||||
feedback_prompts: 320000,
|
feedback_prompts: 320000,
|
||||||
};
|
};
|
||||||
const USER_SETTING_VALUE_MAX_DEFAULT = 320000;
|
const USER_SETTING_VALUE_MAX_DEFAULT = 320000;
|
||||||
|
const SETTINGS_VALUE_MAX = 320000;
|
||||||
const BACKUP_TABLES = [
|
const BACKUP_TABLES = [
|
||||||
'groups', 'students', 'entries', 'project_files', 'branches', 'users', 'user_branches',
|
'groups', 'students', 'entries', 'project_files', 'branches', 'users', 'user_branches',
|
||||||
'user_settings', 'user_notes',
|
'user_settings', 'user_notes',
|
||||||
@@ -453,7 +454,9 @@ function normalizeRestoreData(data) {
|
|||||||
}));
|
}));
|
||||||
const settings = {};
|
const settings = {};
|
||||||
for (const [k, v] of Object.entries(data.settings || {})) {
|
for (const [k, v] of Object.entries(data.settings || {})) {
|
||||||
settings[reqStr(k, 100)] = reqStr(String(v), 15000);
|
const value = String(v);
|
||||||
|
if (value.length > SETTINGS_VALUE_MAX) throw new Error('Invalid string length');
|
||||||
|
settings[reqStr(k, 100)] = value;
|
||||||
}
|
}
|
||||||
const audit_log = (data.audit_log || []).map(x => ({
|
const audit_log = (data.audit_log || []).map(x => ({
|
||||||
id: reqInt(x.id),
|
id: reqInt(x.id),
|
||||||
@@ -564,7 +567,7 @@ function normalizeRestoreData(data) {
|
|||||||
topic: optStr(r.topic),
|
topic: optStr(r.topic),
|
||||||
past_review: optStr(r.past_review),
|
past_review: optStr(r.past_review),
|
||||||
short_message_ids: Array.isArray(r.short_message_ids) ? r.short_message_ids.map(v => reqInt(v)) : [],
|
short_message_ids: Array.isArray(r.short_message_ids) ? r.short_message_ids.map(v => reqInt(v)) : [],
|
||||||
text: optStr(r.text),
|
text: optText(r.text, 100000),
|
||||||
ai_status: optStr(r.ai_status) || 'none',
|
ai_status: optStr(r.ai_status) || 'none',
|
||||||
ai_checked_at: optTs(r.ai_checked_at),
|
ai_checked_at: optTs(r.ai_checked_at),
|
||||||
ai_error: optStr(r.ai_error),
|
ai_error: optStr(r.ai_error),
|
||||||
|
|||||||
@@ -90,6 +90,15 @@ throws('user_settings.feedback_prompts длиннее 320000 отклоняет
|
|||||||
user_settings: [{ user_id: 1, key: 'feedback_prompts', value: 'x'.repeat(320001) }],
|
user_settings: [{ user_id: 1, key: 'feedback_prompts', value: 'x'.repeat(320001) }],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const emptySettings = normalizeRestoreData({ ...base, settings: { system_logo: '', ai_prompt: 'x'.repeat(20000) } });
|
||||||
|
ok('пустое значение настройки принимается', emptySettings.settings.system_logo === '', emptySettings.settings.system_logo);
|
||||||
|
ok('длинный ai_prompt (20000) принимается', emptySettings.settings.ai_prompt.length === 20000);
|
||||||
|
const emptyFeedback = normalizeRestoreData({
|
||||||
|
...base,
|
||||||
|
feedbacks: [{ id: 1, group_id: 1, resident: 'R', text: '' }],
|
||||||
|
});
|
||||||
|
ok('пустой текст отзыва принимается', emptyFeedback.feedbacks[0].text === '', emptyFeedback.feedbacks[0].text);
|
||||||
|
|
||||||
const n = normalizeRestoreData({
|
const n = normalizeRestoreData({
|
||||||
...base,
|
...base,
|
||||||
groups: [{ id: 1, name: 'G', deleted_at: '2026-01-02T03:04:05.000Z', purge_at: '2026-02-03T04:05:06.000Z' }],
|
groups: [{ id: 1, name: 'G', deleted_at: '2026-01-02T03:04:05.000Z', purge_at: '2026-02-03T04:05:06.000Z' }],
|
||||||
|
|||||||
Reference in New Issue
Block a user