83 lines
2.0 KiB
Lua
83 lines
2.0 KiB
Lua
local STATION_BROADCAST_URL = "https://cloud.fse-media.group/d/API/StationBroadcast/station_broadcast.lua?sign=xXsMwezjnEs4c6QrjkJkbvz1rARokmm87zwDcDDS5dk=:0"
|
|
local AUKIT_URL = "https://cloud.fse-media.group/d/API/StationBroadcast/aukit.lua?sign=02_QDktYbSrHrtCDsFlKMkbEOWJGDautZaOtWkvg5q8=:0"
|
|
local AUSTREAM_URL = "https://cloud.fse-media.group/d/API/StationBroadcast/austream.lua?sign=DrLbf9CIX1ZY8DaL8vliZiCMQzGos10nhG26Wf5lbgA=:0"
|
|
|
|
local function fetch(url)
|
|
if not http then
|
|
return nil, "HTTP API unavailable"
|
|
end
|
|
|
|
if http.checkURL then
|
|
local ok, err = http.checkURL(url)
|
|
if not ok then
|
|
return nil, err or "URL blocked"
|
|
end
|
|
end
|
|
|
|
local res, err = http.get(url)
|
|
if not res then
|
|
return nil, err or "request failed"
|
|
end
|
|
|
|
local body = res.readAll()
|
|
res.close()
|
|
|
|
if type(body) ~= "string" or #body == 0 then
|
|
return nil, "empty response"
|
|
end
|
|
|
|
return body
|
|
end
|
|
|
|
local function writeFile(path, content)
|
|
local dir = fs.getDir(path)
|
|
if dir and dir ~= "" and not fs.exists(dir) then
|
|
fs.makeDir(dir)
|
|
end
|
|
|
|
local f = fs.open(path, "w")
|
|
if not f then
|
|
return nil, "cannot open " .. path
|
|
end
|
|
|
|
f.write(content)
|
|
f.close()
|
|
return true
|
|
end
|
|
|
|
local function downloadTo(url, path)
|
|
write(("Updating %s... "):format(path))
|
|
local body, err = fetch(url)
|
|
if not body then
|
|
print("FAILED")
|
|
print(err)
|
|
return false
|
|
end
|
|
|
|
local ok, werr = writeFile(path, body)
|
|
if not ok then
|
|
print("FAILED")
|
|
print(werr)
|
|
return false
|
|
end
|
|
|
|
print("OK")
|
|
return true
|
|
end
|
|
|
|
local targets = {
|
|
{ url = STATION_BROADCAST_URL, path = shell.resolve("/startup") },
|
|
{ url = AUKIT_URL, path = shell.resolve("/aukit.lua") },
|
|
{ url = AUSTREAM_URL, path = shell.resolve("/austream.lua") }
|
|
}
|
|
|
|
for _, t in ipairs(targets) do
|
|
local ok = downloadTo(t.url, t.path)
|
|
if not ok then
|
|
print("Update aborted.")
|
|
return
|
|
end
|
|
end
|
|
|
|
print("Update complete.")
|