Commit 3151842e authored by WorldTeacher's avatar WorldTeacher
Browse files

feat: add file manager hold menu items (sync annotations, match book, sync rating)

parent 21005a69
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -469,7 +469,7 @@ Database.migration_hooks = {
            "manual_sync_only", "sync_mode",
            "historical_sync_ack",
            "booklore_username", "booklore_password",
            "extended_sync_enabled", "rating_sync_enabled", "rating_sync_mode",
            "rating_sync_enabled", "rating_sync_mode",
            "highlights_notes_sync_enabled", "notes_destination", "upload_strategy",
            "auto_update_check", "last_update_check",
        }
@@ -1333,6 +1333,25 @@ function Database:incrementSessionRetryCount(session_id)
    return true
end

function Database:updatePendingSessionBookId(session_id, book_id)
    local stmt = self.conn:prepare([[
        UPDATE pending_sessions
        SET book_id = ?
        WHERE id = ?
    ]])

    if not stmt then
        logger.err("BookloreSync Database: Failed to prepare statement:", self.conn:errmsg())
        return false
    end

    stmt:bind(book_id, session_id)
    stmt:step()
    stmt:close()

    return true
end

function Database:getUnmatchedHistoricalBooks()
    local stmt = self.conn:prepare([[
        SELECT 
+43 −0
Original line number Diff line number Diff line
@@ -149,6 +149,49 @@ function BookloreMetadataExtractor:getModified(doc_path)
    return nil
end

--[[--
Get highlights/annotations from an already-open DocSettings object.

Used when the caller already holds the live in-memory DocSettings (e.g. at
onCloseDocument time, before KOReader flushes to the .sdr sidecar).  This
avoids the stale-read problem that arises when using getHighlights(doc_path),
which opens the on-disk sidecar and therefore misses annotations that were
added during the current session but not yet written to disk.

@param doc_settings DocSettings object (already opened by the caller)
@return table Array of highlights, empty table if nil or no annotations
--]]
function BookloreMetadataExtractor:getHighlightsFromDocSettings(doc_settings)
    if not doc_settings then
        return {}
    end

    local annotations = doc_settings:readSetting("annotations")
    if not annotations or type(annotations) ~= "table" then
        return {}
    end

    local highlights = {}
    for _, annotation in ipairs(annotations) do
        if annotation.text then
            table.insert(highlights, {
                text     = annotation.text,
                note     = annotation.note,
                datetime = annotation.datetime,
                page     = annotation.page,
                chapter  = annotation.chapter,
                color    = annotation.color  or "yellow",
                drawer   = annotation.drawer or "lighten",
                pos0     = annotation.pos0,
                pos1     = annotation.pos1,
            })
        end
    end

    self:log("dbg", "Found", #highlights, "highlights (from live doc_settings)")
    return highlights
end

--[[--
Get highlights for a document

+580 −158

File changed.

Preview size limit exceeded, changes collapsed.