Compare commits
1
Commits
2a02dac74e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a20da2ed2 |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "humhub",
|
||||
"version": "0.2.0",
|
||||
"description": "HumHub via REST-API: Wiki-Seiten, Posts und Umfragen auflisten, anzeigen, anlegen und aktualisieren (humhub.py).",
|
||||
"version": "0.3.0",
|
||||
"description": "HumHub via REST-API: Wiki-Seiten, Posts, Umfragen und Kommentare auflisten, anzeigen, anlegen und aktualisieren (humhub.py).",
|
||||
"author": {
|
||||
"name": "inmedias.it"
|
||||
}
|
||||
|
||||
@@ -80,6 +80,17 @@ und nicht Komfort — ohne Begrenzung antwortet die Instanz ab ~25 Umfragen
|
||||
ebenfalls mit 500. Ein fehlgeschlagener POST legt nichts an; vor einem zweiten
|
||||
Versuch trotzdem mit `poll-list` prüfen.
|
||||
|
||||
### Kommentare
|
||||
|
||||
```bash
|
||||
./humhub.py comment-list <content-id|perma-url> # Kommentare eines Inhalts
|
||||
./humhub.py comment-create <content-id|perma-url> [datei|-] # Kommentar schreiben
|
||||
```
|
||||
|
||||
Beide nehmen wie `fetch` eine **Content-ID** oder Perma-URL (nicht die Post-/
|
||||
Wiki-Seiten-ID) und lösen das Zielobjekt selbst auf — funktioniert für Posts
|
||||
und Wiki-Seiten.
|
||||
|
||||
Inhalte (Markdown) aus Datei oder `-` (stdin) übergeben — nicht als langes
|
||||
Shell-Argument (Sonderzeichen). `container_id` akzeptiert eine numerische
|
||||
Container-ID, einen **Space-Slug** oder eine **Space-URL** (`resolve_container`
|
||||
|
||||
@@ -306,6 +306,48 @@ def cmd_space_list(args: argparse.Namespace) -> None:
|
||||
print("(keine Spaces gefunden)")
|
||||
|
||||
|
||||
# ── Comment commands ─────────────────────────────────────────────────────────
|
||||
|
||||
def cmd_comment_list(args: argparse.Namespace) -> None:
|
||||
session, _ = get_session()
|
||||
content_id = parse_content_ref(args.ref)
|
||||
data = api_get(session, f"/comment/content/{content_id}")
|
||||
results = data.get("results", data if isinstance(data, list) else [])
|
||||
if not results:
|
||||
print("(keine Kommentare)")
|
||||
return
|
||||
for c in results:
|
||||
cid = c.get("id")
|
||||
author = (c.get("createdBy") or {}).get("display_name", "?")
|
||||
created = c.get("createdAt", "")
|
||||
msg = (c.get("message") or "").replace("\n", " ")[:100]
|
||||
print(f"ID {cid:>5} [{created}] {author}: {msg}")
|
||||
|
||||
|
||||
def cmd_comment_create(args: argparse.Namespace) -> None:
|
||||
session, _ = get_session()
|
||||
content_id = parse_content_ref(args.ref)
|
||||
message = read_file(args.file)
|
||||
|
||||
envelope = api_get(session, f"/content/{content_id}")
|
||||
meta = envelope.get("metadata", {})
|
||||
model = meta.get("object_model", "")
|
||||
object_id = meta.get("object_id")
|
||||
if not model or not object_id:
|
||||
sys.exit(f"Error: Content {content_id} nicht auflösbar (object_model/object_id fehlen)")
|
||||
|
||||
payload = {
|
||||
"objectModel": model,
|
||||
"objectId": object_id,
|
||||
"Comment": {"message": message},
|
||||
}
|
||||
data = api_post(session, "/comment", payload)
|
||||
cid = data.get("id")
|
||||
short_model = model.split("\\")[-1]
|
||||
print(f"Kommentar erstellt (ID {cid}) auf {short_model} {object_id}")
|
||||
print(f"Perma: https://humhub.inmedias.it/content/perma?id={content_id}")
|
||||
|
||||
|
||||
# ── Fetch (perma-/content-id-agnostisch) ─────────────────────────────────────
|
||||
|
||||
def parse_content_ref(ref: str) -> int:
|
||||
@@ -460,6 +502,17 @@ def main() -> None:
|
||||
p.add_argument("--topics", default=None, help="Komma-getrennte Topic-Namen")
|
||||
p.set_defaults(func=cmd_post_create)
|
||||
|
||||
# comment-list
|
||||
p = sub.add_parser("comment-list", help="Kommentare eines Inhalts auflisten")
|
||||
p.add_argument("ref", help="Content-ID oder Perma-Link (…/content/perma?id=NNNN)")
|
||||
p.set_defaults(func=cmd_comment_list)
|
||||
|
||||
# comment-create
|
||||
p = sub.add_parser("comment-create", help="Kommentar auf einen Inhalt (Post/Wiki-Seite) schreiben")
|
||||
p.add_argument("ref", help="Content-ID oder Perma-Link (…/content/perma?id=NNNN)")
|
||||
p.add_argument("file", help="Markdown-Datei oder '-' für stdin")
|
||||
p.set_defaults(func=cmd_comment_create)
|
||||
|
||||
# post-update
|
||||
p = sub.add_parser("post-update", help="Post aktualisieren")
|
||||
p.add_argument("id", type=int, help="Post-ID")
|
||||
|
||||
Reference in New Issue
Block a user