From 060d5a988de0bf5af14f01f88d21add2c61d579f Mon Sep 17 00:00:00 2001 From: a158 Date: Wed, 14 Jan 2026 22:08:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8A=E4=BC=A0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- target/fwutils/fwutils/controll/upload.lua | 35 +++++++++++++++++ target/fwutils/fwutils/function/files.lua | 44 ++++++++++++++++++++++ target/fwutils/fwutils/function/upload.lua | 38 +++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 target/fwutils/fwutils/controll/upload.lua create mode 100644 target/fwutils/fwutils/function/files.lua create mode 100644 target/fwutils/fwutils/function/upload.lua diff --git a/target/fwutils/fwutils/controll/upload.lua b/target/fwutils/fwutils/controll/upload.lua new file mode 100644 index 0000000..fe16242 --- /dev/null +++ b/target/fwutils/fwutils/controll/upload.lua @@ -0,0 +1,35 @@ + +local fwutils_upload = require("fwutils.fwutils.function.upload") +local fwutils_config = require("fwutils.config") +local request = require("fastweb.request") +local M = {} + + + +M.up = function() + + local result = {} + local multipart = request.multipart() + for i,v in ipairs(multipart) do + local filename = v.param.filename + -- 取扩展名 + local ext = utils.ext(filename) + local temp_filepath = fwutils_config.path.temp_path .."/".. fw.make_software_guid().."."..ext + utils.save_file(temp_filepath,v.param.data) + local line = { + name = v.param.name, + url = temp_filepath + } + request.multipart_content_save(v.id,fw.website_dir().."/"..temp_filepath) + table.insert(result,line) + end + succ(result) +end + +M.exec = function() + exec({ + up = M.up + }) +end + +return M \ No newline at end of file diff --git a/target/fwutils/fwutils/function/files.lua b/target/fwutils/fwutils/function/files.lua new file mode 100644 index 0000000..955106e --- /dev/null +++ b/target/fwutils/fwutils/function/files.lua @@ -0,0 +1,44 @@ +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) + if ppst:update() == 1 then + return true + end + return false +end +M.use = function(id,conn) + local ppst = conn:setsql("UPDATE fw_file SET use_time = NOW() WHERE id = ?") + ppst:set_i32(1,id) + if ppst:update() == 1 then + return true + end + return false +end +M.delete_by_id = function(id,conn) + local ppst = conn:setsql("UPDATE fw_file SET delete_time = NOW() WHERE id = ?") + ppst:set_i32(1,id) + if ppst:update() == 1 then + return true + end + return false +end +M.delete_by_filepath = function(filepath,conn) + local ppst = conn:setsql("UPDATE fw_file SET delete_time = NOW() WHERE role_id = ? AND custom_id = ? AND filepath = ?") + 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_str(3,filepath) + if ppst:update() == 1 then + return true + end + return false +end +return M \ No newline at end of file diff --git a/target/fwutils/fwutils/function/upload.lua b/target/fwutils/fwutils/function/upload.lua new file mode 100644 index 0000000..bc33750 --- /dev/null +++ b/target/fwutils/fwutils/function/upload.lua @@ -0,0 +1,38 @@ +require("fwutils.webapi") +local oss = require("aliyun.oss") +local fw_files = require("fwutils.fwutils.function.files") +local M = {} + +M.up_file = function(config,remote_dir,local_filepath,desc,conn) + local result,filepath = oss.upload_file(config,remote_dir,local_filepath,false) + if result == false then + return false,filepath + end + result = fw_files.add( + utils.file_size(local_filepath), + filepath, + desc, + conn + ) + if result == false then + return false,"添加文件失败" + end + return true,filepath +end +M.up_data = function(config,remote_dir,data,ext,desc,conn) + local result,filepath = oss.upload_data(config,remote_dir,data,ext) + if result == false then + return false,filepath + end + result = fw_files.add( + #data, + filepath, + desc, + conn + ) + if result == false then + return false,"添加文件失败" + end + return true,filepath +end +return M \ No newline at end of file