Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -98,9 +98,8 @@ def generate_report():
|
|
| 98 |
# (Any existing authentication endpoints remain unchanged)
|
| 99 |
|
| 100 |
# ========================================
|
| 101 |
-
# Receipt Processing Endpoint
|
| 102 |
# ========================================
|
| 103 |
-
|
| 104 |
@app.route('/api/process-receipt', methods=['POST'])
|
| 105 |
def process_receipt_endpoint():
|
| 106 |
try:
|
|
@@ -136,10 +135,6 @@ def process_receipt_endpoint():
|
|
| 136 |
manual=False
|
| 137 |
)
|
| 138 |
|
| 139 |
-
# Handle manual entry (if the user explicitly selects manual entry)
|
| 140 |
-
if request.form.get('manual_entry') == 'true':
|
| 141 |
-
return handle_manual_entry(uid, user_ref, user_data)
|
| 142 |
-
|
| 143 |
# Handle image processing (first submission)
|
| 144 |
file = request.files.get('receipt')
|
| 145 |
if not file:
|
|
@@ -187,7 +182,28 @@ def process_receipt_endpoint():
|
|
| 187 |
print(e)
|
| 188 |
return jsonify({'error': str(e)}), 500
|
| 189 |
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
def handle_manual_entry(uid, user_ref, user_data):
|
| 192 |
try:
|
| 193 |
data = {
|
|
|
|
| 98 |
# (Any existing authentication endpoints remain unchanged)
|
| 99 |
|
| 100 |
# ========================================
|
| 101 |
+
# Image Receipt Processing Endpoint
|
| 102 |
# ========================================
|
|
|
|
| 103 |
@app.route('/api/process-receipt', methods=['POST'])
|
| 104 |
def process_receipt_endpoint():
|
| 105 |
try:
|
|
|
|
| 135 |
manual=False
|
| 136 |
)
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
# Handle image processing (first submission)
|
| 139 |
file = request.files.get('receipt')
|
| 140 |
if not file:
|
|
|
|
| 182 |
print(e)
|
| 183 |
return jsonify({'error': str(e)}), 500
|
| 184 |
|
| 185 |
+
|
| 186 |
+
# ========================================
|
| 187 |
+
# Manual Entry Endpoint
|
| 188 |
+
# ========================================
|
| 189 |
+
@app.route('/api/manual-entry', methods=['POST'])
|
| 190 |
+
def manual_entry_endpoint():
|
| 191 |
+
try:
|
| 192 |
+
auth_header = request.headers.get('Authorization')
|
| 193 |
+
token = auth_header.split('Bearer ')[1] if auth_header else None
|
| 194 |
+
uid = verify_token(token) if token else None
|
| 195 |
+
|
| 196 |
+
if not uid:
|
| 197 |
+
return jsonify({'error': 'Invalid token'}), 401
|
| 198 |
+
|
| 199 |
+
user_ref = db.reference(f'users/{uid}')
|
| 200 |
+
user_data = user_ref.get()
|
| 201 |
+
|
| 202 |
+
return handle_manual_entry(uid, user_ref, user_data)
|
| 203 |
+
except Exception as e:
|
| 204 |
+
return jsonify({'error': str(e)}), 500
|
| 205 |
+
|
| 206 |
+
|
| 207 |
def handle_manual_entry(uid, user_ref, user_data):
|
| 208 |
try:
|
| 209 |
data = {
|