Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local shell = require("shell")
- local comp = require("computer")
- local ser = require("serialization")
- local inet = require("component").internet
- local fs = require("filesystem")
- local ref = "master"
- local repo = ""
- local deploy_path = "/"
- local function request(url, body, headers, timeout)
- local handle, err = inet.request(url, body, headers)
- if not handle then
- return nil, ("request failed: %s"):format(err or "unknown error")
- end
- local start = comp.uptime()
- while true do
- local status, err = handle.finishConnect()
- if status then
- break
- end
- if status == nil then
- return nil, ("request failed: %s"):format(err or "unknown error")
- end
- if comp.uptime() >= start + (timeout or 3 )then
- handle.close()
- return nil, "request failed: connection timed out"
- end
- os.sleep(0.05)
- end
- return handle
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function get_files(path)
- local handle, err = request(path)
- local body = {}
- local read = 0
- while true do
- local chunk, err = handle.read()
- if not chunk then
- local _, _, responseHeaders = handle.response()
- local length
- for k, v in pairs(responseHeaders) do
- if k:lower() == "content-length" then
- length = tonumber(v)
- end
- end
- if not length or read >= length then
- break
- end
- end
- read = read + #chunk
- table.insert(body, chunk)
- end
- body = table.concat(body)
- local types = {}
- local paths = {}
- local urls = {}
- local durls = {}
- for str in string.gmatch(body, "\"type\":\"[^\"]*\",") do
- table.insert(types, str:sub(9,-3))
- end
- for str in string.gmatch(body, "\"path\":\"[^\"]*\",") do
- table.insert(paths, str:sub(9,-3))
- end
- for str in string.gmatch(body, "\"url\":\"[^\"]*\",") do
- table.insert(urls, str:sub(8,-3))
- end
- for str in string.gmatch(body, "\"download_url\":\"[^\"]*\",") do
- table.insert(durls, str:sub(17,-3))
- end
- for i=1,tablelength(types) do
- if types[i] == "file" then
- if not fs.exists(deploy_path..paths[i]:match(".*/")) then fs.makeDirectory(deploy_path..paths[i]:match(".*/")) end
- shell.execute("wget -f "..durls[i].." "..deploy_path..paths[i])
- else
- get_files(urls[i])
- end
- end
- end
- get_files("https://api.github.com/repos/"..repo.."/contents/?ref="..ref)
Add Comment
Please, Sign In to add comment