Line data Source code
1 : import { StorageBackendType, STORAGE_SESSIONS_FOLDER, type SessionEntry } from './storage_backend.js';
2 :
3 : /// Where a single session's files live.
4 : ///
5 : /// The session UUID is the authoritative identity; this describes the *physical* location of that
6 : /// session's files. `nativePath` is the absolute directory that directly holds the session's files
7 : /// (one directory == one session) and is only set when `type` is `Native`.
8 : export interface SessionLocation {
9 : /// The storage backend that physically holds this session's files
10 : type: StorageBackendType;
11 : /// The absolute directory holding the session's files (only for native sessions)
12 : nativePath?: string;
13 : }
14 :
15 : /// Derive a session's physical location from its manifest entry.
16 : ///
17 : /// A `native` entry must carry a `nativePath`; anything else (including the common case of an entry
18 : /// with no storageType field at all) is treated as living in the OPFS root.
19 1 : export function locationFromEntry(entry: SessionEntry): SessionLocation {
20 1 : if (entry.storageType === StorageBackendType.Native && entry.nativePath) {
21 1 : return { type: StorageBackendType.Native, nativePath: entry.nativePath };
22 : }
23 1 : return { type: StorageBackendType.OPFS };
24 1 : }
25 :
26 : /// Build the display path for a session.
27 : ///
28 : /// This value is purely for display (the session bar, the storage overlay). Nothing parses it for
29 : /// identity or routing — the UUID + `SessionLocation` are the source of truth.
30 1 : export function displayPath(uuid: string, loc: SessionLocation): string {
31 1 : if (loc.type === StorageBackendType.Native && loc.nativePath) {
32 1 : return `fs://${loc.nativePath}`;
33 : }
34 1 : return `opfs://${STORAGE_SESSIONS_FOLDER}/${uuid}`;
35 1 : }
|