Skip to content

Commit

Permalink
Cloud storage: fix sorting non-English filenames (koreader#12644)
Browse files Browse the repository at this point in the history
Reported in koreader#12638.
  • Loading branch information
hius07 authored Oct 15, 2024
1 parent ce7fcff commit 1493a09
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions frontend/apps/cloudstorage/dropboxapi.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
local DocumentRegistry = require("document/documentregistry")
local JSON = require("json")
local ffiUtil = require("ffi/util")
local http = require("socket.http")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local ltn12 = require("ltn12")
local socket = require("socket")
local socketutil = require("socketutil")
local util = require("util")
local BaseUtil = require("ffi/util")
local _ = require("gettext")

local DropBoxApi = {
Expand Down Expand Up @@ -126,7 +126,7 @@ function DropBoxApi:downloadFile(path, token, local_path)
end

function DropBoxApi:uploadFile(path, token, file_path, etag, overwrite)
local data = "{\"path\": \"" .. path .. "/" .. BaseUtil.basename(file_path) ..
local data = "{\"path\": \"" .. path .. "/" .. ffiUtil.basename(file_path) ..
"\",\"mode\":" .. (overwrite and "\"overwrite\"" or "\"add\"") ..
",\"autorename\": " .. (overwrite and "false" or "true") ..
",\"mute\": false,\"strict_conflict\": false}"
Expand Down Expand Up @@ -202,10 +202,10 @@ function DropBoxApi:listFolder(path, token, folder_mode)
end
--sort
table.sort(dropbox_list, function(v1,v2)
return v1.text < v2.text
return ffiUtil.strcoll(v1.text, v2.text)
end)
table.sort(dropbox_file, function(v1,v2)
return v1.text < v2.text
return ffiUtil.strcoll(v1.text, v2.text)
end)
-- Add special folder.
if folder_mode then
Expand Down
5 changes: 3 additions & 2 deletions frontend/apps/cloudstorage/ftpapi.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local DocumentRegistry = require("document/documentregistry")
local ffiUtil = require("ffi/util")
local ftp = require("socket.ftp")
local ltn12 = require("ltn12")
local util = require("util")
Expand Down Expand Up @@ -71,10 +72,10 @@ function FtpApi:listFolder(address_path, folder_path)
end
--sort
table.sort(ftp_list, function(v1,v2)
return v1.text < v2.text
return ffiUtil.strcoll(v1.text, v2.text)
end)
table.sort(ftp_file, function(v1,v2)
return v1.text < v2.text
return ffiUtil.strcoll(v1.text, v2.text)
end)
for _, files in ipairs(ftp_file) do
table.insert(ftp_list, {
Expand Down
8 changes: 4 additions & 4 deletions frontend/apps/cloudstorage/webdavapi.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local DocumentRegistry = require("document/documentregistry")
local FFIUtil = require("ffi/util")
local ffiUtil = require("ffi/util")
local http = require("socket.http")
local ltn12 = require("ltn12")
local socket = require("socket")
Expand Down Expand Up @@ -103,7 +103,7 @@ function WebDavApi:listFolder(address, user, pass, folder_path, folder_mode)
--logger.dbg("WebDav catalog item=", item)
-- <d:href> is the path and filename of the entry.
local item_fullpath = item:match("<[^:]*:href[^>]*>(.*)</[^:]*:href>")
local item_name = FFIUtil.basename(util.htmlEntitiesToUtf8(util.urlDecode(item_fullpath)))
local item_name = ffiUtil.basename(util.htmlEntitiesToUtf8(util.urlDecode(item_fullpath)))
local is_current_dir = item_name == string.sub(folder_path, -#item_name)
local is_not_collection = item:find("<[^:]*:resourcetype%s*/>") or
item:find("<[^:]*:resourcetype></[^:]*:resourcetype>")
Expand Down Expand Up @@ -133,10 +133,10 @@ function WebDavApi:listFolder(address, user, pass, folder_path, folder_mode)

--sort
table.sort(webdav_list, function(v1,v2)
return v1.text < v2.text
return ffiUtil.strcoll(v1.text, v2.text)
end)
table.sort(webdav_file, function(v1,v2)
return v1.text < v2.text
return ffiUtil.strcoll(v1.text, v2.text)
end)
for _, files in ipairs(webdav_file) do
table.insert(webdav_list, {
Expand Down

0 comments on commit 1493a09

Please sign in to comment.