Advertisement
itsjstn

CC: Tweaked - github-get

Nov 28th, 2024 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 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. local githubPAT = settings.get("githubPAT");
  10.  
  11. print("Downloading...");
  12. local response;
  13. if githubPAT ~= nil then
  14.     response = http.get({
  15.         url = url,
  16.         headers = {
  17.             Authorization = "Bearer " .. githubPAT
  18.         }
  19.     });
  20. else
  21.     response = http.get(url);
  22. end
  23. if response then
  24.     local fileContent = response.readAll();
  25.     response.close();
  26.  
  27.     local file = fs.open(path, "w");
  28.     file.write(fileContent);
  29.     file.close();
  30.  
  31.     print("Saved as " .. path);
  32. else
  33.     print("Failed to save provided file. Please try again.");
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement