Skip to content

Commit b75d083

Browse files
authored
Fix: Images not downloading when url has trailing slash (#57)
* fix: Images not downloading if url has trailing slash * fix: Wrong config options
1 parent 1cecad5 commit b75d083

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lua/pixelui/core/cl_images.lua

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,26 @@ end
6767

6868
function PIXEL.GetImage(url, callback, matSettings)
6969
local protocol = url:match("^([%a]+://)")
70-
local urlWithoutProtocol = url
71-
if not protocol then
72-
protocol = "http://"
73-
else
74-
urlWithoutProtocol = string.gsub(url, protocol, "")
70+
71+
local hasTrailingSlash = url:sub(-1) == "/"
72+
local urlWithoutTrailingSlash = url
73+
if hasTrailingSlash then
74+
urlWithoutTrailingSlash = url:sub(1, -2)
7575
end
7676

77-
local fileNameStart = url:find("[^/]+$")
77+
local fileNameStart = urlWithoutTrailingSlash:find("[^/]+$")
7878
if not fileNameStart then
7979
return
8080
end
8181

82-
local urlWithoutFileName = url:sub(protocol:len() + 1, fileNameStart - 1)
82+
local urlWithoutProtocol = url
83+
if not protocol then
84+
protocol = "http://"
85+
else
86+
urlWithoutProtocol = string.gsub(urlWithoutTrailingSlash, protocol, "")
87+
end
88+
89+
local urlWithoutFileName = urlWithoutTrailingSlash:sub(protocol:len() + 1, fileNameStart - 1)
8390

8491
local dirPath = PIXEL.DownloadPath .. urlWithoutFileName
8592
local filePath = PIXEL.DownloadPath .. urlWithoutProtocol

0 commit comments

Comments
 (0)