71 lines
2.0 KiB
Lua
71 lines
2.0 KiB
Lua
require("fwutils.webapi")
|
|
local oss = require("aliyun.oss")
|
|
local cos = require("tencent.cos")
|
|
local fw_files = require("fwutils.fwutils.function.files")
|
|
local M = {}
|
|
M.use_type = "cos"
|
|
M.up_file = function(config,remote_dir,local_filepath,desc,conn)
|
|
local result,filepath = nil,nil
|
|
if M.use_type == "oss" then
|
|
result,filepath = oss.upload_file(config,remote_dir,local_filepath,false)
|
|
elseif M.use_type == "cos" then
|
|
result,filepath = cos.upload_file(config,remote_dir,local_filepath,false)
|
|
end
|
|
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 = nil,nil
|
|
if M.use_type == "oss" then
|
|
result,filepath = oss.upload_data(config,remote_dir,data,ext)
|
|
elseif M.use_type == "cos" then
|
|
result,filepath = cos.upload_data(config,remote_dir,data,ext)
|
|
end
|
|
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
|
|
|
|
M.up_file_ex = function(config,remote_dir,local_filepath,desc,conn)
|
|
local result,filepath = nil,nil
|
|
if M.use_type == "oss" then
|
|
fw.throw_string("不支持oss上传")
|
|
elseif M.use_type == "cos" then
|
|
result,filepath = cos.upload_file(config,remote_dir,local_filepath,false)
|
|
end
|
|
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
|
|
return M |