Fixes for Nextcloud highlights export#14517
Conversation
|
Apologies if you wrote it yourself, but pretty much all of the changes in plugins/exporter.koplugin/base.lua look like AI gibberish. |
Frenzie
left a comment
There was a problem hiding this comment.
In short, these changes look random rather than like the result of actual troubleshooting.
| /.project | ||
| .gitignore~ | ||
|
|
||
| .idea/ |
There was a problem hiding this comment.
This should go near Kate/Vim/VS Code. (It supports Lua?)
| -- Add SSL/TLS settings for HTTPS requests | ||
| if endpoint:match("^https://") then | ||
| request.protocol = "any" | ||
| request.options = {"all", "no_sslv2", "no_sslv3"} | ||
| request.verify = "none" | ||
| request.mode = "client" | ||
| end |
There was a problem hiding this comment.
To be clear, none of this is necessary.
| -- Only add body and content headers when body is present | ||
| if body ~= nil then | ||
| body_json, err = rapidjson.encode(body) | ||
| if not body_json then | ||
| return nil, string.format(msg_failed, | ||
| "cannot encode body" .. err) | ||
| end | ||
| local source = ltn12.source.string(body_json) | ||
| request.source = source | ||
| request.headers["Content-Length"] = #body_json | ||
| request.headers["Content-Type"] = "application/json" | ||
| end |
There was a problem hiding this comment.
Nor is this. It may or may not make sense to stick an "if not body then return/error" at the very top but this doesn't.
| -- Check if request was successful (code == 1 means success in LuaSocket) | ||
| if code ~= 1 then |
| request.headers["Content-Type"] = "application/json" | ||
| end | ||
|
|
||
| socketutil:set_timeout(socketutil.FILE_BLOCK_TIMEOUT, socketutil.FILE_TOTAL_TIMEOUT) |
There was a problem hiding this comment.
This is likely to be the only change that actually does anything.
| -- Add user/password if provided (for Basic Auth) | ||
| -- Manually construct Authorization header since LuaSocket's automatic handling may not work with custom headers | ||
| if user and pass then | ||
| local mime = require("mime") | ||
| local auth = mime.b64(user .. ":" .. pass) | ||
| -- Remove any newlines that mime.b64 might add (for MIME compliance) | ||
| auth = auth:gsub("\r?\n", "") | ||
| extra_headers["Authorization"] = "Basic " .. auth | ||
| end |
There was a problem hiding this comment.
It was already constructed manually in the other file.
| -- Use appropriate request function based on URL scheme | ||
| local request_func = endpoint:match("^https://") and https.request or http.request |
|
Pinging @kotnik @schiessle @pazos regarding the underlying problem. |
0676068 to
7cd2a2a
Compare
|
@Frenzie my apologies, and a brief explanation: this was AI and was quite a few hours of troubleshooting. I was having quite a bit of trouble authenticating against Nextcloud, and eventually (embarrassingly) found that using SSH to update Lua is not a language I'm strongly familiar with, and Koreader is new to me as of about 2 days ago - so I saw Nextcloud integration and REALLY wanted it to work. When I did get it working (password issue was resolved) it was late at night and I found an actual problem with uploading when I had a LOT of highlights in one book, above 6700 characters or so. My excitement to get the fix out and it being late made me rush. I did not give it the time and attention I should have to go back through and clean up dead code that was unneeded. To rectify that, I have restarted and tested that this one line code change is all that is needed to fix large uploads. Again, my apologies for rushing! |
The
Yes, free from all of the other distractions it's an obvious fix. 👍 This is simply how it's supposed to be used. See |
Fixes #13623
Open to feedback!
This change is