mirror of
https://git.squeakyrat.moe/faggot-chan/
synced 2026-11-04 18:35:45 +01:00
autocleanup of manually deleted images from media
This commit is contained in:
1 parent
7958daa50d
commit
d704581548
1 file changed
+6
@@ -254,12 +254,15 @@ vector_db_ready = False # gets set to True after first rebuild so we don't keep
|
||||
|
||||
saved_media = set() # file names inside MEDIA_DIR
|
||||
|
||||
kept_media_lines = []
|
||||
with MEDIA_FILE.open("r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
if "saved media:" in line:
|
||||
name = line.split("saved media:", 1)[1].strip()
|
||||
if (MEDIA_DIR / name).is_file(): # old entries were urls (those expire), they don't match a file so they get dropped
|
||||
saved_media.add(name)
|
||||
kept_media_lines.append(line)
|
||||
MEDIA_FILE.write_text("".join(kept_media_lines), encoding="utf-8") # rewritten without the entries of deleted files
|
||||
|
||||
async def steal_media(url: str, name: str):
|
||||
# discord cdn links are signed and die after a day or so, so we keep our own copy
|
||||
@@ -428,6 +431,9 @@ def sync_reactions(guild):
|
||||
if n not in data[key]:
|
||||
data[key][n] = ""
|
||||
changed = True
|
||||
for n in [n for n in data["media"] if n not in saved_media]: # file got deleted, drop its entry too
|
||||
del data["media"][n]
|
||||
changed = True
|
||||
if changed:
|
||||
REACTIONS_FILE.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
||||
|
||||
|
||||
Reference in new issue
Block a user