CCCPaste

Installer

local repo = "https://api.github.com/repos/dashingsoocooldude/CCinstall/contents/"
local branch = "dev"


function downloadFile(destination, url)

    local response = http.get(url)
    if not response then
        error("Failed to download file from " .. url)
        return
    end

    local content = response.readAll()
    response.close()

    local file = fs.open(destination, "w")
    file.write(content)
    file.close()
    
end


function fetchPath(path)
    
    local url = repo .. path
    local body = http.get(url)
    local data = textutils.unserialiseJSON(body.readAll())
    body.close()

    

    for i = 1, #data do
        local entry = data[i]
        local cleanPath = entry.path:gsub("^" .. branch .. "/", "")

        if entry.type == "dir" then
            fetchPath(entry.path)
        elseif entry.type == "file" then
            downloadFile(cleanPath, entry.download_url)
        end

    end
end

fetchPath(branch)