Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function downloadFile(url, savePath)
- local res = http.get(url)
- if res then
- local content = res.readAll()
- res.close()
- local dir = fs.getDir(savePath)
- if dir ~= "" and not fs.exists(dir) then
- fs.makeDir(dir)
- end
- local file = fs.open(savePath, "w")
- file.write(content)
- file.close()
- print("Downloaded: " .. savePath)
- return true
- else
- print("Failed to download: " .. url)
- return false
- end
- end
- -- Step 1: Ensure dkjson is installed
- local dkjsonPath = "lib/dkjson.lua"
- if not fs.exists(dkjsonPath) then
- print("Downloading dkjson.lua...")
- local success = downloadFile("https://raw.githubusercontent.com/LuaDist/dkjson/master/dkjson.lua", dkjsonPath)
- if not success then
- print("Could not download dkjson.lua. Aborting.")
- return
- end
- end
- local dkjson = require("lib.dkjson")
- -- Step 2: Recursive GitHub repo downloader
- local function downloadFolder(user, repo, path, branch)
- branch = branch or "main"
- path = path or ""
- local apiUrl = "https://api.github.com/repos/" .. user .. "/" .. repo .. "/contents/" .. path .. "?ref=" .. branch
- local res = http.get(apiUrl)
- if not res then
- print("Failed to get folder listing: " .. path)
- return
- end
- local body = res.readAll()
- res.close()
- local data, pos, err = dkjson.decode(body, 1, nil)
- if not data then
- print("JSON decode error: " .. err)
- return
- end
- for _, item in ipairs(data) do
- if item.type == "file" then
- downloadFile(item.download_url, item.path)
- elseif item.type == "dir" then
- downloadFolder(user, repo, item.path, branch)
- end
- end
- end
- -- === CONFIGURE YOUR REPO HERE ===
- local githubUser = "ReedSkil"
- local githubRepo = "Reedcoin"
- local branch = "main"
- print("Starting download of repo: " .. githubUser .. "/" .. githubRepo)
- downloadFolder(githubUser, githubRepo, "", branch)
- print("Download complete.")
Advertisement
Add Comment
Please, Sign In to add comment