mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[plugin] Fix wallabag's "Prefer original non-HTML document" setting (#13333)
Fixes #13279.
This commit is contained in:
@@ -102,7 +102,7 @@ function Wallabag:init()
|
||||
self.remove_read_from_history = self.wb_settings.data.wallabag.remove_read_from_history or false
|
||||
self.remove_abandoned_from_history = self.wb_settings.data.wallabag.remove_abandoned_from_history or false
|
||||
self.download_original_document = self.wb_settings.data.wallabag.download_original_document or false
|
||||
self.offline_queue = self.wb_settings.data.wallabag.offline_queue or {}
|
||||
self.offline_queue = self.wb_settings.data.wallabag.offline_queue or {}
|
||||
self.use_local_archive = self.wb_settings.data.wallabag.use_local_archive or false
|
||||
|
||||
-- archive_directory only has a default if directory is set
|
||||
@@ -667,22 +667,32 @@ function Wallabag:downloadArticle(article)
|
||||
-- The mimetype is actually an HTTP Content-Type, so it can include a semicolon with stuff after it.
|
||||
-- Just in case we also trim it, though that shouldn't be necessary.
|
||||
-- A function represents `null` in our JSON.decode, because `nil` would just disappear.
|
||||
-- We can simplify that to not a string.
|
||||
local mimetype = type(article.mimetype) == string and util.trim(article.mimetype:match("^[^;]*")) or nil
|
||||
-- We can simplify that to 'not a string'.
|
||||
local mimetype = type(article.mimetype) == "string" and util.trim(article.mimetype:match("^[^;]*")) or nil
|
||||
|
||||
-- If the article links to a supported file type, we will download it directly.
|
||||
-- All webpages are HTML. Ignore them since we want the Wallabag EPUB instead!
|
||||
if self.download_original_document then
|
||||
if mimetype ~= "text/html" and DocumentRegistry:hasProvider(nil, mimetype) then
|
||||
if mimetype == "text/html" then
|
||||
logger.dbg("Wallabag:downloadArticle: not ignoring EPUB, because", article.url, "is HTML")
|
||||
elseif mimetype == nil then -- base ourselves on the file extension
|
||||
if util.getFileNameSuffix(article.url):lower():find("^html?$") then
|
||||
logger.dbg("Wallabag:downloadArticle: not ignoring EPUB, because", article.url, "appears to be HTML")
|
||||
elseif DocumentRegistry:hasProvider(article.url) then
|
||||
logger.dbg("Wallabag:downloadArticle: ignoring EPUB in favor of original", article.url)
|
||||
file_ext = "." .. util.getFileNameSuffix(article.url)
|
||||
item_url = article.url
|
||||
-- If an article does not have a title in its metadata (e.g. txt files),
|
||||
-- its filename (including extension) is used instead. This would cause it to be
|
||||
-- saved with a duplicate extension. So we remove the extension from the title
|
||||
title = util.trim(title:gsub("%" .. file_ext .. "$", ""))
|
||||
else
|
||||
logger.dbg("Wallabag:downloadArticle: not ignoring EPUB, because there is no provider for", article.url)
|
||||
end
|
||||
elseif DocumentRegistry:hasProvider(nil, mimetype) then
|
||||
logger.dbg("Wallabag:downloadArticle: ignoring EPUB in favor of mimetype", mimetype)
|
||||
file_ext = "."..DocumentRegistry:mimeToExt(article.mimetype)
|
||||
item_url = article.url
|
||||
elseif mimetype == nil and DocumentRegistry:hasProvider(article.url) then
|
||||
logger.dbg("Wallabag:downloadArticle: ignoring EPUB in favor of original", article.url)
|
||||
file_ext = "."..util.getFileNameSuffix(article.url)
|
||||
file_ext = "." .. DocumentRegistry:mimeToExt(article.mimetype)
|
||||
item_url = article.url
|
||||
else
|
||||
logger.dbg("Wallabag:downloadArticle: not ignoring EPUB, because", article.url, "is HTML")
|
||||
logger.dbg("Wallabag:downloadArticle: not ignoring EPUB, because there is no provider for", mimetype)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user