diff --git a/conf/local_macos/admin.conf b/conf/local_macos/admin.conf index 1ce27ed..6e49160 100644 --- a/conf/local_macos/admin.conf +++ b/conf/local_macos/admin.conf @@ -2,13 +2,13 @@ server { # https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx# # server_name $servername; server_name "admin.localhost"; - listen 80; + listen 8088; client_max_body_size 10M; - set $tmp_file_dir "/usr/local/file_upload/"; # 文件存储路径 + set $tmp_file_dir "/usr/local/file_upload"; # 文件存储路径 set $task_server "http://127.0.0.1:8080"; # task server host set $htyuc "http://127.0.0.1:3000"; #htyuc host - set $resty_loc "/usr/local/opt/openresty/"; + set $resty_loc "/usr/local/opt/openresty"; set $convert "/usr/local/bin/convert"; set $upyun_operator "moicen"; set $upyun_password "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN"; @@ -40,23 +40,23 @@ server { #Upload image files location /api/ngx/image/upload { - content_by_lua_file $resty_loc/resty_funcs/upload.lua; + content_by_lua_file $resty_loc/nginx/scripts/upload.lua; } #Combine image files location /api/ngx/image/combine { - content_by_lua_file $resty_loc/resty_funcs/combine.lua; + content_by_lua_file $resty_loc/nginx/scripts/combine.lua; } #Audio file download location /api/ngx/audio/upload { - content_by_lua_file $resty_loc/resty_funcs/upload_audio.lua; + content_by_lua_file $resty_loc/nginx/scripts/upload_audio.lua; } #Audio file convert location /api/ngx/audio/convert { - content_by_lua_file $resty_loc/resty_funcs/convert_audio.lua; + content_by_lua_file $resty_loc/nginx/scripts/convert_audio.lua; } location /api/ngx/convert/test { - content_by_lua_file $resty_loc/resty_funcs/test.lua; + content_by_lua_file $resty_loc/nginx/scripts/test.lua; } location /api/v1/ws/ { diff --git a/conf/local_macos/music-room.conf b/conf/local_macos/music-room.conf index 924fc2c..8d000f0 100644 --- a/conf/local_macos/music-room.conf +++ b/conf/local_macos/music-room.conf @@ -3,7 +3,7 @@ server { # https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx# # server_name $servername; server_name "music-room.localhost"; - listen 80; + listen 8088; client_max_body_size 10M; set $resty_loc "/usr/local/opt/openresty"; diff --git a/conf/local_macos/ts.conf b/conf/local_macos/ts.conf index a07f958..1a4ee66 100644 --- a/conf/local_macos/ts.conf +++ b/conf/local_macos/ts.conf @@ -2,7 +2,7 @@ server { # https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx# # server_name $servername; server_name "ts.localhost"; - listen 80; + listen 8088; client_max_body_size 10M; set $task_server "http://127.0.0.1:8080"; # task server host diff --git a/cp_scripts_local_macos.sh b/cp_scripts_local_macos.sh index 0c962fb..fac8755 100755 --- a/cp_scripts_local_macos.sh +++ b/cp_scripts_local_macos.sh @@ -1,8 +1,8 @@ #!/bin/sh set -x -mkdir -p /usr/local/etc/openresty/conf.d -cp conf/local_macos/*.conf /usr/local/etc/openresty/conf.d/ +openresty_sub_config_dir=/usr/local/etc/openresty/conf.d -cp scripts/*.lua /usr/local/opt/openresty/resty_funcs/ +mkdir -p $openresty_sub_config_dir +cp conf/local_macos/*.conf $openresty_sub_config_dir diff --git a/scripts/combine.lua b/scripts/combine.lua index 3f29af1..9a0b925 100644 --- a/scripts/combine.lua +++ b/scripts/combine.lua @@ -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*") diff --git a/scripts/convert_audio.lua b/scripts/convert_audio.lua index bfa09ef..7062910 100644 --- a/scripts/convert_audio.lua +++ b/scripts/convert_audio.lua @@ -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" diff --git a/scripts/test_upyun_upload.lua b/scripts/test_upyun_upload.lua index abff93d..2f4957d 100644 --- a/scripts/test_upyun_upload.lua +++ b/scripts/test_upyun_upload.lua @@ -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"