Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function parseFolders(pack, repo, info)
- local function getFolderTable(repo, namePath, branch)
- local success, filestring = pcall(getContent,"https://api.github.com/repos/"..repo.."/contents/"..namePath.."?ref="..branch)
- if not success or filestring:find("\"message\": \"Not Found\"") then
- io.stderr:write("Error while trying to parse folder names in declaration of package "..pack..".\n")
- io.stderr:write("Please contact the author of that package.\n")
- return nil
- end
- return serial.unserialize(filestring:gsub("%[", "{"):gsub("%]", "}"):gsub("(\"%S-\")%s?:", "[%1] =")))
- end
- local function unserializeFiles(files, repo, namePath, branch, relPath)
- if not files then return nil end
- local tFiles = {}
- for _,v in pairs(files) do
- if v["type"] == "file" then
- local newPath = v["download_url"]:gsub("https?://raw.githubusercontent.com/"..repo.."(.+)$", "%1"):gsub("/?$",""):gsub("^/?","")
- tFiles[newPath] = fs.concat(relPath, newPath:gsub(branch.."/(.+)$","%1"), nil)
- elseif v["type"] == "dir" then
- local newFiles = unserializeFiles(getFolderTable(repo, namePath.."/"..v["path"], branch), repo, branch, fs.concat(relPath, v["path"])
- for p,q in pairs(newFiles) do
- tFiles[p] = q
- end
- end
- end
- return tFiles
- end
- local newInfo = info
- for i,j in pairs(info.files) do
- if string.find(j,"^:") then
- local branch = string.gsub(i,"^(.-)/.+","%1"):gsub("/?$",""):gsub("^/?","")
- local namePath = string.gsub(i,".-(/.+)$","%1"):gsub("/?$",""):gsub("^/?","")
- local files = unserializeFiles(getFolderTable(repo, namePath, branch), repo, namePath, branch, j)
- if not files then return nil end
- for p,q in pairs(newFiles) do
- newInfo.files[p] = q
- end
- newInfo.files[i] = nil
- end
- end
- return newInfo
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement