|
|
@ -14,7 +14,7 @@ local MemosExporter = require("base"):new {
|
|
|
|
is_remote = true,
|
|
|
|
is_remote = true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local function makeRequest(method, request_body, api)
|
|
|
|
local function makeRequest(method, request_body, api, token)
|
|
|
|
local sink = {}
|
|
|
|
local sink = {}
|
|
|
|
local request_body_json = json.encode(request_body)
|
|
|
|
local request_body_json = json.encode(request_body)
|
|
|
|
local source = ltn12.source.string(request_body_json)
|
|
|
|
local source = ltn12.source.string(request_body_json)
|
|
|
@ -25,7 +25,8 @@ local function makeRequest(method, request_body, api)
|
|
|
|
sink = ltn12.sink.table(sink),
|
|
|
|
sink = ltn12.sink.table(sink),
|
|
|
|
source = source,
|
|
|
|
source = source,
|
|
|
|
headers = {
|
|
|
|
headers = {
|
|
|
|
["Content-Type"] = "application/json"
|
|
|
|
["Content-Type"] = "application/json",
|
|
|
|
|
|
|
|
["Authorization"] = "Bearer " .. token
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local code, headers, status = socket.skip(1, http.request(request))
|
|
|
|
local code, headers, status = socket.skip(1, http.request(request))
|
|
|
@ -42,7 +43,7 @@ local function makeRequest(method, request_body, api)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function MemosExporter:isReadyToExport()
|
|
|
|
function MemosExporter:isReadyToExport()
|
|
|
|
if self.settings.api then return true end
|
|
|
|
if self.settings.api and self.settings.token then return true end
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -83,6 +84,38 @@ function MemosExporter:getMenuTable()
|
|
|
|
auth_dialog:onShowKeyboard()
|
|
|
|
auth_dialog:onShowKeyboard()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
text = _("Set Memos Token"),
|
|
|
|
|
|
|
|
keep_menu_open = true,
|
|
|
|
|
|
|
|
callback = function()
|
|
|
|
|
|
|
|
local token_dialog
|
|
|
|
|
|
|
|
token_dialog = InputDialog:new {
|
|
|
|
|
|
|
|
title = _("Set Token for Memos"),
|
|
|
|
|
|
|
|
input = self.settings.token,
|
|
|
|
|
|
|
|
buttons = {
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
text = _("Cancel"),
|
|
|
|
|
|
|
|
id = "close",
|
|
|
|
|
|
|
|
callback = function()
|
|
|
|
|
|
|
|
UIManager:close(token_dialog)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
text = _("Set Token"),
|
|
|
|
|
|
|
|
callback = function()
|
|
|
|
|
|
|
|
self.settings.token = token_dialog:getInputText()
|
|
|
|
|
|
|
|
self:saveSettings()
|
|
|
|
|
|
|
|
UIManager:close(token_dialog)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UIManager:show(token_dialog)
|
|
|
|
|
|
|
|
token_dialog:onShowKeyboard()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Export to Memos"),
|
|
|
|
text = _("Export to Memos"),
|
|
|
|
checked_func = function() return self:isEnabled() end,
|
|
|
|
checked_func = function() return self:isEnabled() end,
|
|
|
@ -103,7 +136,7 @@ function MemosExporter:createHighlights(booknotes)
|
|
|
|
highlight = highlight .. clipping.note .. "\n\n"
|
|
|
|
highlight = highlight .. clipping.note .. "\n\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
highlight = highlight .. booknotes.title .. " (page: " .. clipping.page .. ")\n\n #" .. booknotes.title .. " #koreader"
|
|
|
|
highlight = highlight .. booknotes.title .. " (page: " .. clipping.page .. ")\n\n #" .. booknotes.title .. " #koreader"
|
|
|
|
local result, err = makeRequest("POST", { content = highlight }, self.settings.api)
|
|
|
|
local result, err = makeRequest("POST", { content = highlight }, self.settings.api, self.settings.token)
|
|
|
|
if not result then
|
|
|
|
if not result then
|
|
|
|
logger.warn("error creating highlights", err)
|
|
|
|
logger.warn("error creating highlights", err)
|
|
|
|
error_number = error_number + 1
|
|
|
|
error_number = error_number + 1
|
|
|
|