Advertisement
itsjstn

CC: Tweaked - github-get

Nov 28th, 2024 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | Gaming | 0 0
  1. if #({...}) < 2 then
  2.     print("Usage: github-get <raw url> <path>");
  3.     return;
  4. end
  5.  
  6. local url = ...;
  7. local path = select(2, ...);
  8.  
  9. if settings.get("githubPAT") == nil then
  10.     settings.define("githubPAT");
  11.     settings.save();
  12.  
  13.     term.write("Enter Github PAT> ");
  14.     settings.set("githubPAT", term.read());
  15.     settings.save();
  16. end
  17.  
  18. local githubPAT = settings.get("githubPAT");
  19.  
  20. print("Downloading...");
  21. local response;
  22. if githubPAT ~= nil then
  23.     response = http.get({
  24.         url = url,
  25.         headers = {
  26.             Authorization = "Bearer " .. githubPAT
  27.         }
  28.     });
  29. else
  30.     response = http.get(url);
  31. end
  32. if response then
  33.     local fileContent = response.readAll();
  34.     response.close();
  35.  
  36.     local file = fs.open(path, "w");
  37.     file.write(fileContent);
  38.     file.close();
  39.  
  40.     print("Saved as " .. path);
  41. else
  42.     print("Failed to save provided file. Please try again.");
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement