Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -494,6 +494,45 @@ def generate_image_edit():
|
|
| 494 |
except Exception as e:
|
| 495 |
return jsonify({'error': str(e)}), 500
|
| 496 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
|
| 498 |
# ---------- Credit Request Endpoints ----------
|
| 499 |
|
|
|
|
| 494 |
except Exception as e:
|
| 495 |
return jsonify({'error': str(e)}), 500
|
| 496 |
|
| 497 |
+
#----------View projedts Endpoint ----------
|
| 498 |
+
@app.route('/api/view/projects', methods=['GET'])
|
| 499 |
+
def view_projects():
|
| 500 |
+
try:
|
| 501 |
+
# --- Authentication ---
|
| 502 |
+
auth_header = request.headers.get('Authorization', '')
|
| 503 |
+
if not auth_header.startswith('Bearer '):
|
| 504 |
+
return jsonify({'error': 'Missing or invalid token'}), 401
|
| 505 |
+
token = auth_header.split(' ')[1]
|
| 506 |
+
uid = verify_token(token)
|
| 507 |
+
if not uid:
|
| 508 |
+
return jsonify({'error': 'Invalid or expired token'}), 401
|
| 509 |
+
|
| 510 |
+
# --- Query Stories for the Authenticated User ---
|
| 511 |
+
stories_ref = db.reference('stories')
|
| 512 |
+
all_stories = stories_ref.get() or {}
|
| 513 |
+
user_stories = {}
|
| 514 |
+
|
| 515 |
+
for story_id, story_record in all_stories.items():
|
| 516 |
+
# Only return projects that belong to the current user
|
| 517 |
+
if story_record.get('uid') == uid:
|
| 518 |
+
user_stories[story_id] = {
|
| 519 |
+
"story_id": story_id,
|
| 520 |
+
"full_story": story_record.get("full_story", ""),
|
| 521 |
+
"sections": story_record.get("sections", []),
|
| 522 |
+
"generation_times": story_record.get("generation_times", {}),
|
| 523 |
+
"created_at": story_record.get("created_at", ""),
|
| 524 |
+
"input_type": story_record.get("input_type", ""),
|
| 525 |
+
"story_type": story_record.get("story_type", "")
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
# Optionally, sort the projects by creation date (newest first)
|
| 529 |
+
sorted_stories = dict(
|
| 530 |
+
sorted(user_stories.items(), key=lambda item: item[1]["created_at"], reverse=True)
|
| 531 |
+
)
|
| 532 |
+
|
| 533 |
+
return jsonify({"projects": sorted_stories})
|
| 534 |
+
except Exception as e:
|
| 535 |
+
return jsonify({'error': str(e)}), 500
|
| 536 |
|
| 537 |
# ---------- Credit Request Endpoints ----------
|
| 538 |
|