fix(restore): allow long feedback_prompts in user_settings
This commit is contained in:
+17
-6
@@ -3,6 +3,13 @@ const LESSON_REPORT_TEXT_MAX = 5000;
|
|||||||
const LESSON_REPORT_TOPIC_MAX = 300;
|
const LESSON_REPORT_TOPIC_MAX = 300;
|
||||||
const BACKUP_FORMAT_VERSION = 2;
|
const BACKUP_FORMAT_VERSION = 2;
|
||||||
const BACKUP_MIN_FORMAT_VERSION = 1;
|
const BACKUP_MIN_FORMAT_VERSION = 1;
|
||||||
|
const USER_SETTING_VALUE_MAX = {
|
||||||
|
feedback_prompt: 15000,
|
||||||
|
feedback_profile: 100,
|
||||||
|
feedback_models: 16000,
|
||||||
|
feedback_prompts: 320000,
|
||||||
|
};
|
||||||
|
const USER_SETTING_VALUE_MAX_DEFAULT = 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',
|
||||||
@@ -573,12 +580,16 @@ function normalizeRestoreData(data) {
|
|||||||
created_at: optTs(r.created_at),
|
created_at: optTs(r.created_at),
|
||||||
updated_at: optTs(r.updated_at),
|
updated_at: optTs(r.updated_at),
|
||||||
}));
|
}));
|
||||||
const user_settings = (data.user_settings || []).map(x => ({
|
const user_settings = (data.user_settings || []).map(x => {
|
||||||
user_id: reqInt(x.user_id),
|
const key = reqStr(x.key, 100);
|
||||||
key: reqStr(x.key, 100),
|
const max = USER_SETTING_VALUE_MAX[key] || USER_SETTING_VALUE_MAX_DEFAULT;
|
||||||
value: optText(x.value, 16000),
|
return {
|
||||||
updated_at: optTs(x.updated_at),
|
user_id: reqInt(x.user_id),
|
||||||
}));
|
key,
|
||||||
|
value: optText(x.value, max),
|
||||||
|
updated_at: optTs(x.updated_at),
|
||||||
|
};
|
||||||
|
});
|
||||||
const user_notes = (data.user_notes || []).map(x => ({
|
const user_notes = (data.user_notes || []).map(x => ({
|
||||||
id: reqInt(x.id),
|
id: reqInt(x.id),
|
||||||
user_id: reqInt(x.user_id),
|
user_id: reqInt(x.user_id),
|
||||||
|
|||||||
@@ -79,6 +79,17 @@ const userAvatar = normalizeRestoreData({
|
|||||||
});
|
});
|
||||||
ok('users.avatar сохраняется', userAvatar.users[0].avatar === '/uploads/avatar.jpg', userAvatar.users[0]);
|
ok('users.avatar сохраняется', userAvatar.users[0].avatar === '/uploads/avatar.jpg', userAvatar.users[0]);
|
||||||
|
|
||||||
|
const prompts = normalizeRestoreData({
|
||||||
|
...base,
|
||||||
|
user_settings: [{ user_id: 1, key: 'feedback_prompts', value: 'x'.repeat(20000) }],
|
||||||
|
});
|
||||||
|
ok('user_settings.feedback_prompts длиннее 16000 принимается',
|
||||||
|
prompts.user_settings[0].value.length === 20000, prompts.user_settings[0].value.length);
|
||||||
|
throws('user_settings.feedback_prompts длиннее 320000 отклоняется', () => normalizeRestoreData({
|
||||||
|
...base,
|
||||||
|
user_settings: [{ user_id: 1, key: 'feedback_prompts', value: 'x'.repeat(320001) }],
|
||||||
|
}));
|
||||||
|
|
||||||
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