文件需转化返回内容

This commit is contained in:
junleea 2025-04-10 18:54:18 +08:00
parent 61f40aa983
commit 74e3470b88
3 changed files with 21 additions and 6 deletions

View File

@ -88,9 +88,11 @@ def get_file():
def get_file_add_convert():
file_list = get_file()
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:
#文件类型是否允许
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("文件类型允许")
else:
print("文件类型不允许:", file["FileStoreName"])
@ -100,11 +102,11 @@ def get_file_add_convert():
text = fileBase.get_file_content(file["FileStoreName"])
if text is None:
print("文件内容获取失败")
return None
continue
print("文件内容长度:", len(text))
#将文件内容上传
print(create_file_content(file["ID"], text))
break
#break
else:
print("未能获取文件列表")
@ -129,5 +131,5 @@ def get_Kbase_server_id():
print(f"请求失败,状态码: {response.status_code}, 错误信息: {response.text}")
return None
if __name__ == "__main__":
get_file_add_convert()
# if __name__ == "__main__":
# get_file_add_convert()

View File

@ -3,6 +3,7 @@ import time
import json
import fileChroma
import threading
import fileCon
config = {}
stop_event = False
@ -92,6 +93,14 @@ def input_listener(ws):
ws.close()
break
def sfile_content():
#每10秒获取转换一次
while True:
time.sleep(10)
# 文件内容转换
fileCon.get_file_add_convert()
if stop_event:
break
if __name__ == "__main__":
config = readConfig()
@ -109,6 +118,9 @@ if __name__ == "__main__":
input_thread = threading.Thread(target=input_listener, args=(ws,))
input_thread.start()
if config["file_convert"]:
file_thread = threading.Thread(target=sfile_content)
file_thread.start()
# 运行 WebSocket 连接
ws.run_forever()

View File

@ -5,5 +5,6 @@
"ws_retry_delay": 1,
"kbase_info": {"vfdbvd":{"1":true,"collection_name":""}},
"redis_url": "localhost:6379",
"redis_db": 0
"redis_db": 0,
"file_convert": false
}