prince1604 commited on
Commit
21eb86b
·
1 Parent(s): bc84e50

Reinstate synchronous legacy endpoint support

Browse files
Files changed (1) hide show
  1. api.py +36 -6
api.py CHANGED
@@ -257,12 +257,42 @@ def scan_result(job_id: str):
257
  # The user didn't ask to remove it, but the new code replaces the structure.
258
  # I'll enable a blocking legacy endpoint for safety.
259
 
260
- @app.route("/api/seo-report", methods=["GET", "POST"])
261
- def get_seo_report_legacy(domain: Optional[str] = None, limit: int = 25):
262
- # This is tricky with FastAPI vs Flask routing.
263
- # FastAPI doesn't easily support mixed GET/POST like Flask on same route without separate defs.
264
- # We will skip strict legacy support unless needed, as the user wants the NEW structure.
265
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
  if __name__ == "__main__":
268
  import uvicorn
 
257
  # The user didn't ask to remove it, but the new code replaces the structure.
258
  # I'll enable a blocking legacy endpoint for safety.
259
 
260
+ @app.get("/api/seo-report")
261
+ def get_seo_report_legacy_get(
262
+ domain: Optional[str] = Query(None),
263
+ limit: Optional[int] = Query(25)
264
+ ):
265
+ return handle_legacy_request(domain, limit)
266
+
267
+ @app.post("/api/seo-report")
268
+ def get_seo_report_legacy_post(payload: StartReq):
269
+ return handle_legacy_request(payload.domain, payload.limit)
270
+
271
+ def handle_legacy_request(domain: Optional[str], limit: int):
272
+ """
273
+ Simulates the old blocking behavior by starting a job and waiting for it.
274
+ Note: This might timeout on some clients if the scan is long.
275
+ """
276
+ if not domain:
277
+ # Attempt to read cached default report if no domain
278
+ if os.path.exists(REPORT_FILE):
279
+ try:
280
+ with open(REPORT_FILE, 'r', encoding='utf-8') as f:
281
+ return json.load(f)
282
+ except:
283
+ pass
284
+ return JSONResponse(status_code=404, content={"error": "No domain provided and no cached report found."})
285
+
286
+ # Start Job
287
+ job_id = str(uuid4())
288
+ run_scan_job(job_id, domain, limit, is_auto=False)
289
+
290
+ # Check Result
291
+ job = JOBS.get(job_id)
292
+ if job and job["status"] == "done":
293
+ return job["result"]
294
+ else:
295
+ return JSONResponse(status_code=500, content={"error": job.get("error", "Unknown error during scan")})
296
 
297
  if __name__ == "__main__":
298
  import uvicorn