文件需转化返回内容
This commit is contained in:
parent
61f40aa983
commit
74e3470b88
|
|
@ -88,9 +88,11 @@ def get_file():
|
||||||
def get_file_add_convert():
|
def get_file_add_convert():
|
||||||
file_list = get_file()
|
file_list = get_file()
|
||||||
if file_list:
|
if file_list:
|
||||||
|
s = {"epub","txt","docx","pdf","doc", "go", "c", "cpp", "java", "py", "js", "html", "css", "json", "xml", "yaml", "md"}
|
||||||
for file in file_list:
|
for file in file_list:
|
||||||
#文件类型是否允许
|
#文件类型是否允许
|
||||||
if file["FileStoreName"].endswith(".txt") or file["FileStoreName"].endswith(".docx") or file["FileStoreName"].endswith(".pdf") or file["FileStoreName"].endswith(".epub"):
|
fileType = file["FileStoreName"].split(".")[-1]
|
||||||
|
if fileType in s:
|
||||||
print("文件类型允许")
|
print("文件类型允许")
|
||||||
else:
|
else:
|
||||||
print("文件类型不允许:", file["FileStoreName"])
|
print("文件类型不允许:", file["FileStoreName"])
|
||||||
|
|
@ -100,11 +102,11 @@ def get_file_add_convert():
|
||||||
text = fileBase.get_file_content(file["FileStoreName"])
|
text = fileBase.get_file_content(file["FileStoreName"])
|
||||||
if text is None:
|
if text is None:
|
||||||
print("文件内容获取失败")
|
print("文件内容获取失败")
|
||||||
return None
|
continue
|
||||||
print("文件内容长度:", len(text))
|
print("文件内容长度:", len(text))
|
||||||
#将文件内容上传
|
#将文件内容上传
|
||||||
print(create_file_content(file["ID"], text))
|
print(create_file_content(file["ID"], text))
|
||||||
break
|
#break
|
||||||
else:
|
else:
|
||||||
print("未能获取文件列表")
|
print("未能获取文件列表")
|
||||||
|
|
||||||
|
|
@ -129,5 +131,5 @@ def get_Kbase_server_id():
|
||||||
print(f"请求失败,状态码: {response.status_code}, 错误信息: {response.text}")
|
print(f"请求失败,状态码: {response.status_code}, 错误信息: {response.text}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if __name__ == "__main__":
|
# if __name__ == "__main__":
|
||||||
get_file_add_convert()
|
# get_file_add_convert()
|
||||||
|
|
@ -3,6 +3,7 @@ import time
|
||||||
import json
|
import json
|
||||||
import fileChroma
|
import fileChroma
|
||||||
import threading
|
import threading
|
||||||
|
import fileCon
|
||||||
|
|
||||||
config = {}
|
config = {}
|
||||||
stop_event = False
|
stop_event = False
|
||||||
|
|
@ -92,6 +93,14 @@ def input_listener(ws):
|
||||||
ws.close()
|
ws.close()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def sfile_content():
|
||||||
|
#每10秒获取转换一次
|
||||||
|
while True:
|
||||||
|
time.sleep(10)
|
||||||
|
# 文件内容转换
|
||||||
|
fileCon.get_file_add_convert()
|
||||||
|
if stop_event:
|
||||||
|
break
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
config = readConfig()
|
config = readConfig()
|
||||||
|
|
@ -109,6 +118,9 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
input_thread = threading.Thread(target=input_listener, args=(ws,))
|
input_thread = threading.Thread(target=input_listener, args=(ws,))
|
||||||
input_thread.start()
|
input_thread.start()
|
||||||
|
if config["file_convert"]:
|
||||||
|
file_thread = threading.Thread(target=sfile_content)
|
||||||
|
file_thread.start()
|
||||||
# 运行 WebSocket 连接
|
# 运行 WebSocket 连接
|
||||||
ws.run_forever()
|
ws.run_forever()
|
||||||
|
|
||||||
|
|
@ -5,5 +5,6 @@
|
||||||
"ws_retry_delay": 1,
|
"ws_retry_delay": 1,
|
||||||
"kbase_info": {"vfdbvd":{"1":true,"collection_name":""}},
|
"kbase_info": {"vfdbvd":{"1":true,"collection_name":""}},
|
||||||
"redis_url": "localhost:6379",
|
"redis_url": "localhost:6379",
|
||||||
"redis_db": 0
|
"redis_db": 0,
|
||||||
|
"file_convert": false
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue