Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download function #34

Open
ChristophLHR opened this issue Dec 7, 2023 · 0 comments
Open

download function #34

ChristophLHR opened this issue Dec 7, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@ChristophLHR
Copy link
Member

In comparison to the downloadGit function, this is superior but was never used. We should look into inserting it into the used function.
Especially in regards to the "UpdateObj", which is not used the downloadGit whatsoever.

    ---@param sourceObject table
    ---@param targetDirectory string
    ---@param updateObj table | nil
    ---@return table | nil
    ---@return boolean
    function Net:downloadURL(sourceObject, targetDirectory, updateObj)
        local sourceName = "default" or (updateObj and updateObj.sourceName)
        if updateObj then
            sourceObject.name = sourceObject.name or updateObj.name
        end

        if not sourceObject.name then
            sourceObject.name = self:getNameFromURL(sourceObject.source[sourceName])
        end
        local request = http.get(sourceObject.source[sourceName])

        if request then
            local content = request.readAll()
            request.close()

            if content then
                local file = fs.open(targetDirectory .. sourceObject.name, "w")
                if not file then
                    os.execute("mkdir " .. targetDirectory)
                    file = fs.open(targetDirectory .. sourceObject.name, "w")
                end
                file.write(content)
                file.close()

                return sourceObject, true
            end
        end

        return nil, false
    end
@ChristophLHR ChristophLHR added the enhancement New feature or request label Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant