Cloud storage: add Dropbox short-lived tokens (#9496)

This commit is contained in:
hius07
2022-10-04 09:33:53 -07:00
committed by GitHub
parent 8a754cd271
commit 1ea7e16f3e
3 changed files with 138 additions and 86 deletions

View File

@@ -12,6 +12,10 @@ local _ = require("gettext")
local DropBox = {}
function DropBox:getAccessToken(refresh_token, app_key_colon_secret)
return DropBoxApi:getAccessToken(refresh_token, app_key_colon_secret)
end
function DropBox:run(url, password, choose_folder_mode)
return DropBoxApi:listFolder(url, password, choose_folder_mode)
end
@@ -92,39 +96,31 @@ function DropBox:createFolder(url, password, folder_name, callback_close)
end
function DropBox:config(item, callback)
local text_info = "How to generate Access Token:\n"..
"1. Open the following URL in your Browser, and log in using your account: https://www.dropbox.com/developers/apps.\n"..
"2. Click on >>Create App<<, then select >>Dropbox API app<<.\n"..
"3. Now go on with the configuration, choosing the app permissions and access restrictions to your DropBox folder.\n"..
"4. Enter the >>App Name<< that you prefer (e.g. KOReader).\n"..
"5. Now, click on the >>Create App<< button.\n" ..
"6. When your new App is successfully created, please click on the Generate button.\n"..
"7. Under the 'Generated access token' section, then enter code in Dropbox token field."
local hint_top = _("Your Dropbox name")
local text_top = ""
local hint_bottom = _("Dropbox token\n\n\n\n")
local text_bottom = ""
local title
local text_button_right = _("Add")
local text_info = _([[
Dropbox access tokens are short-lived (4 hours).
To generate new access token please use Dropbox refresh token and <APP_KEY>:<APP_SECRET> Base64 encoded string.
Some of the previously generated long-lived tokens are still valid.]])
local text_name, text_token, text_appkey
if item then
title = _("Edit Dropbox account")
text_button_right = _("Apply")
text_top = item.text
text_bottom = item.password
else
title = _("Add Dropbox account")
text_name = item.text
text_token = item.password
text_appkey = item.address
end
self.settings_dialog = MultiInputDialog:new {
title = title,
title = _("Dropbox cloud storage"),
fields = {
{
text = text_top,
hint = hint_top ,
text = text_name,
hint = _("Cloud storage displayed name"),
},
{
text = text_bottom,
hint = hint_bottom,
scroll = false,
text = text_token,
hint = _("Dropbox refresh token\nor long-lived token (deprecated)"),
},
{
text = text_appkey,
hint = _("Dropbox <APP_KEY>:<APP_SECRET>\n(leave blank for long-lived token)"),
},
},
buttons = {
@@ -144,29 +140,20 @@ function DropBox:config(item, callback)
end
},
{
text = text_button_right,
text = _("Save"),
callback = function()
local fields = MultiInputDialog:getFields()
if fields[1] ~= "" and fields[2] ~= "" then
if item then
--edit
callback(item, fields)
else
-- add new
callback(fields)
end
self.settings_dialog:onClose()
UIManager:close(self.settings_dialog)
if item then
callback(item, fields)
else
UIManager:show(InfoMessage:new{
text = _("Please fill in all fields.")
})
callback(fields)
end
self.settings_dialog:onClose()
UIManager:close(self.settings_dialog)
end
},
},
},
input_type = "text",
}
UIManager:show(self.settings_dialog)
self.settings_dialog:onShowKeyboard()
@@ -174,14 +161,17 @@ end
function DropBox:info(token)
local info = DropBoxApi:fetchInfo(token)
local info_text
if info and info.name then
info_text = T(_"Type: %1\nName: %2\nEmail: %3\nCountry: %4",
"Dropbox",info.name.display_name, info.email, info.country)
else
info_text = _("No information available")
local space_usage = DropBoxApi:fetchInfo(token, true)
if info and space_usage then
local account_type = info.account_type and info.account_type[".tag"]
local name = info.name and info.name.display_name
local space_total = space_usage.allocation and space_usage.allocation.allocated
UIManager:show(InfoMessage:new{
text = T(_"Type: %1\nName: %2\nEmail: %3\nCountry: %4\nSpace total: %5\nSpace used: %6",
account_type, name, info.email, info.country,
util.getFriendlySize(space_total), util.getFriendlySize(space_usage.used)),
})
end
UIManager:show(InfoMessage:new{text = info_text})
end
return DropBox