From 9dd5a02c887b915619ce3b13aca2ae809f953496 Mon Sep 17 00:00:00 2001 From: NH <1585346868@qq.com> Date: Sat, 21 Feb 2026 19:26:14 +0800 Subject: [PATCH] 1 --- target/aliyun/ai.lua | 26 ++++++++++++++++ target/aliyun/oss.lua | 8 ++++- target/deepseek/ai.lua | 36 +++++++++++++++++++++++ target/fwutils/fwutils/function/files.lua | 32 +++++++++++++++----- target/httpclient.lua | 7 +++-- 5 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 target/deepseek/ai.lua diff --git a/target/aliyun/ai.lua b/target/aliyun/ai.lua index e5a0027..7b8c2ef 100644 --- a/target/aliyun/ai.lua +++ b/target/aliyun/ai.lua @@ -30,6 +30,32 @@ M.ask = function(key,content,model) return false, "请求失败,错误描述:" .. table.concat(response_body) end end +M.ask_local = function(url,content,model) + -- 构造 JSON 格式的请求数据 + local payload = { + model = model, + messages = content, + stream = false + } + local response_body = {} + + local res, code, response_headers, status = http.request{ + url = url, + method = "POST", + headers = { + ["Content-Type"] = "application/json", + }, + source = ltn12.source.string(cjson.encode(payload)), + sink = ltn12.sink.table(response_body) + } + if code == 200 then + print(table.concat(response_body)) + local data = cjson.decode(table.concat(response_body)) + return true,{content = data.message.content} + else + return false, "请求失败,错误描述:" .. table.concat(response_body) + end +end return M diff --git a/target/aliyun/oss.lua b/target/aliyun/oss.lua index 84a65e3..adf7271 100644 --- a/target/aliyun/oss.lua +++ b/target/aliyun/oss.lua @@ -38,7 +38,13 @@ M.ext_dirpath = { "xls", "xlsx", "ppt", - "pptx" + "pptx", + "txt", + "json", + "xml", + "html", + "css", + "js", } } diff --git a/target/deepseek/ai.lua b/target/deepseek/ai.lua new file mode 100644 index 0000000..98baccb --- /dev/null +++ b/target/deepseek/ai.lua @@ -0,0 +1,36 @@ +local http = require("socket.http") +local ltn12 = require("ltn12") +local cjson = require("cjson") + +local M = {} +local url = "https://api.deepseek.com/chat/completions" + +M.ask = function(key,content,model) + -- 构造 JSON 格式的请求数据 + local payload = { + model = model, + messages = content + } + local response_body = {} + + local res, code, response_headers, status = http.request{ + url = url, + method = "POST", + headers = { + ["Authorization"] = "Bearer " .. key, + ["Content-Type"] = "application/json", + }, + source = ltn12.source.string(cjson.encode(payload)), + sink = ltn12.sink.table(response_body) + } + if code == 200 then + local data = cjson.decode(table.concat(response_body)) + return true,{content = data.choices[1].message.content} + else + return false, "请求失败,错误描述:" .. table.concat(response_body) + end +end + +return M + + diff --git a/target/fwutils/fwutils/function/files.lua b/target/fwutils/fwutils/function/files.lua index 955106e..a7c4c0b 100644 --- a/target/fwutils/fwutils/function/files.lua +++ b/target/fwutils/fwutils/function/files.lua @@ -2,13 +2,31 @@ require("fwutils.webapi") local M = {} M.add = function(file_size,filepath,desc,conn) - local ppst = conn:setsql("INSERT INTO fw_file (role_id,custom_id,file_size,filepath,`desc`) VALUES (?,?,?,?,?)") - local user_data = cjson.decode(request.get("user_data")) - ppst:set_i32(1,user_data.role_id) - ppst:set_i32(2,user_data.id) - ppst:set_i64(3,file_size) - ppst:set_str(4,filepath) - ppst:set_str(5,desc) + local sql = "" + + local user_data = request.get("user_data") + if user_data ~= nil and user_data ~= "" then + sql = "INSERT INTO fw_file (role_id,custom_id,file_size,filepath,`desc`) VALUES (?,?,?,?,?)" + user_data = cjson.decode(user_data) + else + user_data = nil + sql = "INSERT INTO fw_file (file_size,filepath,`desc`) VALUES (?,?,?)" + end + + local ppst = conn:setsql(sql) + if user_data ~= nil then + ppst:set_i32(1,user_data.role_id) + ppst:set_i32(2,user_data.id) + ppst:set_i64(3,file_size) + ppst:set_str(4,filepath) + ppst:set_str(5,desc) + else + ppst:set_i64(1,file_size) + ppst:set_str(2,filepath) + ppst:set_str(3,desc) + end + + if ppst:update() == 1 then return true end diff --git a/target/httpclient.lua b/target/httpclient.lua index fb8b7b0..6b523dd 100644 --- a/target/httpclient.lua +++ b/target/httpclient.lua @@ -1,11 +1,12 @@ local http = require("socket.http") local ltn12 = require("ltn12") -local cjson = require("cjson") -require("app.app") + local M = {} +M.timeout = 60*5 M.get = function(url,headers) + http.TIMEOUT = M.timeout local response_body = {} local res, status_code, response_headers, status_text = http.request{ url = url, @@ -24,6 +25,7 @@ M.get = function(url,headers) end M.post = function(url,headers,body) + http.TIMEOUT = M.timeout local response_body = {} headers["Content-Length"] = tostring(#body) local res, status_code, response_headers, status_text = http.request{ @@ -42,6 +44,7 @@ M.post = function(url,headers,body) return true,table.concat(response_body) end M.delete = function(url,headers) + http.TIMEOUT = M.timeout local response_body = {} local res, status_code, response_headers, status_text = http.request{ url = url,