- packages/metadata: {variable} templates, Photo Mechanic code replacement, IPTC fields of the current pad (title = persons shown), IIM/XMP mapping, delivery folder and file-name templates (FPA, Liga)
- API: events with agenda and IPTC template, FTP logins, ingest worker (hash, dedupe, EXIF in Lisbon time, routing by agenda + capture time, previews), library culling, IPTC preview, code list, signed file URLs
- Realtime: Socket.io with Postgres LISTEN/NOTIFY fan-out
- Delivery: queue with fixed sequence numbers, 4000 px JPEG 100 with IPTC via ExifTool, WebDAV upload with retries, OCS share links, encrypted app passwords
- Web app: approved type and Lightroom-style workspace, grid/loupe with keyboard culling, players, IPTC panel, delivery queue, code list editor
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
70 lines
2.5 KiB
TypeScript
70 lines
2.5 KiB
TypeScript
/**
|
||
* Code replacement: `\v7\` in any text field becomes the value stored for code `v7`.
|
||
*
|
||
* Lists are imported from plain text, one entry per line, columns separated by tabs:
|
||
* `code<TAB>value[<TAB>value 2 ...]`. This reads the common two-column Photo Mechanic list as is.
|
||
* `\code\` uses the first value; `\code#2\` picks another column (PhotoReport syntax).
|
||
* Blank lines and lines starting with `#` are ignored. Codes are case-sensitive, like in Photo Mechanic.
|
||
*/
|
||
|
||
export interface CodeList {
|
||
readonly entries: ReadonlyMap<string, readonly string[]>;
|
||
}
|
||
|
||
export interface CodeListIssue {
|
||
line: number;
|
||
message: string;
|
||
}
|
||
|
||
export function parseCodeList(text: string): { list: CodeList; issues: CodeListIssue[] } {
|
||
const entries = new Map<string, string[]>();
|
||
const issues: CodeListIssue[] = [];
|
||
text
|
||
.replace(/^/, "")
|
||
.split(/\r\n|\r|\n/)
|
||
.forEach((raw, index) => {
|
||
const line = index + 1;
|
||
if (raw.trim() === "" || raw.trimStart().startsWith("#")) return;
|
||
const [code, ...values] = raw.split("\t").map((part) => part.trim());
|
||
if (!code || values.length === 0 || values.every((v) => v === "")) {
|
||
issues.push({ line, message: "expected a code, a tab and a value" });
|
||
return;
|
||
}
|
||
if (/[\\\s#]/.test(code)) {
|
||
issues.push({ line, message: `invalid code "${code}"` });
|
||
return;
|
||
}
|
||
if (entries.has(code)) issues.push({ line, message: `duplicate code "${code}", last one wins` });
|
||
entries.set(code, values);
|
||
});
|
||
return { list: { entries }, issues };
|
||
}
|
||
|
||
export function codeList(record: Record<string, string | readonly string[]>): CodeList {
|
||
const entries = new Map<string, readonly string[]>();
|
||
for (const [code, value] of Object.entries(record)) entries.set(code, typeof value === "string" ? [value] : value);
|
||
return { entries };
|
||
}
|
||
|
||
const CODE = /\\([^\\\s#]+)(?:#(\d+))?\\/g;
|
||
|
||
export interface ExpandResult {
|
||
text: string;
|
||
/** Codes used in the text that are not in the list (left untouched). */
|
||
unknown: string[];
|
||
}
|
||
|
||
export function expandCodes(text: string, list: CodeList): ExpandResult {
|
||
const unknown = new Set<string>();
|
||
const out = text.replace(CODE, (match, code: string, column: string | undefined) => {
|
||
const values = list.entries.get(code);
|
||
const value = values?.[column ? Number(column) - 1 : 0];
|
||
if (value === undefined || value === "") {
|
||
unknown.add(column ? `${code}#${column}` : code);
|
||
return match;
|
||
}
|
||
return value;
|
||
});
|
||
return { text: out, unknown: [...unknown] };
|
||
}
|