move upload to a single file
This commit is contained in:
+2
-33
@@ -2,40 +2,9 @@
|
||||
package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
|
||||
local uuid = require "resty.jit-uuid"
|
||||
local cjson = require "cjson"
|
||||
local strip_path = require("strip_path")
|
||||
local Upyun = require('upyun')
|
||||
local upyun_upload = require("upyun_upload")
|
||||
uuid.seed()
|
||||
|
||||
local function upload(filepath)
|
||||
local upyun, err = Upyun:new({
|
||||
user = ngx.var.upyun_operator,
|
||||
passwd = ngx.var.upyun_password,
|
||||
localFilePath = filepath
|
||||
})
|
||||
|
||||
if not upyun then
|
||||
ngx.status = 500
|
||||
ngx.log(ngx.ERR, "failed to initialize upyun: " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
local bucket = ngx.var.upyun_bucket
|
||||
local directory = ngx.var.upyun_directory
|
||||
local filename = strip_path.strip_path(filepath)
|
||||
|
||||
local savePath = bucket .. "/" .. directory .. "/" .. filename
|
||||
|
||||
local info, err = upyun:upload_file(savePath, nil, nil)
|
||||
if not info then
|
||||
ngx.status = 502
|
||||
ngx.log(ngx.ERR, "failed to upload file : " .. err)
|
||||
return
|
||||
else
|
||||
ngx.status = 200
|
||||
ngx.say(ngx.var.upyun_cdn .. directory .. "/" .. filename)
|
||||
end
|
||||
end
|
||||
|
||||
local file_dir = ngx.var.tmp_file_dir
|
||||
ngx.req.read_body()
|
||||
local req_body = cjson.decode(ngx.req.get_body_data())
|
||||
@@ -71,7 +40,7 @@ if result and code == 0 then
|
||||
|
||||
ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
|
||||
|
||||
upload(combined)
|
||||
upyun_upload.upload(combined)
|
||||
|
||||
else
|
||||
ngx.status = 500
|
||||
|
||||
Reference in New Issue
Block a user