fix: burn file items after download, not metadata fetch
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user