Spaces:
Sleeping
Sleeping
get hobs
Browse files- routers/gemini.py +60 -0
routers/gemini.py
CHANGED
|
@@ -256,6 +256,66 @@ async def analyze_image(
|
|
| 256 |
}
|
| 257 |
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
@router.get("/job/{job_id}")
|
| 260 |
async def get_job_status(
|
| 261 |
job_id: str,
|
|
|
|
| 256 |
}
|
| 257 |
|
| 258 |
|
| 259 |
+
@router.get("/jobs")
|
| 260 |
+
async def get_jobs(
|
| 261 |
+
user: User = Depends(get_current_user),
|
| 262 |
+
db: AsyncSession = Depends(get_db),
|
| 263 |
+
page: int = 1,
|
| 264 |
+
limit: int = 20
|
| 265 |
+
):
|
| 266 |
+
"""
|
| 267 |
+
Get all jobs created by the current user.
|
| 268 |
+
Returns a paginated list of jobs with status, type, and prompt (for video jobs).
|
| 269 |
+
"""
|
| 270 |
+
offset = (page - 1) * limit
|
| 271 |
+
|
| 272 |
+
# Query jobs for the current user
|
| 273 |
+
query = select(GeminiJob).where(
|
| 274 |
+
GeminiJob.user_id == user.user_id
|
| 275 |
+
).order_by(GeminiJob.created_at.desc()).offset(offset).limit(limit)
|
| 276 |
+
|
| 277 |
+
result = await db.execute(query)
|
| 278 |
+
jobs = result.scalars().all()
|
| 279 |
+
|
| 280 |
+
# Get total count
|
| 281 |
+
count_query = select(func.count()).where(GeminiJob.user_id == user.user_id)
|
| 282 |
+
count_result = await db.execute(count_query)
|
| 283 |
+
total_count = count_result.scalar()
|
| 284 |
+
|
| 285 |
+
# Build job list
|
| 286 |
+
job_list = []
|
| 287 |
+
for job in jobs:
|
| 288 |
+
job_item = {
|
| 289 |
+
"job_id": job.job_id,
|
| 290 |
+
"job_type": job.job_type,
|
| 291 |
+
"status": job.status,
|
| 292 |
+
"created_at": job.created_at.isoformat() if job.created_at else None,
|
| 293 |
+
"completed_at": job.completed_at.isoformat() if job.completed_at else None,
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
# Include prompt for video jobs
|
| 297 |
+
if job.job_type == "video" and job.input_data:
|
| 298 |
+
job_item["prompt"] = job.input_data.get("prompt")
|
| 299 |
+
|
| 300 |
+
# Include error message for failed jobs
|
| 301 |
+
if job.status == "failed":
|
| 302 |
+
job_item["error"] = job.error_message
|
| 303 |
+
|
| 304 |
+
# Include download URL for completed video jobs
|
| 305 |
+
if job.status == "completed" and job.job_type == "video" and job.output_data and job.output_data.get("filename"):
|
| 306 |
+
job_item["download_url"] = f"/gemini/download/{job.job_id}"
|
| 307 |
+
|
| 308 |
+
job_list.append(job_item)
|
| 309 |
+
|
| 310 |
+
return {
|
| 311 |
+
"success": True,
|
| 312 |
+
"jobs": job_list,
|
| 313 |
+
"total_count": total_count,
|
| 314 |
+
"page": page,
|
| 315 |
+
"limit": limit
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
|
| 319 |
@router.get("/job/{job_id}")
|
| 320 |
async def get_job_status(
|
| 321 |
job_id: str,
|