mirror of
https://github.com/lxsang/antd-lua-plugin
synced 2025-07-23 09:20:05 +02:00
use new antd api
This commit is contained in:
@ -32,7 +32,7 @@ function std.mimeOf(name)
|
||||
end
|
||||
end
|
||||
|
||||
function std.isBinary(name)
|
||||
--[[ function std.isBinary(name)
|
||||
local mime = std.mime(name)
|
||||
if mime ~= "application/octet-stream" then
|
||||
return std.is_bin(name)
|
||||
@ -40,7 +40,7 @@ function std.isBinary(name)
|
||||
local xmime,bin = std.extra_mime(name)
|
||||
return bin
|
||||
end
|
||||
end
|
||||
end ]]
|
||||
|
||||
function std.sendFile(m)
|
||||
local mime = std.mimeOf(m)
|
||||
@ -48,28 +48,24 @@ function std.sendFile(m)
|
||||
local len = tostring(math.floor(finfo.size))
|
||||
local len1 = tostring(math.floor(finfo.size - 1))
|
||||
if mime == "audio/mpeg" then
|
||||
std.status(200, "OK")
|
||||
std.custom_header("Pragma", "public")
|
||||
std.custom_header("Expires", "0")
|
||||
std.custom_header("Content-Type", mime)
|
||||
std.custom_header("Content-Length", len)
|
||||
std.custom_header("Content-Disposition", "inline; filename=" .. std.basename(m))
|
||||
std.custom_header("Content-Range:", "bytes 0-" .. len1 .. "/" .. len)
|
||||
std.custom_header("Accept-Ranges", "bytes")
|
||||
std.custom_header("X-Pad", "avoid browser bug")
|
||||
std.custom_header("Content-Transfer-Encoding", "binary")
|
||||
std.custom_header("Cache-Control", "no-cache, no-store")
|
||||
std.custom_header("Connection", "Keep-Alive")
|
||||
std.custom_header("Etag", "a404b-c3f-47c3a14937c80")
|
||||
std.status(200)
|
||||
std.header("Pragma", "public")
|
||||
std.header("Expires", "0")
|
||||
std.header("Content-Type", mime)
|
||||
std.header("Content-Length", len)
|
||||
std.header("Content-Disposition", "inline; filename=" .. std.basename(m))
|
||||
std.header("Content-Range:", "bytes 0-" .. len1 .. "/" .. len)
|
||||
std.header("Accept-Ranges", "bytes")
|
||||
std.header("X-Pad", "avoid browser bug")
|
||||
std.header("Content-Transfer-Encoding", "binary")
|
||||
std.header("Cache-Control", "no-cache, no-store")
|
||||
std.header("Connection", "Keep-Alive")
|
||||
std.header("Etag", "a404b-c3f-47c3a14937c80")
|
||||
else
|
||||
std.status(200, "OK")
|
||||
std.custom_header("Content-Type", mime)
|
||||
std.custom_header("Content-Length", len)
|
||||
std.status(200)
|
||||
std.header("Content-Type", mime)
|
||||
std.header("Content-Length", len)
|
||||
end
|
||||
std.header_flush()
|
||||
if std.is_bin(m) then
|
||||
std.fb(m)
|
||||
else
|
||||
std.f(m)
|
||||
end
|
||||
std.f(m)
|
||||
end
|
||||
|
122
APIs/std.lua
122
APIs/std.lua
@ -1,73 +1,103 @@
|
||||
std = modules.std()
|
||||
bytes = modules.bytes()
|
||||
array = modules.array()
|
||||
function std.html()
|
||||
std._html(HTTP_REQUEST.id)
|
||||
end
|
||||
function std.text()
|
||||
std._text(HTTP_REQUEST.id)
|
||||
end
|
||||
function std.status(code, msg)
|
||||
std._status(HTTP_REQUEST.id, code, msg)
|
||||
RESPONSE_HEADER = {
|
||||
status = 200,
|
||||
header = {},
|
||||
cookie = {},
|
||||
sent = false
|
||||
}
|
||||
|
||||
function std.status(code)
|
||||
RESPONSE_HEADER.status=code
|
||||
end
|
||||
function std.custom_header(k,v)
|
||||
--print(k..":"..v)
|
||||
std.t(k..": "..v)
|
||||
std.header(k,v)
|
||||
end
|
||||
function std.header_flush()
|
||||
std.t("")
|
||||
std._send_header(HTTP_REQUEST.id,RESPONSE_HEADER.status, RESPONSE_HEADER.header, RESPONSE_HEADER.cookie)
|
||||
RESPONSE_HEADER.sent = true
|
||||
end
|
||||
--_redirect
|
||||
function std.redirect(s)
|
||||
std._redirect(HTTP_REQUEST.id,s)
|
||||
|
||||
function std.header(k,v)
|
||||
RESPONSE_HEADER.header[k] = v
|
||||
end
|
||||
function std.json()
|
||||
std._json(HTTP_REQUEST.id)
|
||||
|
||||
function std.cjson(ck)
|
||||
for k,v in pairs(ck) do
|
||||
std.setCookie(k.."="..v.."; Path=/")
|
||||
end
|
||||
std.header("Content-Type","application/json")
|
||||
std.header_flush()
|
||||
end
|
||||
function std.jpeg()
|
||||
std._jpeg(HTTP_REQUEST.id)
|
||||
end
|
||||
function std.header(s)
|
||||
std._header(HTTP_REQUEST.id,s)
|
||||
end
|
||||
function std.octstream(s)
|
||||
std._octstream(HTTP_REQUEST.id,s)
|
||||
end
|
||||
function std.textstream()
|
||||
std._textstream(HTTP_REQUEST.id)
|
||||
end
|
||||
function std.ti(v)
|
||||
std._ti(HTTP_REQUEST.id,v)
|
||||
function std.chtml(ck)
|
||||
for k,v in pairs(ck) do
|
||||
std.setCookie(k.."="..v.."; Path=/")
|
||||
end
|
||||
std.header("Content-Type","text/html")
|
||||
std.header_flush()
|
||||
end
|
||||
function std.t(s)
|
||||
if RESPONSE_HEADER.sent == false then
|
||||
std.header_flush()
|
||||
end
|
||||
std._t(HTTP_REQUEST.id,s)
|
||||
end
|
||||
function std.b(s)
|
||||
if RESPONSE_HEADER.sent == false then
|
||||
std.header_flush()
|
||||
end
|
||||
std._b(HTTP_REQUEST.id,s)
|
||||
end
|
||||
function std.f(v)
|
||||
std._f(HTTP_REQUEST.id,v)
|
||||
end
|
||||
function std.fb(v)
|
||||
std._f(HTTP_REQUEST.id,v)
|
||||
|
||||
function std.setCookie(v)
|
||||
RESPONSE_HEADER.cookie[#RESPONSE_HEADER.cookie] = v
|
||||
end
|
||||
function std.setCookie(t,v,p)
|
||||
p = p or ""
|
||||
std._setCookie(HTTP_REQUEST.id,t,v,p)
|
||||
end
|
||||
function std.cjson(v, p)
|
||||
|
||||
std.setCookie("application/json; charset=utf-8",v)
|
||||
end
|
||||
function std.chtml(v)
|
||||
std.setCookie("text/html; charset=utf-8",v)
|
||||
end
|
||||
function std.ctext(v)
|
||||
std.setCookie("text/plain; charset=utf-8",v)
|
||||
|
||||
function std.error(status, msg)
|
||||
std._error(HTTP_REQUEST.id, status, msg)
|
||||
end
|
||||
--_upload
|
||||
--_route
|
||||
function std.unknow(s)
|
||||
std._unknow(HTTP_REQUEST.id,s)
|
||||
std.error(404, "Unknown request")
|
||||
end
|
||||
|
||||
--_redirect
|
||||
--[[ function std.redirect(s)
|
||||
std._redirect(HTTP_REQUEST.id,s)
|
||||
end ]]
|
||||
|
||||
function std.html()
|
||||
std.header("Content-Type","text/html")
|
||||
std.header_flush()
|
||||
end
|
||||
function std.text()
|
||||
std.header("Content-Type","text/plain")
|
||||
std.header_flush()
|
||||
end
|
||||
|
||||
function std.json()
|
||||
std.header("Content-Type","application/json")
|
||||
std.header_flush()
|
||||
end
|
||||
function std.jpeg()
|
||||
std.header("Content-Type","image/jpeg")
|
||||
std.header_flush()
|
||||
end
|
||||
function std.octstream(s)
|
||||
std.header("Content-Type","application/octet-stream")
|
||||
std.header("Content-Disposition",'attachment; filename="'..s..'"')
|
||||
std.header_flush()
|
||||
end
|
||||
--[[ function std.textstream()
|
||||
std._textstream(HTTP_REQUEST.id)
|
||||
end ]]
|
||||
|
||||
|
||||
function std.readOnly(t) -- bugging
|
||||
local proxy = {}
|
||||
local mt = { -- create metatable
|
||||
|
10
APIs/web.lua
10
APIs/web.lua
@ -5,7 +5,7 @@ local wurl = require("wurl")
|
||||
|
||||
local web = {}
|
||||
|
||||
web.undestand = function(proto)
|
||||
web.understand = function(proto)
|
||||
if proto == "http" or proto == "https" then
|
||||
return true
|
||||
else
|
||||
@ -15,7 +15,7 @@ end
|
||||
|
||||
web.get = function(url)
|
||||
local obj = utils.url_parser(url)
|
||||
if web.undestand(obj.protocol) then
|
||||
if web.understand(obj.protocol) then
|
||||
return wurl._get(obj.hostname,obj.port, obj.query)
|
||||
else
|
||||
return nil,"Protocol is unsupported: "..obj.protocol
|
||||
@ -25,7 +25,7 @@ end
|
||||
|
||||
web.post = function(url,data)
|
||||
local obj = utils.url_parser(url)
|
||||
if web.undestand(obj.protocol) then
|
||||
if web.understand(obj.protocol) then
|
||||
if type(data) == "string" then
|
||||
return wurl._post(obj.hostname,
|
||||
obj.port,
|
||||
@ -44,7 +44,7 @@ end
|
||||
|
||||
web.download = function(url,to)
|
||||
local obj = utils.url_parser(url)
|
||||
if web.undestand(obj.protocol) then
|
||||
if web.understand(obj.protocol) then
|
||||
local file
|
||||
if std.is_dir(to) then
|
||||
-- need to find file name here
|
||||
@ -64,7 +64,7 @@ end
|
||||
|
||||
web.upload = function(url,name,file)
|
||||
local obj = utils.url_parser(url)
|
||||
if web.undestand(obj.protocol) then
|
||||
if web.understand(obj.protocol) then
|
||||
return wurl._upload(obj.hostname,obj.port,obj.query,name,file)
|
||||
else
|
||||
return nil,"Protocol is unsupported: "..obj.protocol
|
||||
|
Reference in New Issue
Block a user