Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -424,7 +424,6 @@ def get_blob_from_image_url(image_url):
|
|
| 424 |
return None
|
| 425 |
|
| 426 |
|
| 427 |
-
|
| 428 |
@app.route('/api/admin/receipt/<string:transaction_id>/view', methods=['GET'])
|
| 429 |
def view_receipt(transaction_id):
|
| 430 |
try:
|
|
@@ -439,10 +438,11 @@ def view_receipt(transaction_id):
|
|
| 439 |
return jsonify({'error': 'No receipt image found for this transaction'}), 404
|
| 440 |
|
| 441 |
blob_path = get_blob_from_image_url(image_url)
|
|
|
|
| 442 |
if not blob_path:
|
| 443 |
return jsonify({'error': 'Could not determine blob path from URL'}), 500
|
| 444 |
|
| 445 |
-
print(f"**DEBUG: Blob path being used: {blob_path}**")
|
| 446 |
blob = bucket.blob(blob_path)
|
| 447 |
|
| 448 |
if not blob.exists():
|
|
@@ -450,7 +450,7 @@ def view_receipt(transaction_id):
|
|
| 450 |
return jsonify({'error': 'Blob not found'}), 404
|
| 451 |
|
| 452 |
signed_url = blob.generate_signed_url(expiration=timedelta(minutes=10))
|
| 453 |
-
print(f"Signed URL for view: {signed_url}")
|
| 454 |
r = requests.get(signed_url)
|
| 455 |
print(f"View endpoint response status: {r.status_code}") # Debug log
|
| 456 |
if r.status_code != 200:
|
|
@@ -474,20 +474,19 @@ def download_receipt(transaction_id):
|
|
| 474 |
if not image_url:
|
| 475 |
return jsonify({'error': 'No receipt image found for this transaction'}), 404
|
| 476 |
|
| 477 |
-
|
| 478 |
if not blob_path:
|
| 479 |
return jsonify({'error': 'Could not determine blob path from URL'}), 500
|
| 480 |
|
| 481 |
-
print(f"**DEBUG: Blob path being used: {blob_path}**")
|
| 482 |
-
blob = bucket.blob(blob_path)
|
| 483 |
|
| 484 |
-
blob = bucket.blob(blob_path)
|
| 485 |
if not blob.exists():
|
| 486 |
print("Blob does not exist at path:", blob_path)
|
| 487 |
return jsonify({'error': 'Blob not found'}), 404
|
| 488 |
|
| 489 |
signed_url = blob.generate_signed_url(expiration=timedelta(minutes=10))
|
| 490 |
-
print(f"Signed URL for download: {signed_url}")
|
| 491 |
r = requests.get(signed_url)
|
| 492 |
print(f"Download endpoint response status: {r.status_code}") # Debug log
|
| 493 |
if r.status_code != 200:
|
|
@@ -505,6 +504,7 @@ def download_receipt(transaction_id):
|
|
| 505 |
|
| 506 |
|
| 507 |
|
|
|
|
| 508 |
# delete users
|
| 509 |
|
| 510 |
@app.route('/api/admin/users/<string:uid>', methods=['DELETE'])
|
|
|
|
| 424 |
return None
|
| 425 |
|
| 426 |
|
|
|
|
| 427 |
@app.route('/api/admin/receipt/<string:transaction_id>/view', methods=['GET'])
|
| 428 |
def view_receipt(transaction_id):
|
| 429 |
try:
|
|
|
|
| 438 |
return jsonify({'error': 'No receipt image found for this transaction'}), 404
|
| 439 |
|
| 440 |
blob_path = get_blob_from_image_url(image_url)
|
| 441 |
+
|
| 442 |
if not blob_path:
|
| 443 |
return jsonify({'error': 'Could not determine blob path from URL'}), 500
|
| 444 |
|
| 445 |
+
print(f"**DEBUG: Blob path being used: {blob_path}**") # ADD THIS LINE
|
| 446 |
blob = bucket.blob(blob_path)
|
| 447 |
|
| 448 |
if not blob.exists():
|
|
|
|
| 450 |
return jsonify({'error': 'Blob not found'}), 404
|
| 451 |
|
| 452 |
signed_url = blob.generate_signed_url(expiration=timedelta(minutes=10))
|
| 453 |
+
print(f"Signed URL for view: {signed_url}") # Debug log
|
| 454 |
r = requests.get(signed_url)
|
| 455 |
print(f"View endpoint response status: {r.status_code}") # Debug log
|
| 456 |
if r.status_code != 200:
|
|
|
|
| 474 |
if not image_url:
|
| 475 |
return jsonify({'error': 'No receipt image found for this transaction'}), 404
|
| 476 |
|
| 477 |
+
blob_path = get_blob_from_image_url(image_url)
|
| 478 |
if not blob_path:
|
| 479 |
return jsonify({'error': 'Could not determine blob path from URL'}), 500
|
| 480 |
|
| 481 |
+
print(f"**DEBUG: Blob path being used: {blob_path}**") # ADD THIS LINE
|
| 482 |
+
blob = bucket.blob(blob_path) # Debug log
|
| 483 |
|
|
|
|
| 484 |
if not blob.exists():
|
| 485 |
print("Blob does not exist at path:", blob_path)
|
| 486 |
return jsonify({'error': 'Blob not found'}), 404
|
| 487 |
|
| 488 |
signed_url = blob.generate_signed_url(expiration=timedelta(minutes=10))
|
| 489 |
+
print(f"Signed URL for download: {signed_url}") # Debug log
|
| 490 |
r = requests.get(signed_url)
|
| 491 |
print(f"Download endpoint response status: {r.status_code}") # Debug log
|
| 492 |
if r.status_code != 200:
|
|
|
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
+
|
| 508 |
# delete users
|
| 509 |
|
| 510 |
@app.route('/api/admin/users/<string:uid>', methods=['DELETE'])
|