| Name | Message | Date |
|---|---|---|
| 📁 ui | 10 hours ago | |
| 📄 api.ts | 10 hours ago | |
| 📄 auth.ts | 10 hours ago | |
| 📄 content.ts | 10 hours ago | |
| 📄 errors.ts | 10 hours ago | |
| 📄 hash.ts | 10 hours ago | |
| 📄 md5.ts | 10 hours ago | |
| 📄 selectors.ts | 10 hours ago | |
| 📄 titles.ts | 10 hours ago |
📄
src/titles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { fetchContextToken, fetchDownloadableTitleIds } from './api';
/**
* Cache of title ids that are downloadable as PDF (the main paper — inserts
* and bilagor are not). Warmed on page load and on demand; used to leave
* non-downloadable issues completely untouched (native behaviour).
*/
let downloadableTitleIds: Set<string> | null = null;
let warming: Promise<void> | null = null;
/**
* Is this title downloadable as PDF?
* Returns null when unknown (cache cold) — callers should then intercept
* optimistically and rely on the graceful fallback.
*/
export function isDownloadableTitle(titleId: string): boolean | null {
if (downloadableTitleIds === null) return null;
return downloadableTitleIds.has(titleId);
}
/** Warm the cache (best effort, silent). Safe to call repeatedly. */
export function warmTitlesCache(clientToken: string, sessionToken: string | null): Promise<void> {
warming ??= doWarm(clientToken, sessionToken);
return warming;
}
async function doWarm(clientToken: string, sessionToken: string | null): Promise<void> {
try {
if (!sessionToken) return; // not logged in — nothing to warm yet
const contextToken = await fetchContextToken(clientToken, sessionToken);
downloadableTitleIds = await fetchDownloadableTitleIds(contextToken);
} catch {
downloadableTitleIds = null; // stay cold; next click intercepts optimistically
} finally {
warming = null;
}
}