Skip to content

Commit

Permalink
Fix: Images not downloading when url has trailing slash (#57)
Browse files Browse the repository at this point in the history
* fix: Images not downloading if url has trailing slash

* fix: Wrong config options
  • Loading branch information
Lythium4848 authored Nov 18, 2024
1 parent 1cecad5 commit b75d083
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lua/pixelui/core/cl_images.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,26 @@ end

function PIXEL.GetImage(url, callback, matSettings)
local protocol = url:match("^([%a]+://)")
local urlWithoutProtocol = url
if not protocol then
protocol = "http://"
else
urlWithoutProtocol = string.gsub(url, protocol, "")

local hasTrailingSlash = url:sub(-1) == "/"
local urlWithoutTrailingSlash = url
if hasTrailingSlash then
urlWithoutTrailingSlash = url:sub(1, -2)
end

local fileNameStart = url:find("[^/]+$")
local fileNameStart = urlWithoutTrailingSlash:find("[^/]+$")
if not fileNameStart then
return
end

local urlWithoutFileName = url:sub(protocol:len() + 1, fileNameStart - 1)
local urlWithoutProtocol = url
if not protocol then
protocol = "http://"
else
urlWithoutProtocol = string.gsub(urlWithoutTrailingSlash, protocol, "")
end

local urlWithoutFileName = urlWithoutTrailingSlash:sub(protocol:len() + 1, fileNameStart - 1)

local dirPath = PIXEL.DownloadPath .. urlWithoutFileName
local filePath = PIXEL.DownloadPath .. urlWithoutProtocol
Expand Down

0 comments on commit b75d083

Please sign in to comment.