mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
handle missing files
This commit is contained in:
parent
66d05ea860
commit
db99ea33e9
1 changed files with 12 additions and 3 deletions
|
@ -208,14 +208,23 @@ class File(db.Model):
|
||||||
def delete_from_disk(self):
|
def delete_from_disk(self):
|
||||||
purge_from_cache = []
|
purge_from_cache = []
|
||||||
if self.file_path and os.path.isfile(self.file_path):
|
if self.file_path and os.path.isfile(self.file_path):
|
||||||
|
try:
|
||||||
os.unlink(self.file_path)
|
os.unlink(self.file_path)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
...
|
||||||
purge_from_cache.append(self.file_path.replace('app/', f"https://{current_app.config['SERVER_NAME']}/"))
|
purge_from_cache.append(self.file_path.replace('app/', f"https://{current_app.config['SERVER_NAME']}/"))
|
||||||
if self.thumbnail_path and os.path.isfile(self.thumbnail_path):
|
if self.thumbnail_path and os.path.isfile(self.thumbnail_path):
|
||||||
|
try:
|
||||||
os.unlink(self.thumbnail_path)
|
os.unlink(self.thumbnail_path)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
...
|
||||||
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 self.source_url.startswith('http') and current_app.config['SERVER_NAME'] in self.source_url:
|
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
|
# self.source_url is always a url rather than a file path, which makes deleting the file a bit fiddly
|
||||||
|
try:
|
||||||
os.unlink(self.source_url.replace(f"https://{current_app.config['SERVER_NAME']}/", 'app/'))
|
os.unlink(self.source_url.replace(f"https://{current_app.config['SERVER_NAME']}/", 'app/'))
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
...
|
||||||
purge_from_cache.append(self.source_url) # otoh it makes purging the cdn cache super easy.
|
purge_from_cache.append(self.source_url) # otoh it makes purging the cdn cache super easy.
|
||||||
|
|
||||||
if purge_from_cache:
|
if purge_from_cache:
|
||||||
|
|
Loading…
Add table
Reference in a new issue