Skip to content
Permalink
Browse files

[fix] OPDS last-modified check (#4874)

Fixes #4873. Unfortunately this will introduce a slight delay but I don't see any other quick & reasonable solution.
  • Loading branch information...
Frenzie committed Apr 5, 2019
1 parent 1887708 commit 22db71c07549ffc59196f1f27cd9bb162eacd6d7
Showing with 14 additions and 2 deletions.
  1. +14 −2 frontend/ui/widget/opdsbrowser.lua
@@ -269,13 +269,13 @@ function OPDSBrowser:genItemTableFromRoot()
return item_table
end

function OPDSBrowser:fetchFeed(item_url, username, password)
function OPDSBrowser:fetchFeed(item_url, username, password, method)
local request, sink = {}, {}
local parsed = url.parse(item_url)
local hostname = parsed.host
local auth = string.format("%s:%s", username, password)
request['url'] = item_url
request['method'] = 'GET'
request['method'] = method and method or "GET"
request['sink'] = ltn12.sink.table(sink)
request['headers'] = { Authorization = "Basic " .. mime.b64(auth), ["Host"] = hostname, }
logger.info("request", request)
@@ -287,6 +287,13 @@ function OPDSBrowser:fetchFeed(item_url, username, password)
error(code)
end
if code == 200 then
if method == "HEAD" then
if headers["last-modified"] then
return headers["last-modified"]
else
return
end
end
local xml = table.concat(sink)
if xml ~= "" then
return xml
@@ -300,7 +307,12 @@ end

function OPDSBrowser:parseFeed(item_url, username, password)
local feed
local feed_last_modified = self:fetchFeed(item_url, username, password, "HEAD")
local hash = "opds|catalog|" .. item_url
if feed_last_modified then
hash = hash .. feed_last_modified
end

local cache = CatalogCache:check(hash)
if cache then
feed = cache.feed

0 comments on commit 22db71c

Please sign in to comment.
You can’t perform that action at this time.