Skip to content

Commit

Permalink
Merge pull request from GHSA-p5qc-vj2x-9rjp
Browse files Browse the repository at this point in the history
advisory-fix
  • Loading branch information
dartpain committed Apr 8, 2024
2 parents 018f950 + d36f582 commit bd2d0b6
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions application/api/user/routes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")

if r.status_code != 200:
return {"status": "null"}
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"}
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"}

Expand Down

0 comments on commit bd2d0b6

Please sign in to comment.