From 871b8cf3818b7e5196c9de5db302a8d6126e493c Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Tue, 31 Dec 2024 15:49:25 +0100 Subject: [PATCH] [plugin] NewsDownloader: download images without extension (#12969) Fixes #12967. --- plugins/newsdownloader.koplugin/epubdownloadbackend.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/newsdownloader.koplugin/epubdownloadbackend.lua b/plugins/newsdownloader.koplugin/epubdownloadbackend.lua index a409f5696..be07cafd1 100644 --- a/plugins/newsdownloader.koplugin/epubdownloadbackend.lua +++ b/plugins/newsdownloader.koplugin/epubdownloadbackend.lua @@ -353,14 +353,13 @@ function EpubDownloadBackend:createEpub(epub_path, html, url, include_images, me src_ext = src_ext:match("(.-)%?") -- remove ?blah end local ext = src_ext:match(".*%.(%S%S%S?%S?%S?)$") -- extensions are only 2 to 5 chars - if ext == nil or ext == "" then - -- we won't know what mimetype to use, ignore it - logger.dbg("no file extension found in ", src) - return nil + if ext == nil then + --- @todo Reverse the logic to download the image first so we can get the mimetype from the headers? + ext = "" end ext = ext:lower() local imgid = string.format("img%05d", imagenum) - local imgpath = string.format("images/%s.%s", imgid, ext) + local imgpath = ext ~= "" and string.format("images/%s.%s", imgid, ext) or string.format("images/%s", imgid) local mimetype = ext_to_mimetype[ext] or "" local width = tonumber(img_tag:match([[width="([^"]*)"]])) local height = tonumber(img_tag:match([[height="([^"]*)"]]))