vomebook commited on
Commit
3c2686c
·
1 Parent(s): f593deb

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +2 -0
  2. app.py +11 -2
Dockerfile CHANGED
@@ -8,6 +8,8 @@ RUN pip install --no-cache-dir -r requirements.txt
8
  COPY app.py .
9
  COPY static/ static/
10
  COPY data/ data/
 
 
11
 
12
  EXPOSE 7860
13
 
 
8
  COPY app.py .
9
  COPY static/ static/
10
  COPY data/ data/
11
+ COPY CCRD/ CCRD/
12
+ COPY CW/ CW/
13
 
14
  EXPOSE 7860
15
 
app.py CHANGED
@@ -15,6 +15,7 @@ from typing import Optional
15
  from urllib.parse import quote
16
 
17
  from fastapi import FastAPI, Query
 
18
  from fastapi.middleware.cors import CORSMiddleware
19
  from fastapi.middleware.gzip import GZipMiddleware
20
  from fastapi.responses import HTMLResponse, JSONResponse, PlainTextResponse, StreamingResponse
@@ -270,7 +271,10 @@ def api_preview(doc_id: str):
270
  rec = record_map.get(doc_id)
271
  if not rec:
272
  return JSONResponse({"error": "not found"}, status_code=404)
273
- text = get_doc_storage_path(rec).read_text(encoding="utf-8", errors="ignore")
 
 
 
274
  return JSONResponse({"doc_id": doc_id, "title": rec["display_name"], "path": rec["display_rel_path"], "source": rec["source_name"], "text": text})
275
 
276
 
@@ -280,6 +284,8 @@ def api_download(doc_id: str):
280
  if not rec:
281
  return JSONResponse({"error": "not found"}, status_code=404)
282
  file_path = get_doc_storage_path(rec)
 
 
283
  encoded_filename = quote(f"{rec['display_name']}.txt", safe="")
284
  return StreamingResponse(
285
  iter([file_path.read_bytes()]),
@@ -295,7 +301,10 @@ def api_zip(req: ZipRequest):
295
  rec = record_map.get(doc_id)
296
  if not rec:
297
  continue
298
- valid.append((rec["display_rel_path"], get_doc_storage_path(rec).read_bytes()))
 
 
 
299
  if not valid:
300
  return JSONResponse({"error": "no files"}, status_code=400)
301
 
 
15
  from urllib.parse import quote
16
 
17
  from fastapi import FastAPI, Query
18
+ from fastapi import HTTPException
19
  from fastapi.middleware.cors import CORSMiddleware
20
  from fastapi.middleware.gzip import GZipMiddleware
21
  from fastapi.responses import HTMLResponse, JSONResponse, PlainTextResponse, StreamingResponse
 
271
  rec = record_map.get(doc_id)
272
  if not rec:
273
  return JSONResponse({"error": "not found"}, status_code=404)
274
+ file_path = get_doc_storage_path(rec)
275
+ if not file_path.exists():
276
+ return JSONResponse({"error": f"missing file: {file_path.name}"}, status_code=404)
277
+ text = file_path.read_text(encoding="utf-8", errors="ignore")
278
  return JSONResponse({"doc_id": doc_id, "title": rec["display_name"], "path": rec["display_rel_path"], "source": rec["source_name"], "text": text})
279
 
280
 
 
284
  if not rec:
285
  return JSONResponse({"error": "not found"}, status_code=404)
286
  file_path = get_doc_storage_path(rec)
287
+ if not file_path.exists():
288
+ return JSONResponse({"error": f"missing file: {file_path.name}"}, status_code=404)
289
  encoded_filename = quote(f"{rec['display_name']}.txt", safe="")
290
  return StreamingResponse(
291
  iter([file_path.read_bytes()]),
 
301
  rec = record_map.get(doc_id)
302
  if not rec:
303
  continue
304
+ file_path = get_doc_storage_path(rec)
305
+ if not file_path.exists():
306
+ continue
307
+ valid.append((rec["display_rel_path"], file_path.read_bytes()))
308
  if not valid:
309
  return JSONResponse({"error": "no files"}, status_code=400)
310