more complicated proposal

reviewable/pr11532/r1
Frans de Jonge 3 months ago
parent 882a1c061c
commit 049bde79f1

@ -99,7 +99,7 @@ function Wallabag:init()
self.articles_per_sync = self.wb_settings.data.wallabag.articles_per_sync self.articles_per_sync = self.wb_settings.data.wallabag.articles_per_sync
end end
self.remove_finished_from_history = self.wb_settings.data.wallabag.remove_finished_from_history or false self.remove_finished_from_history = self.wb_settings.data.wallabag.remove_finished_from_history or false
self.download_original_pdf = self.wb_settings.data.wallabag.download_original_pdf self.download_original_document = self.wb_settings.data.wallabag.download_original_document
self.download_queue = self.wb_settings.data.wallabag.download_queue or {} self.download_queue = self.wb_settings.data.wallabag.download_queue or {}
-- workaround for dateparser only available if newsdownloader is active -- workaround for dateparser only available if newsdownloader is active
@ -342,13 +342,13 @@ function Wallabag:addToMainMenu(menu_items)
separator = true, separator = true,
}, },
{ {
text = _("Download original PDF if available"), text = _("Download original document if supported and not HTML"),
keep_menu_open = true, keep_menu_open = true,
checked_func = function() checked_func = function()
return self.download_original_pdf return self.download_original_document
end, end,
callback = function() callback = function()
self.download_original_pdf = not self.download_original_pdf self.download_original_document = not self.download_original_document
self:saveSettings() self:saveSettings()
end, end,
separator = true, separator = true,
@ -564,11 +564,24 @@ function Wallabag:download(article)
local title = util.getSafeFilename(article.title, self.directory, 230, 0) local title = util.getSafeFilename(article.title, self.directory, 230, 0)
local file_ext = ".epub" local file_ext = ".epub"
local item_url = "/api/entries/" .. article.id .. "/export.epub" local item_url = "/api/entries/" .. article.id .. "/export.epub"
-- The mimetype is actually an HTTP Content-Type, so it can include a semicolon with stuff after it.
if self.download_original_pdf and type(article.mimetype) == "string" and article.mimetype:find("^application/pdf") then -- Just in case we also trim it, though that shouldn't be necessary.
logger.dbg("Wallabag: ignoring EPUB in favor of original PDF") -- A function represents `null` in our JSON.decode, because `nil` would just disappear.
file_ext = ".pdf" -- We can simplify that to not a string.
item_url = article.url local mimetype = type(article.mimetype) == string and util.trim(article.mimetype:match("^[^;]*")) or nil
-- If the article links to a supported file, 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
logger.dbg("Wallabag: 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: ignoring EPUB in favor of original: ", article.url)
file_ext = "."..util.getFileNameSuffix(article.url)
item_url = article.url
end
end end
local local_path = self.directory .. article_id_prefix .. article.id .. article_id_postfix .. title .. file_ext local local_path = self.directory .. article_id_prefix .. article.id .. article_id_postfix .. title .. file_ext
@ -1144,7 +1157,7 @@ function Wallabag:saveSettings()
send_review_as_tags = self.send_review_as_tags, send_review_as_tags = self.send_review_as_tags,
remove_finished_from_history = self.remove_finished_from_history, remove_finished_from_history = self.remove_finished_from_history,
remove_read_from_history = self.remove_read_from_history, remove_read_from_history = self.remove_read_from_history,
download_original_pdf = self.download_original_pdf, download_original_document = self.download_original_document,
download_queue = self.download_queue, download_queue = self.download_queue,
} }
self.wb_settings:saveSetting("wallabag", tempsettings) self.wb_settings:saveSetting("wallabag", tempsettings)

Loading…
Cancel
Save