modify local dev config & make openresty directy upload combine file to upyun

This commit is contained in:
liyong
2022-02-07 19:04:21 +08:00
committed by XiaoLi
parent 155bd693b2
commit 9355277bc0
7 changed files with 55 additions and 20 deletions
+40 -5
View File
@@ -1,7 +1,41 @@
-- 指定模块引用目录,否则无法加载同目录下的其他文件
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')
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())
@@ -32,12 +66,13 @@ local cmd = convert .. " -append " .. table.concat(origin, " ") .. " " .. combin
ngx.log(ngx.INFO, 'CMD -> ', cmd)
local result, _, code = os.execute(cmd)
if result and code == 0 then
local file = io.open(combined)
local content = file:read("*all")
file:close()
os.remove(combined)
ngx.log(ngx.INFO, "IMAGE COMBINED -> ", combined)
ngx.say(content)
ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
upload(combined)
else
ngx.status = 500
ngx.log(ngx.ERR, "IMAGE COMBINE *FAILED*")
+1 -1
View File
@@ -1,5 +1,5 @@
-- 指定模块引用目录,否则无法加载同目录下的其他文件
package.path = package.path .. ';/usr/local/openresty/nginx/scripts/?.lua';
package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
local cjson = require "cjson"
local uuid = require "resty.jit-uuid"
local http = require "resty.http"
+1 -1
View File
@@ -1,4 +1,4 @@
package.path = package.path .. ';/usr/local/openresty/nginx/scripts/?.lua';
package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
local yun = require("upyun")
local cjson = require "cjson"