Dateien nach "app" hochladen

Anpassungen an der Ausgabe in Outline
This commit is contained in:
2026-07-24 16:31:32 +00:00
parent 84d89addfe
commit 1b4d20f295
2 changed files with 293 additions and 14 deletions
+71 -2
View File
@@ -50,10 +50,15 @@ class OutlineClient:
data = self._post("/collections.info", {"id": collection_id_or_slug})
return data["data"]["id"]
def get_document(self, document_id_or_slug: str) -> dict:
"""Lädt die vollständigen Metadaten eines Dokuments per ID oder
Friendly-URL-Slug (u.a. für den aktuellen Titel gebraucht)."""
data = self._post("/documents.info", {"id": document_id_or_slug})
return data["data"]
def resolve_document_id(self, document_id_or_slug: str) -> str:
"""Löst eine Dokument-ID oder Friendly-URL-Slug in die echte UUID auf."""
data = self._post("/documents.info", {"id": document_id_or_slug})
return data["data"]["id"]
return self.get_document(document_id_or_slug)["id"]
def find_document_by_title(
self, title: str, collection_id: str, parent_document_id: str | None = None
@@ -99,6 +104,70 @@ class OutlineClient:
)
return data["data"]
def list_documents(self, collection_id: str, parent_document_id: str | None = None) -> list[dict]:
"""Listet alle Dokumente einer Collection (optional gefiltert auf
direkte Kinder von parent_document_id), paginiert."""
docs: list[dict] = []
offset = 0
limit = 100
while True:
payload: dict = {"collectionId": collection_id, "limit": limit, "offset": offset}
if parent_document_id:
payload["parentDocumentId"] = parent_document_id
data = self._post("/documents.list", payload)
batch = data["data"]
docs.extend(batch)
if len(batch) < limit:
break
offset += limit
return docs
def list_revisions(self, document_id: str) -> list[dict]:
"""Listet alle Revisionen (Versionsverlauf) eines Dokuments, paginiert."""
revisions: list[dict] = []
offset = 0
limit = 100
while True:
data = self._post(
"/revisions.list",
{"documentId": document_id, "limit": limit, "offset": offset},
)
batch = data["data"]
revisions.extend(batch)
if len(batch) < limit:
break
offset += limit
return revisions
def delete_revision(self, revision_id: str) -> None:
self._post("/revisions.delete", {"id": revision_id})
def purge_document_history(self, document_id: str) -> int:
"""Löscht ALLE Revisionen eines Dokuments dauerhaft und unwiederbringlich
(nicht der aktuelle Inhalt selbst, nur der Versionsverlauf).
Returns: Anzahl gelöschter Revisionen.
"""
revisions = self.list_revisions(document_id)
for revision in revisions:
self.delete_revision(revision["id"])
return len(revisions)
def prune_document_history(self, document_id: str, keep: int) -> int:
"""Behält nur die `keep` neuesten Revisionen eines Dokuments, alle
älteren werden dauerhaft gelöscht und sind nicht wiederherstellbar.
Returns: Anzahl gelöschter Revisionen.
"""
if keep < 0:
keep = 0
revisions = self.list_revisions(document_id)
revisions.sort(key=lambda r: r.get("createdAt") or "", reverse=True)
to_delete = revisions[keep:]
for revision in to_delete:
self.delete_revision(revision["id"])
return len(to_delete)
def upsert_document(
self,
title: str,