feat(quizzes): публичные ссылки по токену и флаг no_shuffle

- quizzes.public_token (VARCHAR 32, уникальный индекс) вместо числового id в публичных роутах /api/public-quizzes/:token
- бэкилл токенов для существующих строк в db/migration.sql + ensureQuizTables
- quiz_questions.no_shuffle — вопрос исключён из перемешивания
- POST /api/quizzes/:id/public-token/rotate — сброс утёкшей ссылки (автор/админ)
- restore: no_shuffle в INSERT quiz_questions, backup.selftest обновлён
- документация AGENTS.md + handoff
This commit is contained in:
dev
2026-12-03 00:33:50 +03:00
parent a92fa830a2
commit d9b785d36c
13 changed files with 157 additions and 58 deletions
+7
View File
@@ -1,3 +1,4 @@
const crypto = require('crypto');
const { normalizeStudentStatus } = require('./lib/students');
const { normalizeUserColor } = require('./lib/users');
const PHOTO_JOB_ACTIONS = new Set(['ai', 'ai_face', 'ai_upscale', 'enhance', 'restore', 'rollback']);
@@ -863,6 +864,10 @@ function normalizeRestoreData(data) {
return Math.min(hi, Math.max(lo, Math.trunc(n)));
};
const quizScore = v => Math.min(100000, Math.max(0, Math.round((Number(v) || 0) * 100) / 100));
const quizPublicToken = v => {
const value = typeof v === 'string' ? v.trim().toLowerCase() : '';
return /^[a-f0-9]{32}$/.test(value) ? value : crypto.randomBytes(16).toString('hex');
};
const gradeScales = (data.quiz_grade_scales || []).map(x => ({
id: reqInt(x.id),
name: optText(x.name, 200) || '',
@@ -903,6 +908,7 @@ function normalizeRestoreData(data) {
allow_anonymous: x.allow_anonymous === true,
stats_public: x.stats_public === true,
access_code: optText(x.access_code, 64) || null,
public_token: quizPublicToken(x.public_token),
author_id: x.author_id == null ? null : reqInt(x.author_id),
created_at: optTs(x.created_at),
updated_at: optTs(x.updated_at),
@@ -921,6 +927,7 @@ function normalizeRestoreData(data) {
required: x.required !== false,
min_length: quizInt(x.min_length, 0, 2000, 0),
options_inline: x.options_inline === true,
no_shuffle: x.no_shuffle === true,
text_match: x.text_match === 'contains' ? 'contains' : 'exact',
accepted_answers: (() => {
if (!Array.isArray(x.accepted_answers)) return [];