Files
resty_functions/scripts/upyun_remove.lua
T

33 lines
1.1 KiB
Lua
Raw Normal View History

2024-01-03 22:14:25 +08:00
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
local http = require "resty.http"
local verify = require('lib.jwt_verify')
local cjson = require "cjson"
local httpc = http:new()
local authHeader = ngx.req.get_headers().Authorization
local sudoerToken = ngx.req.get_headers().HtySudoerToken
ngx.req.read_body()
local request_body = ngx.req.get_body_data()
local request_body_json = cjson.decode(request_body)
local upyun_remove_url = request_body_json["request_url"]
ngx.log(ngx.INFO, 'upyun_remove_url -> ', upyun_remove_url)
verify(httpc, authHeader, sudoerToken)
ngx.log(ngx.INFO, 'REMOVE UPYUN FILE -> start')
local upyun_upload = require("lib.upyun_remove")
ngx.log(ngx.INFO, 'REMOVE UPYUN FILE -> upyun_remove loaded')
local file_to_remove = string.match(upyun_remove_url, ".*/(.*)")
ngx.log(ngx.INFO, 'REMOVE UPYUN FILE -> file to remove -> ', file_to_remove)
--local file_dir = ngx.var.tmp_file_dir
--local fullpath = file_dir .. "/" .. file_to_remove
--
--ngx.log(ngx.INFO, 'REMOVE UPYUN FILE -> fullpath -> ', fullpath)
--
--upyun_upload.remove(fullpath, nil, 0)
upyun_upload.remove(file_to_remove, file_to_remove, 0)