diff --git a/git.lua b/git.lua index af0d49c..43f72db 100644 --- a/git.lua +++ b/git.lua @@ -1,41 +1,12 @@ -- Leave empty for public repos, or add "your-token-here" local GIT_TOKEN = "" + +local GIT_OUTPUT_LOCATION = "/home" + -- Update config -local GIT_URL = "https://git.ejebring.com/eejebring/CC-tweaked-Gitea-Client/raw/branch/main/git.lua" +local UPDATE_URL = "https://git.ejebring.com/eejebring/CC-tweaked-Gitea-Client/raw/branch/main/git.lua" local GIT_FILE = "git.lua" --- Parse a Gitea URL like: https://gitea.example.com/owner/repo or /owner/repo/branch/filename --- local function parseGiteaURL(url) --- local protocol, domain, path = url:match("^(https?://([^/]+))(/[^?]*)") --- if not protocol then --- protocol, domain, path = "https://gitea.local", "gitea.local", url --- end - --- -- Remove trailing slashes and clean path --- path = path:gsub("/+$", "") - --- -- Extract components from path (format: /owner/repo or /owner/repo/branch) --- local parts = {} --- for segment in path:gmatch("[^/]+") do --- if segment ~= "" then table.insert(parts, segment) end --- end - --- if #parts < 2 then --- return nil, "Invalid URL format. Expected: https://domain.com/owner/repo" --- end - --- local owner = parts[1] --- local repo = parts[2] --- local branch = parts[3] or "master" - --- return { --- base = protocol .. "/" .. domain, --- owner = owner, --- repo = repo, --- branch = branch --- } --- end - ---@param str string ---@param comp string function string.beginsWith(str, comp) @@ -134,12 +105,8 @@ end local function cloneRepo(url) local urlInfo = parseGiteaURL(url) - -- if not info then error(err) end - print("Cloning: " .. urlInfo.owner .. "/" .. urlInfo.repo .. "@" .. urlInfo.branch) - -- local treeUrl = ("%s/api/v1/repos/%s/%s/git/trees/%s?recursive=1"):format(info.base, info.owner, info.repo,info.branch) - local req = { url = urlInfo.treeUrl } if GIT_TOKEN ~= "" then req.headers = { Authorization = "token " .. GIT_TOKEN } @@ -157,7 +124,7 @@ local function cloneRepo(url) local count = 0 for _, node in ipairs(tree.tree) do if node.type == "blob" then - local localPath = ("git/%s/%s/%s"):format(urlInfo.owner, urlInfo.repo, node.path) + local localPath = ("%s/%s/%s"):format(GIT_OUTPUT_LOCATION, urlInfo.repo, node.path) local dir = fs.getDir(localPath) if not fs.isDir(dir) then fs.makeDir(dir) end @@ -167,14 +134,14 @@ local function cloneRepo(url) end end - print(("Cloned %d files to /home/git/%s/%s"):format(count, urlInfo.owner, urlInfo.repo)) + print(("Cloned %d files to %s/%s"):format(count, GIT_OUTPUT_LOCATION, urlInfo.repo)) end local args = { ... } if args[1] == "clone" and args[2] then cloneRepo(args[2]) elseif args[1] == "update" then - local resp = http.get(GIT_URL) + local resp = http.get(UPDATE_URL) if not resp then error("Failed to download update.") end local code = resp.readAll() if not code then error("Recived empty response from server.") end