From 5cde4ac06ba05d608577ac4c748b29463cec4d8f Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Sat, 18 May 2024 18:59:41 +0200 Subject: [PATCH] Also report note URL for revision check --- hedgedoc-expire.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hedgedoc-expire.py b/hedgedoc-expire.py index 21d4ce6..90b19b6 100644 --- a/hedgedoc-expire.py +++ b/hedgedoc-expire.py @@ -94,6 +94,7 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]: "Users"."email", "Revisions"."id" as "revisionId", "Notes"."id" as "noteId", + "Notes"."shortid" as "shortid", "Notes"."title" FROM "Revisions", "Notes", "Users" WHERE "Revisions"."createdAt" < $1 @@ -106,6 +107,7 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]: 'email': row.email, 'noteId': row.noteId, 'revisionId': row.revisionId, + 'shortid': row.shortid, 'title': row.title }) return revisions @@ -119,7 +121,7 @@ def check_notes_to_be_expired(age: timedelta, config: Config) -> None: print(f' {note["email"]} ({humanize.naturaldelta(age)}) {config.url}/{note["alias"]}: {note["title"]}') -def check_revisions_to_be_expired(age: timedelta) -> None: +def check_revisions_to_be_expired(age: timedelta, config: Config) -> None: cutoff = datetime.now(timezone.utc) - age print(f'Revisions to be deleted older than {cutoff} ({humanize.naturaldelta(age)}):') notes = {} @@ -130,7 +132,8 @@ def check_revisions_to_be_expired(age: timedelta) -> None: notes[row['noteId']].append(row) for id, revisions in notes.items(): email = revisions[0]['email'] - print(f' {revisions[0]["email"]}: {revisions[0]["title"]}') + url = config.url + '/' + (revisions[0]["title"] if revisions[0]["title"] is not None else revisions[0]["shorturl"]) + print(f' {revisions[0]["email"]} {url}: {revisions[0]["title"]}') for rev in revisions: print(f' {humanize.naturaldelta(rev["age"])}: {rev["revisionId"]}') @@ -199,7 +202,7 @@ if __name__ == '__main__': with pgsql.Connection((config.postgres_hostname, config.postgres_port), config.postgres_username, config.postgres_password) as db: if args.check: - check_revisions_to_be_expired(revisions_delta) + check_revisions_to_be_expired(revisions_delta, config) check_notes_to_be_expired(notes_delta, config) sys.exit(0) expire_old_revisions(revisions_delta)