Skip to content

download URLs #34

@ChristophLHR

Description

@ChristophLHR

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Open

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions