properly delete files

This commit is contained in:
rimu 2024-04-03 20:13:05 +13:00
parent 1e38fcf9b3
commit 950590db5f

View file

@ -213,9 +213,10 @@ class File(db.Model):
if self.thumbnail_path and os.path.isfile(self.thumbnail_path): if self.thumbnail_path and os.path.isfile(self.thumbnail_path):
os.unlink(self.thumbnail_path) os.unlink(self.thumbnail_path)
purge_from_cache.append(self.thumbnail_path.replace('app/', f"https://{current_app.config['SERVER_NAME']}/")) 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): if self.source_url and self.source_url.startswith('http') and current_app.config['SERVER_NAME'] in self.source_url:
os.unlink(self.source_url) # self.source_url is always a url rather than a file path, which makes deleting the file a bit fiddly
purge_from_cache.append(self.source_url.replace('app/', f"https://{current_app.config['SERVER_NAME']}/")) 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: if purge_from_cache:
flush_cdn_cache(purge_from_cache) flush_cdn_cache(purge_from_cache)