[plugin] Wallabag: remove empty file when download fails (#12723)

Wallabag can be really slow to generate epub for large articles. For
example, some Wikipedia articles can take 20+ seconds on app.wallabag.it
instance that I use.
This commit is contained in:
fenuks
2024-11-09 19:48:21 +00:00
committed by GitHub
parent 7c166a294e
commit 1f89f24e29

View File

@@ -667,6 +667,7 @@ function Wallabag:callAPI(method, apiurl, headers, body, filepath, quiet)
-- raise error message when network is unavailable
if resp_headers == nil then
logger.dbg("Wallabag: Server error:", status or code)
self:removeFailedDownload(filepath)
return nil, "network_error"
end
if code == 200 then
@@ -693,11 +694,7 @@ function Wallabag:callAPI(method, apiurl, headers, body, filepath, quiet)
end
else
if filepath ~= "" then
local entry_mode = lfs.attributes(filepath, "mode")
if entry_mode == "file" then
os.remove(filepath)
logger.dbg("Wallabag: Removed failed download:", filepath)
end
self:removeFailedDownload(filepath)
elseif not quiet then
UIManager:show(InfoMessage:new{
text = _("Communication with server failed."), })
@@ -708,6 +705,16 @@ function Wallabag:callAPI(method, apiurl, headers, body, filepath, quiet)
end
end
function Wallabag:removeFailedDownload(filepath)
if filepath ~= "" then
local entry_mode = lfs.attributes(filepath, "mode")
if entry_mode == "file" then
os.remove(filepath)
logger.dbg("Wallabag: Removed failed download:", filepath)
end
end
end
function Wallabag:synchronize()
local info = InfoMessage:new{ text = _("Connecting…") }
UIManager:show(info)