-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wallabag plugin #4271
Wallabag plugin #4271
Conversation
Archiving on server non-functional. Missing screen for local settings.
Setting archived status on server doesn't work. Might be a server issue. Switch to branch 'wallabag-archiving' to work on this feature.
Password is obscured. Ugly hack to get parse the time of article.
|
About your 1st issue I have not found how to refresh the value after a change : the callback gets provided the |
|
Can I run the CI checks on my own branch? |
Thanks to poire-z.
Thanks, that worked nicely. |
|
You can enable CircleCI on your own repo, yes. Let me know if you need a pointer! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
plugins/wallabag.koplugin/main.lua
Outdated
| local _ = require("gettext") | ||
| local T = FFIUtil.template | ||
| local Screen = require("device").screen | ||
| local DataStorage = require("datastorage") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note the order in our coding standards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
plugins/wallabag.koplugin/main.lua
Outdated
| end, | ||
| }, | ||
| { | ||
| text = _("Remotely delete Finished articles"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalization.
plugins/wallabag.koplugin/main.lua
Outdated
| keep_menu_open = true, | ||
| callback = function() | ||
| UIManager:show(InfoMessage:new{ | ||
| text = _('Download directory: use a directory that is exclusively used by the Wallabag plugin. ' .. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a multiline comment. Our translation string extraction regex will fail on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a max of 79 chars OK or should I split them further?
plugins/wallabag.koplugin/main.lua
Outdated
| keep_menu_open = true, | ||
| callback = function() | ||
| UIManager:show(InfoMessage:new{ | ||
| text = T(_('Wallabag is an open source Read-it-later service. This plugin synchronises with a Wallabag server.\n\n' .. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
plugins/wallabag.koplugin/main.lua
Outdated
|
|
||
| -- Check if the configuration is complete | ||
| local function isempty(s) | ||
| return s == nil or s == '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but could you use double quotes?
plugins/wallabag.koplugin/main.lua
Outdated
|
|
||
| function Wallabag:getBearerToken() | ||
| -- workaround for dateparser, only once | ||
| -- the parser is in newsdownloader.koplugin, check if it is available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be moved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it to init().
The date parser is really useful. Ideally it would be moved to a place where all plugins can access it.
plugins/wallabag.koplugin/main.lua
Outdated
| end | ||
|
|
||
| function Wallabag:editServerSettings() | ||
| local text_info = "Enter the details of your Wallabag server and account.\n".. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shortened strings a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about length but concat won't work right.
Use either just a single line with \n or [[multiline]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really a defect in the regex imo (or I would've changed it) because [[]] is much nicer anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it now. I have changed it to multiline.
plugins/wallabag.koplugin/main.lua
Outdated
| end | ||
| local num_deleted = self:processLocalFiles( "manual" ) | ||
| UIManager:show(InfoMessage:new{ | ||
| text = T(_('Articles processed.\nDeleted: %1'), num_deleted) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also make these double quotes for consistency?
plugins/wallabag.koplugin/main.lua
Outdated
| else | ||
| path = filemanagerutil.abbreviate(self.directory) | ||
| end | ||
| return _("Set download directory") .. " (" .. path .. ")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even for stuff like this it's generally preferable to use T(). The thing is, you don't really know if some localization might like to make it (path) Set download directory or Download directory (path) set or many other possibilities. :-)
plugins/wallabag.koplugin/main.lua
Outdated
| keep_menu_open = true, | ||
| callback = function() | ||
| UIManager:show(InfoMessage:new{ | ||
| text = T(_([[Wallabag is an open source Read-it-later service. This plugin synchronises with a Wallabag server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read-it-later should be lowercase
plugins/wallabag.koplugin/main.lua
Outdated
|
|
||
| if isempty(self.server_url) or isempty(self.username) or isempty(self.password) or isempty(self.client_id) or isempty(self.client_secret) or isempty(self.directory) then | ||
| UIManager:show(InfoMessage:new{ | ||
| text = _('Please configure the server and local settings.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotes
plugins/wallabag.koplugin/main.lua
Outdated
| logger.dbg("mode:", dir_mode) | ||
| if dir_mode ~= "directory" then | ||
| UIManager:show(InfoMessage:new{ | ||
| text = _('The download directory is not valid.\nPlease configure it in the settings.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotes
plugins/wallabag.koplugin/main.lua
Outdated
| }) | ||
| return false | ||
| end | ||
| if string.sub( self.directory, -1 ) ~= '/' then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more quotes ;-)
plugins/wallabag.koplugin/main.lua
Outdated
| end | ||
|
|
||
| local login_url = "/oauth/v2/token" | ||
| local body = "{ \"grant_type\": \"password\", \"client_id\": \"" .. self.client_id .. "\", \"client_secret\": \"" .. self.client_secret .. "\", \"username\": \"" .. self.username .. "\", \"password\": \"" .. self.password .. "\"}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet perhaps here there's a good reason to deviate and use single quotes? ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS string.format could potentially be more legible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good shout. A string.format and a [[multiline]] made it a lot neater.
plugins/wallabag.koplugin/main.lua
Outdated
| ["Accept"] = "application/json, */*", | ||
| ["Content-Length"] = tostring(#body), | ||
| } | ||
| local result = self:callAPI( 'POST', login_url, headers, body, "" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to wonder actually, is there a specific rationale behind where you used single and where double quotes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid there was no specific logic in my use of quotes.
I starting by grabbing a few bits of interesting code in other plugins and after a while the inconsistencies spread a bit.
All changed to double quotes and a few multilines.
plugins/wallabag.koplugin/main.lua
Outdated
|
|
||
| function Wallabag:getArticleList() | ||
| local articles_url = "/api/entries.json?archive=0&tags=" .. self.filter_tag | ||
| return self:callAPI( 'GET', articles_url, nil, "", "" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotes
plugins/wallabag.koplugin/main.lua
Outdated
| function Wallabag:callAPI( method, apiurl, headers, body, filepath ) | ||
| local request, sink = {}, {} | ||
| local parsed = url.parse(apiurl) | ||
| request['url'] = self.server_url .. apiurl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more quotes
plugins/wallabag.koplugin/main.lua
Outdated
| logger.dbg("method ", method) | ||
|
|
||
| http.TIMEOUT, https.TIMEOUT = 10, 10 | ||
| local httpRequest = parsed.scheme == 'http' and http.request or https.request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These nits should be the last. Earlier I left a couple of quick comments on my phone for code that "smells" at a glance; these were nitpicks on my laptop. ;-)
plugins/wallabag.koplugin/main.lua
Outdated
| logger.dbg("deleting article ", path ) | ||
| local id = self:getArticleID( path ) | ||
| if id then | ||
| self:callAPI( 'DELETE', "/api/entries/" .. id .. ".json", nil, "", "" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotes
plugins/wallabag.koplugin/main.lua
Outdated
| local text_info = [[Enter the details of your Wallabag server and account. | ||
|
|
||
| Client ID and client secret are long strings so you might prefer to save the empty settings and edit the config file directly: | ||
| .adds/koreader/settings/wallabag.lua |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is Kobo-specific (and even then mainly for KSM), plus I suspect you typod settings? You should populate this with DataStorage:getSettingsDir().
Line 36 in fa0117b
| function DataStorage:getSettingsDir() |
plugins/wallabag.koplugin/main.lua
Outdated
| else | ||
| filter = self.filter_tag | ||
| end | ||
| return _("Filter articles by tag") .. " (" .. filter .. ")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copying my other comment.
Even for stuff like this it's generally preferable to use T().
https://github.com/koreader/koreader/pull/4271/files#r225139189
Double quotes. T(). Multilines.
|
Alright, I'll let it sit a couple more days so feel free to ping me then if I haven't looked on GH yet. @poire-z or just merge it if you think it's ready. ;-) |
|
Looking fine and clean, so merging. |
|
There might be a little something if one has not yet configured this plugin. The menu is still registered and usable thus. koreader/plugins/wallabag.koplugin/main.lua Lines 42 to 45 in a3a17db
Looks like when there is no settings yet, there is no |
Yes, I've reproduced it after deleting the config file. PR to fix it coming up. |
|
The wallabag plugin provides ALMOST 1:1 parity to the pocket integration on the Kobo. This is amazing. Currently, the functionality is focused on server-side deletion post-read. To accommodate maybe more use cases, maybe, there should be an option that only favorited/unread articled be allowed. Triggers activate when the un-stared article is finished to make the "mark as read" api call. On next sync the article will be removed from the device but kept on the server. At that point, the device could also accept permanently retained articles via a "device" tag. |
|
Thanks @bobberb. I have a couple of bugs to fix on the plugin first. Then I'll have a look at your suggestion. |
Marking a document as "finished" is important for Wallabag (see, among others, koreader#4737, koreader#4271). Also it's an obvious missing action. Default to left, up. That keeps with the fullscreen dialog gestures generally go up. Also it was still unassigned.
Marking a document as "finished" is important for Wallabag (see, among others, koreader#4737, koreader#4271). Also it's an obvious missing action. Default to left, up. That keeps with the fullscreen dialog gestures generally go up. Also it was still unassigned.
Marking a document as "finished" is important for Wallabag (see, among others, #4737, #4271). Also it's an obvious missing action. Default to left, up. That keeps with the fullscreen dialog gestures generally go up. Also it was still unassigned. * Remove separator on last item, see #4737 (review)
Marking a document as "finished" is important for Wallabag (see, among others, koreader#4737, koreader#4271). Also it's an obvious missing action. Default to left, up. That keeps with the fullscreen dialog gestures generally go up. Also it was still unassigned. * Remove separator on last item, see koreader#4737 (review)
A plugin to download articles from a Wallabag server, an open source read-it-later service (https://wallabag.org).
Issues:
(solved) The settings menu changes the menu item text for the download directory and the tag filter. It makes it easy to see the current configuration. But I have not found how to refresh the value after a change. I could remove the feature but I'd rather have a hint on how to fix it.
To skip files that already exist locally, I want to check the dates of the local and remote versions. The only date parser is in the newsdownloader plugin. I have added an ugly hack to use it if available. Thoughts?