From d36f58230a326ecacb9c32a4ae8eac65666044f2 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 8 Apr 2024 12:56:27 +0100 Subject: [PATCH] advisory-fix --- application/api/user/routes.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/application/api/user/routes.py b/application/api/user/routes.py index b1ec69e4..ec75554e 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -1,6 +1,7 @@ import os import uuid from flask import Blueprint, request, jsonify +from urllib.parse import urlparse import requests from pymongo import MongoClient from bson.objectid import ObjectId @@ -252,20 +253,26 @@ def check_docs(): if os.path.exists(vectorstore) or data["docs"] == "default": return {"status": "exists"} else: - r = requests.get(base_path + vectorstore + "index.faiss") + file_url = urlparse(base_path + vectorstore + "index.faiss") + + if file_url.scheme in ['https'] and file_url.netloc == 'raw.githubusercontent.com' and file_url.path.startswith('/arc53/DocsHUB/main/'): + + r = requests.get(file_url.geturl()) - if r.status_code != 200: - return {"status": "null"} + if r.status_code != 200: + return {"status": "null"} + else: + if not os.path.exists(vectorstore): + os.makedirs(vectorstore) + with open(vectorstore + "index.faiss", "wb") as f: + f.write(r.content) + + # download the store + r = requests.get(base_path + vectorstore + "index.pkl") + with open(vectorstore + "index.pkl", "wb") as f: + f.write(r.content) else: - if not os.path.exists(vectorstore): - os.makedirs(vectorstore) - with open(vectorstore + "index.faiss", "wb") as f: - f.write(r.content) - - # download the store - r = requests.get(base_path + vectorstore + "index.pkl") - with open(vectorstore + "index.pkl", "wb") as f: - f.write(r.content) + return {"status": "null"} return {"status": "loaded"}