Skip to content

Commit

Permalink
🎨️Refactor logic for adding potentially duplicate media
Browse files Browse the repository at this point in the history
  • Loading branch information
meatballs committed Apr 5, 2024
1 parent 16ba5c6 commit 6dcb7a9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server_code/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ def _store_media(request, hash=None, verify=None, **kwargs):
if not verified:
return anvil.server.HttpResponse(400, "Invalid hash for given body")

if app_tables.media.get(hash=hash):
return anvil.server.HttpResponse(400, "Content already exists with this hash")
existing_row = app_tables.media.get(hash=hash)
if existing_row is None:
app_tables.media.add_row(hash=hash, content=content, verified=verified)
elif not existing_row["verified"]:
return anvil.server.HttpResponse(
400, "Unverified content already exists with this hash"
)

app_tables.media.add_row(hash=hash, content=content, verified=verified)
return hash


Expand Down

0 comments on commit 6dcb7a9

Please sign in to comment.