mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[feat] CloudStorage/WebDAV: show 'file size' property in WebDAV (#13371)
This commit is contained in:
@@ -19,6 +19,7 @@ local logger = require("logger")
|
||||
local _ = require("gettext")
|
||||
local N_ = _.ngettext
|
||||
local T = require("ffi/util").template
|
||||
local util = require("util")
|
||||
|
||||
local CloudStorage = Menu:extend{
|
||||
no_title = false,
|
||||
@@ -227,15 +228,18 @@ function CloudStorage:downloadFile(item)
|
||||
})
|
||||
end
|
||||
|
||||
local function createTitle(filename_orig, filename, path) -- title for ButtonDialog
|
||||
return T(_("Filename:\n%1\n\nDownload filename:\n%2\n\nDownload folder:\n%3"),
|
||||
filename_orig, filename, BD.dirpath(path))
|
||||
local function createTitle(filename_orig, filesize, filename, path) -- title for ButtonDialog
|
||||
local filesize_str = filesize and util.getFriendlySize(filesize) or _("N/A")
|
||||
|
||||
return T(_("Filename:\n%1\n\nFile size:\n%2\n\nDownload filename:\n%3\n\nDownload folder:\n%4"),
|
||||
filename_orig, filesize_str, filename, BD.dirpath(path))
|
||||
end
|
||||
|
||||
local cs_settings = self:readSettings()
|
||||
local download_dir = cs_settings:readSetting("download_dir") or G_reader_settings:readSetting("lastdir")
|
||||
local filename_orig = item.text
|
||||
local filename = filename_orig
|
||||
local filesize = item.filesize
|
||||
|
||||
local buttons = {
|
||||
{
|
||||
@@ -247,7 +251,7 @@ function CloudStorage:downloadFile(item)
|
||||
self.cs_settings:saveSetting("download_dir", path)
|
||||
self.cs_settings:flush()
|
||||
download_dir = path
|
||||
self.download_dialog:setTitle(createTitle(filename_orig, filename, download_dir))
|
||||
self.download_dialog:setTitle(createTitle(filename_orig, filesize, filename, download_dir))
|
||||
end,
|
||||
}:chooseDir(download_dir)
|
||||
end,
|
||||
@@ -278,7 +282,7 @@ function CloudStorage:downloadFile(item)
|
||||
filename = filename_orig
|
||||
end
|
||||
UIManager:close(input_dialog)
|
||||
self.download_dialog:setTitle(createTitle(filename_orig, filename, download_dir))
|
||||
self.download_dialog:setTitle(createTitle(filename_orig, filesize, filename, download_dir))
|
||||
end,
|
||||
},
|
||||
}
|
||||
@@ -318,7 +322,7 @@ function CloudStorage:downloadFile(item)
|
||||
}
|
||||
|
||||
self.download_dialog = ButtonDialog:new{
|
||||
title = createTitle(filename_orig, filename, download_dir),
|
||||
title = createTitle(filename_orig, filesize, filename, download_dir),
|
||||
buttons = buttons,
|
||||
}
|
||||
UIManager:show(self.download_dialog)
|
||||
@@ -388,7 +392,6 @@ function CloudStorage:onMenuHold(item)
|
||||
callback = function()
|
||||
UIManager:close(cs_server_dialog)
|
||||
self:editCloudServer(item)
|
||||
|
||||
end
|
||||
},
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ function WebDavApi:listFolder(address, user, pass, folder_path, folder_mode)
|
||||
end
|
||||
|
||||
local sink = {}
|
||||
local data = [[<?xml version="1.0"?><a:propfind xmlns:a="DAV:"><a:prop><a:resourcetype/></a:prop></a:propfind>]]
|
||||
local data = [[<?xml version="1.0"?><a:propfind xmlns:a="DAV:"><a:prop><a:resourcetype/><a:getcontentlength/></a:prop></a:propfind>]]
|
||||
socketutil:set_timeout()
|
||||
local request = {
|
||||
url = webdav_url,
|
||||
@@ -109,6 +109,9 @@ function WebDavApi:listFolder(address, user, pass, folder_path, folder_mode)
|
||||
item:find("<[^:]*:resourcetype></[^:]*:resourcetype>")
|
||||
local item_path = path .. "/" .. item_name
|
||||
|
||||
-- only available for files, not directories/collections
|
||||
local item_filesize = item:match("<[^:]*:getcontentlength[^>]*>(%d+)</[^:]*:getcontentlength>")
|
||||
|
||||
if item:find("<[^:]*:collection[^<]*/>") then
|
||||
item_name = item_name .. "/"
|
||||
if not is_current_dir then
|
||||
@@ -124,6 +127,7 @@ function WebDavApi:listFolder(address, user, pass, folder_path, folder_mode)
|
||||
text = item_name,
|
||||
url = item_path,
|
||||
type = "file",
|
||||
filesize = tonumber(item_filesize)
|
||||
})
|
||||
end
|
||||
end
|
||||
@@ -143,6 +147,8 @@ function WebDavApi:listFolder(address, user, pass, folder_path, folder_mode)
|
||||
text = files.text,
|
||||
url = files.url,
|
||||
type = files.type,
|
||||
filesize = files.filesize or nil,
|
||||
mandatory = util.getFriendlySize(files.filesize) or nil
|
||||
})
|
||||
end
|
||||
if folder_mode then
|
||||
|
||||
Reference in New Issue
Block a user