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:
@@ -1,6 +1,6 @@
|
||||
(function () {
|
||||
const API = location.origin;
|
||||
const quizId = parseInt(new URLSearchParams(location.search).get('id'), 10);
|
||||
const quizToken = (new URLSearchParams(location.search).get('t') || '').trim();
|
||||
const SYSTEM_KINDS = ['student', 'group', 'branch', 'module'];
|
||||
const FREE_KINDS = ['line', 'text', 'number', 'date', ...SYSTEM_KINDS];
|
||||
const SYSTEM_LABELS = { student: 'ученика', group: 'группы', branch: 'филиала', module: 'темы модуля' };
|
||||
@@ -17,7 +17,7 @@
|
||||
timer: null,
|
||||
done: false,
|
||||
};
|
||||
const RETRY_KEY = 'whatido_quiz_retry_' + (Number.isInteger(quizId) ? quizId : '');
|
||||
const RETRY_KEY = 'whatido_quiz_retry_' + quizToken;
|
||||
let retryTimer = null;
|
||||
|
||||
function esc2(v) {
|
||||
@@ -70,7 +70,11 @@
|
||||
function prepareQuestions(list) {
|
||||
const quiz = state.quiz || {};
|
||||
let items = Array.isArray(list) ? list.slice() : [];
|
||||
if (quiz.shuffle_questions) items = shuffleList(items);
|
||||
if (quiz.shuffle_questions) {
|
||||
const pinned = items.filter(q => q.no_shuffle);
|
||||
const rest = items.filter(q => !q.no_shuffle);
|
||||
items = pinned.concat(shuffleList(rest));
|
||||
}
|
||||
if (quiz.shuffle_options) {
|
||||
items = items.map(q => ({ ...q, options: shuffleList(q.options || []) }));
|
||||
}
|
||||
@@ -199,7 +203,7 @@
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const url = API + '/api/public-quizzes/' + quizId + '/options?field=' + encodeURIComponent(kind)
|
||||
const url = API + '/api/public-quizzes/' + encodeURIComponent(quizToken) + '/options?field=' + encodeURIComponent(kind)
|
||||
+ '&q=' + encodeURIComponent(text) + '&code=' + encodeURIComponent(state.code || '');
|
||||
const res = await fetch(url);
|
||||
const data = await res.json().catch(() => ({}));
|
||||
@@ -348,7 +352,7 @@
|
||||
const codeInput = document.getElementById('qpAccessCode');
|
||||
const code = codeInput ? codeInput.value.trim() : '';
|
||||
try {
|
||||
const res = await fetch(API + '/api/public-quizzes/' + quizId + '/attempts', {
|
||||
const res = await fetch(API + '/api/public-quizzes/' + encodeURIComponent(quizToken) + '/attempts', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code }),
|
||||
@@ -451,7 +455,7 @@
|
||||
answer_id: isSystemKind(q.kind) ? (state.systemIds.get(q.id) || null) : null,
|
||||
}));
|
||||
try {
|
||||
const res = await fetch(API + '/api/public-quizzes/' + quizId + '/attempts/' + state.attempt.id, {
|
||||
const res = await fetch(API + '/api/public-quizzes/' + encodeURIComponent(quizToken) + '/attempts/' + state.attempt.id, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ token: state.attempt.anon_token, answers, time_up: auto === true }),
|
||||
@@ -550,13 +554,13 @@
|
||||
}
|
||||
|
||||
async function init() {
|
||||
if (!Number.isInteger(quizId) || quizId < 1) {
|
||||
if (!/^[a-f0-9]{32}$/i.test(quizToken)) {
|
||||
document.getElementById('qpBody').innerHTML = '<div class="qp-error">Неверная ссылка</div>';
|
||||
return;
|
||||
}
|
||||
bind();
|
||||
try {
|
||||
const res = await fetch(API + '/api/public-quizzes/' + quizId);
|
||||
const res = await fetch(API + '/api/public-quizzes/' + encodeURIComponent(quizToken));
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) throw new Error(data.error || 'Тест не найден');
|
||||
state.quiz = data.quiz;
|
||||
|
||||
Reference in New Issue
Block a user