Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -231,6 +231,7 @@ async def list_similar_files():
|
|
231 |
@app.get("/files/find/{search}")
|
232 |
async def search_file(search: str):
|
233 |
try:
|
|
|
234 |
for filename in os.listdir(BASE_DIR):
|
235 |
if f"{search}" in filename and filename.endswith(".json"):
|
236 |
filepath = os.path.join(BASE_DIR, filename)
|
@@ -240,11 +241,11 @@ async def search_file(search: str):
|
|
240 |
file_content = f.read()
|
241 |
try:
|
242 |
file_content_json = json.loads(file_content)
|
243 |
-
|
244 |
except json.JSONDecodeError:
|
245 |
-
|
246 |
except (IOError, OSError) as e:
|
247 |
raise HTTPException(status_code=500, detail=f"Erro ao ler o ficheiro {filename}: {e}")
|
248 |
-
|
249 |
except FileNotFoundError:
|
250 |
raise HTTPException(status_code=404, detail="Diret贸rio de dados n茫o encontrado")
|
|
|
231 |
@app.get("/files/find/{search}")
|
232 |
async def search_file(search: str):
|
233 |
try:
|
234 |
+
files_data = []
|
235 |
for filename in os.listdir(BASE_DIR):
|
236 |
if f"{search}" in filename and filename.endswith(".json"):
|
237 |
filepath = os.path.join(BASE_DIR, filename)
|
|
|
241 |
file_content = f.read()
|
242 |
try:
|
243 |
file_content_json = json.loads(file_content)
|
244 |
+
files_data.append({"filename": filename, "content": file_content_json})
|
245 |
except json.JSONDecodeError:
|
246 |
+
files_data.append({"filename": filename, "content": file_content})
|
247 |
except (IOError, OSError) as e:
|
248 |
raise HTTPException(status_code=500, detail=f"Erro ao ler o ficheiro {filename}: {e}")
|
249 |
+
return JSONResponse({"files_data": files_data})
|
250 |
except FileNotFoundError:
|
251 |
raise HTTPException(status_code=404, detail="Diret贸rio de dados n茫o encontrado")
|