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