Skip to content

Fixes for Nextcloud highlights export#14517

Merged
Frenzie merged 1 commit into
koreader:masterfrom
wylanswets:nextcloud-fixes
Oct 27, 2025
Merged

Fixes for Nextcloud highlights export#14517
Frenzie merged 1 commit into
koreader:masterfrom
wylanswets:nextcloud-fixes

Conversation

@wylanswets

@wylanswets wylanswets commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

Fixes #13623

  • Fixed huge exports not working due to sink[1] reference.

Open to feedback!


This change is Reviewable

@Frenzie

Frenzie commented Oct 27, 2025

Copy link
Copy Markdown
Member

Apologies if you wrote it yourself, but pretty much all of the changes in plugins/exporter.koplugin/base.lua look like AI gibberish.

@Frenzie Frenzie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In short, these changes look random rather than like the result of actual troubleshooting.

Comment thread .gitignore Outdated
/.project
.gitignore~

.idea/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go near Kate/Vim/VS Code. (It supports Lua?)

Comment thread plugins/exporter.koplugin/base.lua Outdated
Comment on lines +178 to +184
-- 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, none of this is necessary.

Comment thread plugins/exporter.koplugin/base.lua Outdated
Comment on lines +196 to +207
-- 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread plugins/exporter.koplugin/base.lua Outdated
Comment on lines +221 to +222
-- Check if request was successful (code == 1 means success in LuaSocket)
if code ~= 1 then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nonsense.

Comment thread plugins/exporter.koplugin/base.lua Outdated
request.headers["Content-Type"] = "application/json"
end

socketutil:set_timeout(socketutil.FILE_BLOCK_TIMEOUT, socketutil.FILE_TOTAL_TIMEOUT)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely to be the only change that actually does anything.

Comment thread plugins/exporter.koplugin/base.lua Outdated
Comment on lines +186 to +194
-- 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already constructed manually in the other file.

Comment thread plugins/exporter.koplugin/base.lua Outdated
Comment on lines +216 to +217
-- Use appropriate request function based on URL scheme
local request_func = endpoint:match("^https://") and https.request or http.request

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary.

@Frenzie Frenzie added the Plugin label Oct 27, 2025
@Frenzie

Frenzie commented Oct 27, 2025

Copy link
Copy Markdown
Member

Pinging @kotnik @schiessle @pazos regarding the underlying problem.

@wylanswets

Copy link
Copy Markdown
Contributor Author

@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 settings.reader.lua did not actually take the latest app specific password along the way. Somehow the old password stuck.

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!

@Frenzie Frenzie merged commit 95b2edb into koreader:master Oct 27, 2025
4 checks passed
@Frenzie Frenzie added this to the 2025.10 milestone Oct 27, 2025
@Frenzie

Frenzie commented Oct 27, 2025

Copy link
Copy Markdown
Member

I was having quite a bit of trouble authenticating against Nextcloud, and eventually (embarrassingly) found that using SSH to update settings.reader.lua did not actually take the latest app specific password along the way. Somehow the old password stuck.

The settings.reader.lua file is read on start and written on exit. There may or may not be other times it's written, but it'll never be read at any other time. :-)

To rectify that, I have restarted and tested that this one line code change is all that is needed to fix large uploads.

Yes, free from all of the other distractions it's an obvious fix. 👍 This is simply how it's supposed to be used. See table.concat(sink) many times in the code here and of course with an explanation about data chunks in the LuaSocket documentation.

0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nextcloud export

3 participants