1
0
mirror of https://github.com/lxsang/antd-lua-plugin synced 2025-07-27 03:09:53 +02:00

mimgrating from another repo

This commit is contained in:
Xuan Sang LE
2018-09-19 15:08:49 +02:00
parent 91320521e8
commit 38bd13b46b
600 changed files with 362490 additions and 1 deletions

View File

@ -0,0 +1,62 @@
auth_or_die("User unauthorized. Please login")
if std.ws.enable() then
-- read header
local streaming = true
while streaming do
local header = std.ws.header()
if header then
if header.mask == 0 then
print("Data is not masked")
std.ws.close(1012)
streaming = false
elseif header.opcode == std.ws.CLOSE then
print("Connection closed")
std.ws.close(1000)
streaming = false
elseif header.opcode == std.ws.BIN then
-- read the file
local data = std.ws.read(header)
local cmd = nil
if data then
local str = bytes.__tostring(data)
local b,e = str:find("^%d+")
if(b) then
local size = tonumber(str:sub(b,e))
local path = require("fs.vfs").ospath(str:sub(e+1))
local file = io.open(path, "rb")
if file then
local sum, len = 0,0
repeat
local buffer = file:read(size)
if buffer then
len = len + #buffer
cmd = bytes.new(#buffer)
for i = 1, #buffer do
cmd[i] = buffer:byte(i)
end
std.ws.write_bytes(cmd)
end
until not buffer
file:close()
print("ospath is : "..path)
print("length:",len)
else
print(path.." is not found")
std.ws.close(1011)
end
else
std.ws.close(1011)
end
else
std.ws.close(1011)
streaming = false
end
end
else
streaming = false
end
end
else
print("Web socket is not available.")
end
print("Quit streaming")

View File

@ -0,0 +1,33 @@
if std.ws.enable() then
-- read header
local streaming = true
while streaming do
local header = std.ws.header()
if header then
if header.mask == 0 then
print("Data is not masked")
std.ws.close(1012)
streaming = false
elseif header.opcode == std.ws.CLOSE then
print("Connection closed")
std.ws.close(1000)
streaming = false
elseif header.opcode == std.ws.BIN then
local data = std.ws.read(header)
if data then
local path = (__ROOT__.."/ws/img%d.jpg"):format(data[0])
print("writing : "..path)
std.ws.fwrite(path)
else
std.ws.close(1011)
streaming = false
end
end
else
streaming = false
end
end
else
print("Web socket is not available.")
end
print("Quit streaming")