feat: enhance lesson plan handling with new parser and color-coded room assignments

This commit is contained in:
2026-10-23 00:33:13 +03:00
parent c0487e4c2a
commit 02e6404731
11 changed files with 121 additions and 18 deletions

View File

@@ -4,6 +4,8 @@ import { request, MIN_REFRESH } from "./source.js";
import { DATA } from "./paths.js";
const data = DATA + "parsed/";
// The downloaded Word files: a new parser reads them again without asking the university.
const originals = DATA + "documents/";
// When each document was last downloaded, and the downloads under way: a forced refresh
// downloads a document at most once per MIN_REFRESH, and simultaneous ones share a download.
const fetchedAt = new Map(),
@@ -16,11 +18,12 @@ export async function scheduleFor(file, { refresh = false } = {}) {
if (!refresh)
try {
const cached = JSON.parse(await readFile(cache, "utf8"));
if (
cached.schemaVersion === PARSER_VERSION &&
cached.source.modified === file.modified
)
return cached;
if (cached.source.modified === file.modified) {
if (cached.schemaVersion === PARSER_VERSION) return cached;
// The same file read by an older parser: parse the saved copy again.
const saved = await readFile(originals + file.id).catch(() => null);
if (saved) return parse(file, saved, cache);
}
} catch {}
if (!loading.has(file.id))
loading.set(
@@ -33,6 +36,12 @@ export async function scheduleFor(file, { refresh = false } = {}) {
async function download(file, cache) {
const buffer = await request(file.path);
fetchedAt.set(file.id, Date.now());
await mkdir(originals, { recursive: true });
await writeFile(originals + file.id, buffer);
return parse(file, buffer, cache);
}
async function parse(file, buffer, cache) {
const parsed = await parseWord(buffer, {
name: file.name,
url: file.url,