fix: burn file items after download, not metadata fetch

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
肉末
2026-07-14 12:48:42 +08:00
parent eda7010cae
commit f2a1f3a1d6
3 changed files with 51 additions and 7 deletions
+14 -7
View File
@@ -134,20 +134,27 @@ def get_file_item(db: Session, slug: str) -> Item | None:
return item
def burn_file_item(db: Session, item: Item) -> None:
"""Mark a file item burned and remove its bytes from disk."""
item.burned = True
path = resolve_file_path(item)
db.commit()
if path is not None:
try:
path.unlink(missing_ok=True)
except OSError:
pass
def get_item(db: Session, slug: str) -> Item | None:
item = db.scalar(select(Item).where(Item.slug == slug))
if item is None or _is_unavailable(item):
return None
item.view_count += 1
if item.burn_after_read:
# File items burn on download, not metadata fetch.
if item.burn_after_read and item.kind != "file":
item.burned = True
path = resolve_file_path(item)
if path is not None:
try:
path.unlink(missing_ok=True)
except OSError:
pass
db.commit()
db.refresh(item)
return item