CelticCoder

github-test

May 25th, 2025 (edited)
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 KB | None | 0 0
  1. local function downloadFile(url, savePath)
  2.   local res = http.get(url)
  3.   if res then
  4.     local content = res.readAll()
  5.     res.close()
  6.  
  7.     local dir = fs.getDir(savePath)
  8.     if dir ~= "" and not fs.exists(dir) then
  9.       fs.makeDir(dir)
  10.     end
  11.  
  12.     local file = fs.open(savePath, "w")
  13.     file.write(content)
  14.     file.close()
  15.     print("Downloaded: " .. savePath)
  16.     return true
  17.   else
  18.     print("Failed to download: " .. url)
  19.     return false
  20.   end
  21. end
  22.  
  23. -- Step 1: Ensure dkjson is installed
  24. local dkjsonPath = "lib/dkjson.lua"
  25. if not fs.exists(dkjsonPath) then
  26.   print("Downloading dkjson.lua...")
  27.   local success = downloadFile("https://raw.githubusercontent.com/LuaDist/dkjson/master/dkjson.lua", dkjsonPath)
  28.   if not success then
  29.     print("Could not download dkjson.lua. Aborting.")
  30.     return
  31.   end
  32. end
  33.  
  34. local dkjson = require("lib.dkjson")
  35.  
  36. -- Step 2: Recursive GitHub repo downloader
  37. local function downloadFolder(user, repo, path, branch)
  38.   branch = branch or "main"
  39.   path = path or ""
  40.  
  41.   local apiUrl = "https://api.github.com/repos/" .. user .. "/" .. repo .. "/contents/" .. path .. "?ref=" .. branch
  42.   local res = http.get(apiUrl)
  43.  
  44.   if not res then
  45.     print("Failed to get folder listing: " .. path)
  46.     return
  47.   end
  48.  
  49.   local body = res.readAll()
  50.   res.close()
  51.  
  52.   local data, pos, err = dkjson.decode(body, 1, nil)
  53.   if not data then
  54.     print("JSON decode error: " .. err)
  55.     return
  56.   end
  57.  
  58.   for _, item in ipairs(data) do
  59.     if item.type == "file" then
  60.       downloadFile(item.download_url, item.path)
  61.     elseif item.type == "dir" then
  62.       downloadFolder(user, repo, item.path, branch)
  63.     end
  64.   end
  65. end
  66.  
  67. -- === CONFIGURE YOUR REPO HERE ===
  68. local githubUser = "ReedSkil"
  69. local githubRepo = "Reedcoin"
  70. local branch = "main"
  71.  
  72. print("Starting download of repo: " .. githubUser .. "/" .. githubRepo)
  73. downloadFolder(githubUser, githubRepo, "", branch)
  74. print("Download complete.")
  75.  
Advertisement
Add Comment
Please, Sign In to add comment