From 950590db5fa466d3cd3e351eeedeced67135cc8b Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 3 Apr 2024 20:13:05 +1300 Subject: [PATCH] properly delete files --- app/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models.py b/app/models.py index f6100f15..2780f3df 100644 --- a/app/models.py +++ b/app/models.py @@ -213,9 +213,10 @@ class File(db.Model): if self.thumbnail_path and os.path.isfile(self.thumbnail_path): os.unlink(self.thumbnail_path) purge_from_cache.append(self.thumbnail_path.replace('app/', f"https://{current_app.config['SERVER_NAME']}/")) - if self.source_url and not self.source_url.startswith('http') and os.path.isfile(self.source_url): - os.unlink(self.source_url) - purge_from_cache.append(self.source_url.replace('app/', f"https://{current_app.config['SERVER_NAME']}/")) + if self.source_url and self.source_url.startswith('http') and current_app.config['SERVER_NAME'] in self.source_url: + # self.source_url is always a url rather than a file path, which makes deleting the file a bit fiddly + os.unlink(self.source_url.replace(f"https://{current_app.config['SERVER_NAME']}/", 'app/')) + purge_from_cache.append(self.source_url) # otoh it makes purging the cdn cache super easy. if purge_from_cache: flush_cdn_cache(purge_from_cache)