check vocabulary

This commit is contained in:
2026-05-25 11:25:12 +08:00
parent 4088fbc9e7
commit 1de143740a
6 changed files with 573 additions and 8 deletions

View File

@@ -73,11 +73,19 @@ const WORD_RECORD_MODES: WordRecordModeKey[] = [
'multipleChoice'
];
const getNumericEnv = (names: string[], fallback: number): number => {
for (const name of names) {
const parsed = Number(process.env[name]);
if (Number.isFinite(parsed)) return parsed;
}
return fallback;
};
const ATTEMPT_TTL_MS = 30 * 60 * 1000;
const MIN_STUDY_WORD_COUNT = 10;
const MAX_STUDY_WORD_COUNT = 100;
const MIN_SECONDS_PER_QUESTION = Number(process.env.VOCABULARY_MIN_SECONDS_PER_QUESTION || 2);
const MAX_SECONDS_PER_QUESTION = Number(process.env.VOCABULARY_MAX_SECONDS_PER_QUESTION || 10);
const MIN_SECONDS_PER_QUESTION = getNumericEnv(['VOCABULARY_MIN_SECONDS_PER_QUESTION', 'MIN_SECONDS_PER_QUESTION'], 2);
const MAX_SECONDS_PER_QUESTION = getNumericEnv(['VOCABULARY_MAX_SECONDS_PER_QUESTION', 'MAX_SECONDS_PER_QUESTION'], 10);
const VOCABULARY_ALLOWED_ORIGINS = (process.env.VOCABULARY_ALLOWED_ORIGINS || 'https://d1kt.cn,http://localhost:3000,http://localhost:3001')
.split(',')
.map(item => item.trim())
@@ -1249,7 +1257,9 @@ router.post('/test-record', authMiddleware, async (req, res) => {
userAnswer: result.userAnswer,
correctAnswer: result.correctAnswer,
isCorrect: shouldInvalidateBatch ? false : result.isCorrect
}))
})),
invalidated: shouldInvalidateBatch,
riskFlags: attemptAny.riskFlags || []
});
res.status(201).json({