Skip to content

Commit 653d5b6

Browse files
authored
Update app.py
1 parent e8bc530 commit 653d5b6

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎api/app.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,48 @@ async def global_exception_handler(request: Request, exc: Exception):
142142
}
143143
)
144144

145+
@app.get("/check")
146+
@limiter.limit("15/minute")
147+
async def check_cached(request: Request, url: str, target: str):
148+
if not url or not target:
149+
return JSONResponse(
150+
status_code=400,
151+
content={
152+
"status": "error",
153+
"message": "Missing 'url' or 'target' query parameter."
154+
}
155+
)
156+
157+
if target not in SUPPORTED_TARGETS:
158+
return JSONResponse(
159+
status_code=400,
160+
content={
161+
"status": "error",
162+
"message": f"Unsupported target type. Supported: {', '.join(SUPPORTED_TARGETS)}"
163+
}
164+
)
165+
166+
storage_path = generate_storage_path(url)
167+
168+
if hf_api and check_file_in_dataset(storage_path, target):
169+
cache_url = f"https://huggingface.co/datasets/{DATASET_REPO}/resolve/main/{storage_path}/{target}"
170+
return JSONResponse(
171+
status_code=200,
172+
content={
173+
"status": "found",
174+
"download_url": cache_url,
175+
"target": target
176+
}
177+
)
178+
179+
return JSONResponse(
180+
status_code=200,
181+
content={
182+
"status": "not_found",
183+
"target": target
184+
}
185+
)
186+
145187
@app.post("/extract")
146188
@limiter.limit("3/minute")
147189
async def extract_target(request: Request, payload: dict):

0 commit comments

Comments
 (0)