feat: publish Velum copies beside project folder

This commit is contained in:
muena
2026-09-27 08:58:40 +02:00
parent 23af4993db
commit ec327a5220
6 changed files with 95 additions and 21 deletions

View File

@@ -8,7 +8,7 @@ import type { EntityType, PlaceholderMapping } from "./types";
import { getEntityTypes, pseudonymize, pseudonymizeDocument, requireProjectCapabilities } from "./velum";
import type { DocumentHit } from "./velum";
import {
createRun, digest, forceMasks, listRuns, loadProjectEntityTypes, loadProjectRules, parseProjectRules, replaceSpans,
createRun, digest, forceMasks, listRuns, loadProjectEntityTypes, loadProjectRules, parseProjectRules, publishProjectCopies, replaceSpans,
loadProjectWhitelist, matchesPreviousOutput, replaceProjectFilesInPlace, resolveWithin, safeRelativePath, saveProjectRules,
saveProjectEntityTypes, saveProjectWhitelist, saveRun, scanProjectFiles, toUtf16Offsets, whitelistKey,
} from "./lib/velum-project";
@@ -251,7 +251,7 @@ function HitReview(props: { root: string; rules: ProjectRule[]; whitelist: Proje
return next;
});
}
async function apply(inPlace = false) {
async function apply(inPlace = true) {
if (!props.preview.drafts.length && !accepted.size) {
try {
const rejected = groups.map((group) => ({ type: group.type, original: group.original }));
@@ -278,6 +278,7 @@ function HitReview(props: { root: string; rules: ProjectRule[]; whitelist: Proje
const toast = await showToast({ style: Toast.Style.Animated,
title: inPlace ? "Originaldateien werden ersetzt" : "Pseudonymisierte Kopien werden erstellt" });
let directory: string | undefined;
let publishedCopyPath: string | undefined;
let persisted = false;
try {
const created = await createRun(props.root);
@@ -336,6 +337,10 @@ function HitReview(props: { root: string; rules: ProjectRule[]; whitelist: Proje
run.files.push(file);
replacements.push(file);
}
if (!inPlace) {
publishedCopyPath = await publishProjectCopies(run, directory);
run.copyPath = publishedCopyPath;
}
await saveRun(directory, run);
persisted = true;
if (inPlace) {
@@ -355,11 +360,12 @@ function HitReview(props: { root: string; rules: ProjectRule[]; whitelist: Proje
toast.style = Toast.Style.Success;
toast.title = inPlace ? `${replacements.length} Dateien ersetzt` : `${run.files.length} Kopien erstellt`;
toast.message = inPlace ? "Die Sicherung ist im Raycast-Datenordner gespeichert."
: "Die Kopien sind im Raycast-Datenordner gespeichert.";
setCompleted({ directory: join(directory, inPlace ? "backup" : "files"), inPlace, files: run.files.length });
await showInFinder(inPlace ? props.root : join(directory, "files")).catch(() => undefined);
: "Die Kopien liegen neben dem Projektordner.";
setCompleted({ directory: inPlace ? join(directory, "backup") : publishedCopyPath!, inPlace, files: run.files.length });
await showInFinder(inPlace ? props.root : publishedCopyPath!).catch(() => undefined);
} catch (error) {
if (directory && !persisted) await fs.rm(directory, { recursive: true, force: true });
if (publishedCopyPath && !persisted) await fs.rm(publishedCopyPath, { recursive: true, force: true });
toast.style = Toast.Style.Failure;
toast.title = "Pseudonymisierung fehlgeschlagen";
toast.message = `${(error as Error).message}${persisted && directory ? ` Kopien/Sicherung: ${directory}` : ""}`;
@@ -370,7 +376,7 @@ function HitReview(props: { root: string; rules: ProjectRule[]; whitelist: Proje
<List.Item icon={Icon.CheckCircle}
title={completed.inPlace ? "Projektdateien ersetzt" : `${completed.files} pseudonymisierte Kopien erstellt`}
subtitle={completed.inPlace ? "Die Originale wurden gesichert."
: "Die Originaldateien im Projektordner bleiben unverändert."}
: completed.directory}
actions={<ActionPanel>
<Action title={completed.inPlace ? "Sicherung im Finder anzeigen" : "Kopien im Finder anzeigen"}
icon={Icon.Folder} onAction={() => showInFinder(completed.directory)} />
@@ -384,8 +390,8 @@ function HitReview(props: { root: string; rules: ProjectRule[]; whitelist: Proje
<List.Item icon={Icon.Play} title="Pseudonymisierung starten"
subtitle={`${selectedGroups.size} Zuordnungen · ${people.length} Personen · ${props.preview.retained.length} unveränderte Dateien übernommen`}
actions={<ActionPanel>
<Action title="Pseudonymisierte Kopien erstellen" icon={Icon.Document} onAction={() => apply()} />
<Action title="Originaldateien ersetzen" icon={Icon.Pencil} onAction={() => apply(true)} />
<Action title="Originaldateien ersetzen" icon={Icon.Pencil} onAction={() => apply()} />
<Action title="Pseudonymisierte Kopien erstellen" icon={Icon.Document} onAction={() => apply(false)} />
<Action title="Zur Trefferauswahl" icon={Icon.ArrowLeft} onAction={() => setStage("selection")} />
</ActionPanel>} />
</List.Section>
@@ -409,8 +415,8 @@ function HitReview(props: { root: string; rules: ProjectRule[]; whitelist: Proje
onAction={() => setPersonMerges((current) => {
const next = { ...current }; delete next[person.placeholder]; return next;
})} />}
<Action title="Pseudonymisierte Kopien erstellen" icon={Icon.Document} onAction={() => apply()} />
<Action title="Originaldateien ersetzen" icon={Icon.Pencil} onAction={() => apply(true)} />
<Action title="Originaldateien ersetzen" icon={Icon.Pencil} onAction={() => apply()} />
<Action title="Pseudonymisierte Kopien erstellen" icon={Icon.Document} onAction={() => apply(false)} />
</ActionPanel>} />;
})}
</List.Section>
@@ -590,6 +596,6 @@ export default function Command() {
{availableTypes.map((type) => <Form.TagPicker.Item key={type} value={type} title={labelForType(type)} />)}
</Form.TagPicker>
<Form.Description title="Projekt-Whitelist" text={`${whitelist.length} Begriffe werden bei diesem Ordner nicht mehr vorgeschlagen. Über die Aktionen kannst du sie wieder freigeben.`} />
<Form.Description title="Ablauf" text="Kategorien wählen, Zuordnungen auswählen, Personen bei Bedarf zusammenfassen und dann Kopien erstellen oder Originale ersetzen." />
<Form.Description title="Ablauf" text="Kategorien wählen, Zuordnungen auswählen und Personen bei Bedarf zusammenfassen. Standardmäßig werden die Originaldateien nach Bestätigung ersetzt; Kopien sind als Alternative verfügbar." />
</Form>;
}