feat: export daily practice image packages

This commit is contained in:
Codex
2026-06-29 17:40:10 +08:00
parent 60501a0f70
commit a68b4ab9e3
16 changed files with 809 additions and 62 deletions

View File

@@ -7,7 +7,7 @@ import { requireTenantContentEditor, type TenantContentAuth } from './auth.js';
import { boolValue, jsonObjectValue, nullableString } from './utils.js';
const INLINE_EXPORT_FORMATS = ['json', 'paper_json', 'print_payload'];
const BINARY_EXPORT_FORMATS = ['pdf', 'docx'];
const BINARY_EXPORT_FORMATS = ['pdf', 'docx', 'daily_practice_zip'];
const EXPORT_FORMATS = [...INLINE_EXPORT_FORMATS, ...BINARY_EXPORT_FORMATS];
const EXPORT_TYPES = ['questions', 'paper', 'daily_practice'];
const SCOPE_TYPES = ['collection', 'entry', 'content_node'];
@@ -184,6 +184,16 @@ function isBinaryExportFormat(format: string) {
return BINARY_EXPORT_FORMATS.includes(format);
}
function assertExportFormatMatchesType(format: string, exportType: string) {
if (format === 'daily_practice_zip' && exportType !== 'daily_practice') {
throw new HttpError(
400,
'daily_practice_zip is only supported for daily_practice exports',
'DAILY_PRACTICE_ZIP_REQUIRES_DAILY_PRACTICE',
);
}
}
function jsonArray(value: unknown) {
return Array.isArray(value) ? value : [];
}
@@ -732,9 +742,10 @@ export async function createQuestionExportRoute(ctx: RequestContext) {
const exportType = choose(
body.exportType,
EXPORT_TYPES,
format === 'paper_json' || isBinaryExportFormat(format) ? 'paper' : 'questions',
format === 'daily_practice_zip' ? 'daily_practice' : format === 'paper_json' || isBinaryExportFormat(format) ? 'paper' : 'questions',
'INVALID_EXPORT_TYPE',
);
assertExportFormatMatchesType(format, exportType);
const includeAnswers = boolValue(body.includeAnswers, true);
const includeExplanations = boolValue(body.includeExplanations, includeAnswers);
const includeVideoRefs = boolValue(body.includeVideoRefs, false);