refactor lib
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||
|
||||
local cjson = require "cjson"
|
||||
local pl = require "pl.pretty"
|
||||
local http = require 'resty.http'
|
||||
local uuid = require "resty.jit-uuid"
|
||||
local upyun_upload = require("lib.upyun_upload")
|
||||
@@ -17,7 +18,7 @@ local function convert()
|
||||
local req_body = cjson.decode(ngx.req.get_body_data())
|
||||
ngx.log(ngx.INFO, 'REQ_BODY -> ', ngx.req.get_body_data())
|
||||
|
||||
local input_audio_file = get_wx_media(httpc, req_body["payload"]["media_id"]);
|
||||
local input_audio_file = get_wx_media(httpc, req_body["payload"]["media_id"], cjson, pl);
|
||||
local converted_audio_file = file_dir .. "/" .. uuid.generate_v4() .. ".mp3";
|
||||
|
||||
ngx.log(ngx.INFO, "Input audio file -> ", input_audio_file);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
local cjson = require "cjson"
|
||||
--local cjson = require "cjson"
|
||||
|
||||
|
||||
local TaskTypes = {
|
||||
NOOP = 'NOOP',
|
||||
UPLOAD_PICTURE = 'UPLOAD_PICTURE'
|
||||
}
|
||||
--
|
||||
--local TaskTypes = {
|
||||
-- NOOP = 'NOOP',
|
||||
-- UPLOAD_PICTURE = 'UPLOAD_PICTURE'
|
||||
--}
|
||||
|
||||
local task_server = ngx.var.task_server
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local cjson = require "cjson"
|
||||
--local cjson = require "cjson"
|
||||
--# https://github.com/SkyLothar/lua-resty-jwt
|
||||
--$ opm get SkyLothar/lua-resty-jwt
|
||||
local jwt = require "resty.jwt"
|
||||
--local jwt = require "resty.jwt"
|
||||
|
||||
local function cleanupString(str, remove)
|
||||
local lcSubStrTab = {}
|
||||
@@ -63,7 +63,7 @@ local function verifyJwtToken(httpc, token)
|
||||
|
||||
end
|
||||
|
||||
local function decodeJwtClaim(jwtClaim)
|
||||
local function decodeJwtClaim(jwtClaim, cjson, jwt)
|
||||
local jwtKey = "0xCAFEBABE0xCAFEBABE0xCAFEBABE0xCAFEBABE0xCAFEBABE0xCAFEBABE"
|
||||
local jwtObj = jwt:verify(jwtKey, jwtClaim)
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
local cjson = require "cjson"
|
||||
local pl = require "pl.pretty"
|
||||
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
||||
local htyhostHeader = ngx.req.get_headers().HtyHost
|
||||
--local cjson = require "cjson"
|
||||
--local pl = require "pl.pretty"
|
||||
|
||||
local function get_access_token(httpc)
|
||||
|
||||
|
||||
local function get_access_token(httpc, cjson, pl)
|
||||
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
||||
local htyHostHeader = ngx.req.get_headers().HtyHost
|
||||
local htyuc = ngx.var.htyuc
|
||||
local host = ngx.var.host
|
||||
local wx_domain = ngx.var.wx_domain
|
||||
|
||||
ngx.log(ngx.INFO, "HTYUC -> ", htyuc)
|
||||
ngx.log(ngx.INFO, "Host -> ", host)
|
||||
ngx.log(ngx.INFO, 'HtyHostHeader -> ', htyhostHeader)
|
||||
ngx.log(ngx.INFO, 'HtyHostHeader -> ', htyHostHeader)
|
||||
ngx.log(ngx.INFO, 'HtySudoerToken -> ', sudoerToken)
|
||||
|
||||
local remote_url = string.format("%s/api/v1/uc/wx_get_access_token", htyuc)
|
||||
@@ -54,8 +56,8 @@ local function get_access_token(httpc)
|
||||
|
||||
end
|
||||
|
||||
local function get_wx_media(httpc, media_id)
|
||||
local access_token = get_access_token(httpc)
|
||||
local function get_wx_media(httpc, media_id, cjson, pl)
|
||||
local access_token = get_access_token(httpc, cjson, pl)
|
||||
print("access token: " .. access_token)
|
||||
local wx_media_url = string.format("https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s", access_token, media_id)
|
||||
print("wx_media_url: " .. wx_media_url)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||
local http = require "resty.http"
|
||||
local cjson = require "cjson"
|
||||
local pl = require "pl.pretty"
|
||||
local uuid = require "resty.jit-uuid"
|
||||
local upyun_upload = require("lib.upyun_upload")
|
||||
local get_wx_media = require("lib.wx_download")
|
||||
@@ -20,7 +21,7 @@ local function run()
|
||||
local req_body = cjson.decode(ngx.req.get_body_data())
|
||||
ngx.log(ngx.INFO, 'REQ_BODY -> ', ngx.req.get_body_data())
|
||||
|
||||
local downloaded_file = get_wx_media(httpc, req_body["media_id"]);
|
||||
local downloaded_file = get_wx_media(httpc, req_body["media_id"], cjson, pl);
|
||||
|
||||
upyun_upload.upload(downloaded_file, uuid.generate_v4() .. ".jpg")
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||
|
||||
local cjson = require "cjson"
|
||||
local http = require 'resty.http'
|
||||
local pl = require "pl.pretty"
|
||||
local get_wx_media = require("wx_download")
|
||||
local create_task = require("lib.create_task")
|
||||
local verify = require('lib.jwt_verify')
|
||||
@@ -24,7 +25,7 @@ local function read_wx_file()
|
||||
local files = {}
|
||||
for i = 1, #req_body["media_ids"] do
|
||||
print("media_id -> ", i, req_body["media_ids"][i])
|
||||
local _, filename = get_wx_media(httpc, req_body["media_ids"][i])
|
||||
local _, filename = get_wx_media(httpc, req_body["media_ids"][i], cjson, pl)
|
||||
table.insert(files, filename);
|
||||
end
|
||||
local task_text = cjson.encode({ task_type = TaskTypes.UPLOAD_PICTURE, payload = { images = files } })
|
||||
|
||||
Reference in New Issue
Block a user