Diff-Endpunkt (GET /documents/{id}/diff) im versioningapi-Handler, Diff-Seite
mit freier Revisionswahl, Farbe+Symbol je Aenderung und Sprung zur naechsten
Aenderung im dms-browser-Frontend.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
// Duenner Client fuer VER-04s Backend-Voraussetzung
|
|
// (dms/internal/versioningapi.handleDiff) — enthaelt keine eigene
|
|
// Diff-Berechnung, nur den HTTP-Aufruf.
|
|
|
|
function apiBase(): string {
|
|
const base = process.env.NEXT_PUBLIC_VERSIONING_API_URL;
|
|
if (!base) {
|
|
throw new Error("NEXT_PUBLIC_VERSIONING_API_URL ist nicht gesetzt (Umgebungsvariable erforderlich)");
|
|
}
|
|
return base;
|
|
}
|
|
|
|
function caller(): string {
|
|
const c = process.env.NEXT_PUBLIC_USER_ID;
|
|
if (!c) {
|
|
throw new Error("NEXT_PUBLIC_USER_ID ist nicht gesetzt (Umgebungsvariable erforderlich)");
|
|
}
|
|
return c;
|
|
}
|
|
|
|
export type DiffOp = "equal" | "insert" | "delete";
|
|
|
|
export interface DiffLine {
|
|
op: DiffOp;
|
|
text: string;
|
|
}
|
|
|
|
export interface MetadataDiffEntry {
|
|
field: string;
|
|
before: string;
|
|
after: string;
|
|
}
|
|
|
|
export interface DiffResult {
|
|
text: DiffLine[];
|
|
metadata: MetadataDiffEntry[];
|
|
}
|
|
|
|
export async function fetchDiff(documentID: string, fromRevisionID: string, toRevisionID: string): Promise<DiffResult> {
|
|
const url = `${apiBase()}/documents/${encodeURIComponent(documentID)}/diff?caller=${encodeURIComponent(caller())}&from=${encodeURIComponent(fromRevisionID)}&to=${encodeURIComponent(toRevisionID)}`;
|
|
const res = await fetch(url);
|
|
if (!res.ok) {
|
|
if (res.status === 403) throw new Error("Zugriff verweigert: keine Berechtigung für eine der beiden Revisionen.");
|
|
throw new Error(`Vergleich fehlgeschlagen (${res.status})`);
|
|
}
|
|
return res.json();
|
|
}
|