more log + increase upload timeout

This commit is contained in:
2022-03-21 22:15:31 +08:00
parent 9aea9bcba2
commit 59ed6c035b
+26 -66
View File
@@ -35,13 +35,13 @@ local host_list = {
} }
local gmkerl_format = { local gmkerl_format = {
type = { type = {
type = { type = {
"required", "required",
["fix_width"]="allowed", ["fix_height"]="allowed", ["fix_width"] = "allowed", ["fix_height"] = "allowed",
["fix_width_or_height"]="allowed", ["fix_width_or_height"] = "allowed",
["fix_both"]="allowed", ["fix_max"]="allowed", ["fix_both"] = "allowed", ["fix_max"] = "allowed",
["fix_min"]="allowed", ["fix_scale"]="allowed" ["fix_min"] = "allowed", ["fix_scale"] = "allowed"
}, },
value = { value = {
"required", "required",
@@ -53,11 +53,11 @@ local gmkerl_format = {
}, },
unsharp = { unsharp = {
"optional", "optional",
["true"]="allowed", ["false"]="allowed" ["true"] = "allowed", ["false"] = "allowed"
}, },
["exif-switch"] = { ["exif-switch"] = {
"optional", "optional",
["true"]="allowed", ["false"]="allowed" ["true"] = "allowed", ["false"] = "allowed"
} }
}, },
thumbnail = { thumbnail = {
@@ -67,30 +67,28 @@ local gmkerl_format = {
}, },
["exif-switch"] = { ["exif-switch"] = {
"optional", "optional",
["true"]="allowed", ["false"]="allowed" ["true"] = "allowed", ["false"] = "allowed"
} }
}, },
rotate = { rotate = {
rotate = { rotate = {
"required", "required",
["auto"]="allowed", ["90"]="allowed", ["auto"] = "allowed", ["90"] = "allowed",
["180"]="allowed", ["270"]="allowed" ["180"] = "allowed", ["270"] = "allowed"
} }
}, },
crop = { crop = {
crop = { crop = {
"required", "required",
"[0-9]+,[0-9]+,[1-9][0-9]*,[1-9][0-9]*" "[0-9]+,[0-9]+,[1-9][0-9]*,[1-9][0-9]*"
}, },
["exif-switch"] = { ["exif-switch"] = {
"optional", "optional",
["true"]="allowed", ["false"]="allowed" ["true"] = "allowed", ["false"] = "allowed"
} }
} }
} }
local function _rev_headers(sock) local function _rev_headers(sock)
-- return headers, err -- return headers, err
local headers = {} local headers = {}
@@ -116,8 +114,6 @@ local function _rev_headers(sock)
return headers return headers
end end
local function _receive_length(sock, length) local function _receive_length(sock, length)
-- return chunk, err -- return chunk, err
local chunk, err = sock:receive(length) local chunk, err = sock:receive(length)
@@ -128,8 +124,6 @@ local function _receive_length(sock, length)
return chunk return chunk
end end
local function _receive_chunked(sock, maxsize) local function _receive_chunked(sock, maxsize)
-- return chunks, err -- return chunks, err
local chunks = {} local chunks = {}
@@ -171,8 +165,6 @@ local function _receive_chunked(sock, maxsize)
return concat(chunks) return concat(chunks)
end end
local function _receive(sock) local function _receive(sock)
-- return {}, err -- return {}, err
local line, err = sock:receive() local line, err = sock:receive()
@@ -230,8 +222,6 @@ local function _receive(sock)
return { status = status, headers = headers, body = body } return { status = status, headers = headers, body = body }
end end
local function _req_header(method, path, headers, extra) local function _req_header(method, path, headers, extra)
-- return req -- return req
local req = { local req = {
@@ -263,33 +253,34 @@ local function _req_header(method, path, headers, extra)
return concat(req) return concat(req)
end end
local function _request(sock, method, path, headers, body, extra) local function _request(sock, method, path, headers, body, extra)
-- return {}, err -- return {}, err
local host = headers.Host local host = headers.Host
if not sock then if not sock then
ngx.log(ngx.ERR, "sock not initialized yet")
return nil, "not initialized yet" return nil, "not initialized yet"
else else
print("Upyun module request connect host : ", host) ngx.log(ngx.INFO, "Upyun module request connect host : ", host)
end end
sock:settimeout(5000) sock:settimeout(20000)
local ok, err = sock:connect(host, 80) local ok, err = sock:connect(host, 80)
if not ok then if not ok then
ngx.log(ngx.ERR, "sock:connect ERROR -> ", err)
return nil, err return nil, err
end end
-- Build and send request header -- Build and send request header
print("Debug upyun module request header method : ", method) ngx.log(ngx.INFO, "Debug upyun module request header method : ", method)
print("Debug upyun module request header path : ", path) ngx.log(ngx.INFO, "Debug upyun module request header path : ", path)
--print("Debug upyun module request header headers : ", headers) --print("Debug upyun module request header headers : ", headers)
--print("Debug upyun module request header extra : ", extra) --print("Debug upyun module request header extra : ", extra)
local header = _req_header(method, path, headers, extra) local header = _req_header(method, path, headers, extra)
local bytes, err = sock:send(header) local bytes, err = sock:send(header)
if not bytes then if not bytes then
ngx.log(ngx.ERR, "sock:send ERR -> ", err)
return nil, err return nil, err
end end
@@ -297,6 +288,7 @@ local function _request(sock, method, path, headers, body, extra)
if body and body.content then if body and body.content then
local bytes, err = sock:send(body.content) local bytes, err = sock:send(body.content)
if not bytes then if not bytes then
ngx.log(ngx.ERR, "sock:send ERR -> ", err)
return nil, err return nil, err
end end
end end
@@ -304,8 +296,6 @@ local function _request(sock, method, path, headers, body, extra)
return _receive(sock) return _receive(sock)
end end
local function _upyun_request(self, method, path, headers, body, extra) local function _upyun_request(self, method, path, headers, body, extra)
local sock = self.sock local sock = self.sock
local author_mode = self.author_mode local author_mode = self.author_mode
@@ -323,15 +313,11 @@ local function _upyun_request(self, method, path, headers, body, extra)
return _request(sock, method, path, headers, body, extra) return _request(sock, method, path, headers, body, extra)
end end
local function _is_dir(path) local function _is_dir(path)
-- return true or false -- return true or false
return str_sub(path, -1, -1) == "/" return str_sub(path, -1, -1) == "/"
end end
local function _parse_gmkerl(gmkerl, extra) local function _parse_gmkerl(gmkerl, extra)
-- return ok, err -- return ok, err
local expect_format = true local expect_format = true
@@ -369,7 +355,7 @@ local function _parse_gmkerl(gmkerl, extra)
end end
-- regex is stored in the v[2] -- regex is stored in the v[2]
local m ,err = ngx_match(value, v[2]) local m, err = ngx_match(value, v[2])
if err then if err then
return nil, "error occurs when matching " return nil, "error occurs when matching "
.. value .. " with " .. v[2] .. value .. " with " .. v[2]
@@ -390,8 +376,6 @@ local function _parse_gmkerl(gmkerl, extra)
return true return true
end end
local function _format_path(path, legal_path) local function _format_path(path, legal_path)
-- return path, err -- return path, err
if not path or type(path) ~= "string" or path == "" then if not path or type(path) ~= "string" or path == "" then
@@ -402,7 +386,7 @@ local function _format_path(path, legal_path)
return nil, path .. " is not a legal directory name" return nil, path .. " is not a legal directory name"
end end
if legal_path == "file" and _is_dir(path)then if legal_path == "file" and _is_dir(path) then
return nil, path .. " is not a legal file name" return nil, path .. " is not a legal file name"
end end
@@ -414,8 +398,6 @@ local function _format_path(path, legal_path)
return path return path
end end
local function _parse_upyun_option(option, extra, content) local function _parse_upyun_option(option, extra, content)
-- return modified extra -- return modified extra
local mkdir = tostring(option.mkdir) local mkdir = tostring(option.mkdir)
@@ -440,8 +422,6 @@ local function _parse_upyun_option(option, extra, content)
end end
end end
local function _parse_upyun_headers(headers, regex) local function _parse_upyun_headers(headers, regex)
-- return info, err -- return info, err
if not headers or type(headers) ~= "table" then if not headers or type(headers) ~= "table" then
@@ -464,8 +444,6 @@ local function _parse_upyun_headers(headers, regex)
return info return info
end end
local function _parse_upyun_body(body) local function _parse_upyun_body(body)
-- return info, err -- return info, err
if not body or type(body) ~= "string" then if not body or type(body) ~= "string" then
@@ -481,7 +459,7 @@ local function _parse_upyun_body(body)
local j = 1 local j = 1
local file local file
local info = {} local info = {}
local key = {"name", "type", "size", "lastmodified"} local key = { "name", "type", "size", "lastmodified" }
while true do while true do
local m, err = iterator() local m, err = iterator()
if err then if err then
@@ -513,8 +491,6 @@ local function _parse_upyun_body(body)
return info return info
end end
function _M.new(self, config) function _M.new(self, config)
local user = config.user local user = config.user
local passwd = config.passwd local passwd = config.passwd
@@ -581,7 +557,7 @@ function _M.new(self, config)
return nil, "failed to create a TCP socket" return nil, "failed to create a TCP socket"
end end
return setmetatable ({ return setmetatable({
sock = sock, sock = sock,
user = user, user = user,
passwd = passwd, passwd = passwd,
@@ -592,12 +568,10 @@ function _M.new(self, config)
Date = date, Date = date,
["Content-Length"] = "0" ["Content-Length"] = "0"
}, },
body = {content = content}, body = { content = content },
}, mt) }, mt)
end end
function _M.upload_file(self, path, gmkerl, option) function _M.upload_file(self, path, gmkerl, option)
-- return info, err -- return info, err
local headers = self.headers local headers = self.headers
@@ -654,8 +628,6 @@ function _M.upload_file(self, path, gmkerl, option)
return ret return ret
end end
function _M.download_file(self, path) function _M.download_file(self, path)
-- return file, err -- return file, err
local headers = self.headers local headers = self.headers
@@ -678,8 +650,6 @@ function _M.download_file(self, path)
return ret.body return ret.body
end end
function _M.get_fileinfo(self, path) function _M.get_fileinfo(self, path)
-- return info, err -- return info, err
local headers = self.headers local headers = self.headers
@@ -707,8 +677,6 @@ function _M.get_fileinfo(self, path)
return ret return ret
end end
function _M.remove_file(self, path) function _M.remove_file(self, path)
-- return ok, err -- return ok, err
local headers = self.headers local headers = self.headers
@@ -731,8 +699,6 @@ function _M.remove_file(self, path)
return true return true
end end
function _M.make_dir(self, path, option) function _M.make_dir(self, path, option)
-- return ok, err -- return ok, err
local headers = self.headers local headers = self.headers
@@ -760,8 +726,6 @@ function _M.make_dir(self, path, option)
return true return true
end end
function _M.read_dir(self, path) function _M.read_dir(self, path)
-- return items, err -- return items, err
local headers = self.headers local headers = self.headers
@@ -789,8 +753,6 @@ function _M.read_dir(self, path)
return ret return ret
end end
function _M.get_usage(self, path) function _M.get_usage(self, path)
-- return usage, err -- return usage, err
local headers = self.headers local headers = self.headers
@@ -815,6 +777,4 @@ function _M.get_usage(self, path)
return ret.body return ret.body
end end
return _M return _M