mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Calibre - pull files from device (#7492)
Add a proper implementation of `GET_BOOK_FILE_SEGMENT`, so calibre is now able to pull files from the device.
This commit is contained in:
@@ -13,6 +13,7 @@ local InputDialog = require("ui/widget/inputdialog")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local NetworkMgr = require("ui/network/manager")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local logger = require("logger")
|
||||
local rapidjson = require("rapidjson")
|
||||
local sha = require("ffi/sha2")
|
||||
@@ -644,9 +645,30 @@ end
|
||||
|
||||
function CalibreWireless:sendToCalibre(arg)
|
||||
logger.dbg("GET_BOOK_FILE_SEGMENT", arg)
|
||||
-- not implemented yet, we just send an invalid opcode to raise a control error in calibre.
|
||||
-- If we don't do this calibre will wait *a lot* for the file(s)
|
||||
self:sendJsonData('NOOP', {})
|
||||
local inbox_dir = G_reader_settings:readSetting("inbox_dir")
|
||||
local path = inbox_dir .. "/" .. arg.lpath
|
||||
|
||||
local file_size = lfs.attributes(path, "size")
|
||||
if not file_size then
|
||||
self:sendJsonData("NOOP", {})
|
||||
return
|
||||
end
|
||||
|
||||
local file = io.open(path, "rb")
|
||||
if not file then
|
||||
self:sendJsonData("NOOP", {})
|
||||
return
|
||||
end
|
||||
|
||||
self:sendJsonData("OK", { fileLength = file_size })
|
||||
|
||||
while true do
|
||||
local data = file:read(4096)
|
||||
if not data then break end
|
||||
self.calibre_socket:send(data)
|
||||
end
|
||||
|
||||
file:close()
|
||||
end
|
||||
|
||||
function CalibreWireless:isCalibreAtLeast(x,y,z)
|
||||
|
||||
Reference in New Issue
Block a user