Add upyun new2
This commit is contained in:
@@ -574,6 +574,87 @@ function _M.new(self, config)
|
||||
}, mt)
|
||||
end
|
||||
|
||||
function _M.new2(self, config)
|
||||
local user = config.user
|
||||
local passwd = config.passwd
|
||||
local endpoint = config.endpoint and tonumber(config.endpoint) + 1 or 1
|
||||
local author = config.author and lower(config.author) or nil
|
||||
local localFilePath = config.localFilePath or nil -- add config para for upload file directly
|
||||
|
||||
if not user or type(user) ~= "string" or user == "" then
|
||||
return nil, "invalid user"
|
||||
end
|
||||
|
||||
if not passwd or type(passwd) ~= "string" or passwd == "" then
|
||||
return nil, "invalid passwd"
|
||||
end
|
||||
|
||||
if endpoint > 4 then
|
||||
return nil, "invalid endpoint"
|
||||
end
|
||||
|
||||
-- explicit "basic" sets author_mode to Basic
|
||||
local author_mode = "U"
|
||||
if author == "basic" then
|
||||
author_mode = "B"
|
||||
author = "Basic " .. base64(user .. ":" .. passwd)
|
||||
else
|
||||
author = "UpYun " .. user .. ":"
|
||||
end
|
||||
|
||||
---- file to be uploaded is stored in the request body
|
||||
--print("Upyun module new config para local file path : ", localFilePath)
|
||||
--local file = nil
|
||||
--local content = nil
|
||||
--if localFilePath == nil then
|
||||
-- read_body()
|
||||
-- content = get_body_data()
|
||||
-- file = ngx.req.get_body_file()
|
||||
--else
|
||||
-- file = localFilePath;
|
||||
--end
|
||||
--
|
||||
--print("Upyun module new config file : ", file)
|
||||
--if file then
|
||||
-- local f, err = io.open(file, "r")
|
||||
-- if not f then
|
||||
-- return nil, err
|
||||
-- end
|
||||
--
|
||||
-- content = f:read("*a")
|
||||
-- f:close()
|
||||
--end
|
||||
|
||||
--if not content then
|
||||
-- return nil, "request body is expected"
|
||||
--end
|
||||
|
||||
--TODO ngx.updatetime?
|
||||
local date = http_time(time_sec())
|
||||
if not date then
|
||||
return nil, "failed to get current time"
|
||||
end
|
||||
|
||||
local sock = tcp()
|
||||
if not sock then
|
||||
return nil, "failed to create a TCP socket"
|
||||
end
|
||||
|
||||
return setmetatable({
|
||||
sock = sock,
|
||||
user = user,
|
||||
passwd = passwd,
|
||||
author_mode = author_mode,
|
||||
headers = {
|
||||
Authorization = author,
|
||||
Host = host_list[endpoint],
|
||||
Date = date,
|
||||
["Content-Length"] = "0"
|
||||
},
|
||||
body = { content = content },
|
||||
}, mt)
|
||||
end
|
||||
|
||||
function _M.upload_file(self, path, gmkerl, option)
|
||||
-- return info, err
|
||||
local headers = self.headers
|
||||
|
||||
Reference in New Issue
Block a user