🐛 (notes): 想法按私密阅读设置发表并回读
新想法跟这本书的私密阅读走,修改已有想法沿用原来的可见范围。 回读对不上就当这轮失败,不把 HTTP 成功当成已经私密。
This commit is contained in:
1 parent
69a72f63c0
commit
352ee1bd99
11 files changed
+359
-57
No files matched your search
@@ -33,7 +33,7 @@ local LOCAL_COLOR = {
|
||||
}
|
||||
|
||||
local WR_FIELDS = {
|
||||
"wr_range", "wr_bookmark_id", "wr_review_id", "wr_review_only",
|
||||
"wr_range", "wr_bookmark_id", "wr_review_id", "wr_review_only", "wr_private",
|
||||
"wr_delete_review", "wr_update_review", "wr_update_bookmark",
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ local WR_FIELDS = {
|
||||
---@field wr_bookmark_id string|number|nil
|
||||
---@field wr_range string|nil
|
||||
---@field wr_review_id string|number|nil
|
||||
---@field wr_private integer|nil 0 公开,1 仅自己可见
|
||||
---@field wr_deleted boolean|nil
|
||||
---@field chapter_idx number|nil
|
||||
---@field datetime string|nil
|
||||
@@ -76,6 +77,31 @@ local function unwrapReview(entry)
|
||||
return type(review) == "table" and review or nil
|
||||
end
|
||||
|
||||
--- 想法上的 ``isPrivate``:1 仅自己可见,0 公开。没有这个字段就返回 nil,不能当成公开。
|
||||
---@param review table|nil
|
||||
---@return integer|nil
|
||||
function Notes.privateOf(review)
|
||||
if type(review) ~= "table" then return nil end
|
||||
local body = type(review.review) == "table" and review.review or review
|
||||
local flag = body.isPrivate
|
||||
if flag == 1 or flag == true then return 1 end
|
||||
if flag == 0 or flag == false then return 0 end
|
||||
return nil
|
||||
end
|
||||
|
||||
--- 发表/修改要带的 ``isPrivate``。已有想法没记过可见范围时返回 nil,请求里就不带这个字段。
|
||||
---@param annotation table
|
||||
---@param book_secret integer|boolean|nil 书籍 ``secret==1`` 表示私密阅读
|
||||
---@return integer|nil
|
||||
function Notes.reviewIsPrivate(annotation, book_secret)
|
||||
local known = annotation.wr_private
|
||||
if known == 1 or known == true then return 1 end
|
||||
if known == 0 or known == false then return 0 end
|
||||
if annotation.wr_review_id ~= nil then return nil end
|
||||
if book_secret == 1 or book_secret == true then return 1 end
|
||||
return 0
|
||||
end
|
||||
|
||||
---@param items table[]|nil
|
||||
---@param total_pages integer|nil
|
||||
---@return table[]
|
||||
@@ -452,6 +478,10 @@ function Notes.reconcileReviews(annotations, wire)
|
||||
end
|
||||
if review then
|
||||
item.wr_review_id = review.reviewId
|
||||
if item.wr_private ~= 0 and item.wr_private ~= 1 then
|
||||
local private = Notes.privateOf(review)
|
||||
if private ~= nil then item.wr_private = private end
|
||||
end
|
||||
confirmed[item] = true
|
||||
end
|
||||
end
|
||||
@@ -517,6 +547,8 @@ function Notes.toAnnotations(wire, chapter_uid, reviews, source_id, stable_id)
|
||||
ann.wr_range = range ~= "" and range or nil
|
||||
ann.wr_bookmark_id = row.bookmarkId or row.id
|
||||
ann.wr_review_id = review and review.reviewId or nil
|
||||
local private = review and Notes.privateOf(review) or nil
|
||||
if private ~= nil then ann.wr_private = private end
|
||||
out[#out + 1] = ann
|
||||
end
|
||||
end
|
||||
@@ -538,6 +570,8 @@ function Notes.toAnnotations(wire, chapter_uid, reviews, source_id, stable_id)
|
||||
ann.note = content
|
||||
ann.wr_range = range
|
||||
ann.wr_review_id = review.reviewId or entry.reviewId
|
||||
local private = Notes.privateOf(review)
|
||||
if private ~= nil then ann.wr_private = private end
|
||||
ann.wr_review_only = true
|
||||
out[#out + 1] = ann
|
||||
end
|
||||
@@ -561,7 +595,7 @@ function Notes.keepLocalReviews(annotations, local_items)
|
||||
if type(old) == "table" and old.wr_review_id and not known[tostring(old.wr_review_id)] then
|
||||
local ann = old.wr_bookmark_id and by_bookmark[tostring(old.wr_bookmark_id)] or nil
|
||||
if ann then
|
||||
ann.note, ann.wr_review_id = old.note, old.wr_review_id
|
||||
ann.note, ann.wr_review_id, ann.wr_private = old.note, old.wr_review_id, old.wr_private
|
||||
elseif old.wr_review_only then
|
||||
annotations[#annotations + 1] = old
|
||||
end
|
||||
@@ -672,13 +706,15 @@ function Notes.toBookmarkUpdateBody(annotation)
|
||||
}
|
||||
end
|
||||
|
||||
--- KOReader 注解 → ``/web/review/add`` 请求体。
|
||||
--- KOReader 注解 → ``/review/add`` 请求体。
|
||||
--- 新想法:私密阅读的书 ``isPrivate=1``,否则 ``0``。已有想法沿用 ``wr_private``。
|
||||
---@param book_id string
|
||||
---@param chapter_uid string|number
|
||||
---@param annotation table
|
||||
---@param book_secret integer|boolean|nil
|
||||
---@return table|nil body
|
||||
---@return string|nil err
|
||||
function Notes.toReviewBody(book_id, chapter_uid, annotation)
|
||||
function Notes.toReviewBody(book_id, chapter_uid, annotation, book_secret)
|
||||
local content = annotation.note
|
||||
if type(content) ~= "string" or content == "" then
|
||||
return nil, "empty note"
|
||||
@@ -691,28 +727,32 @@ function Notes.toReviewBody(book_id, chapter_uid, annotation)
|
||||
if type(abstract) ~= "string" or abstract == "" then
|
||||
return nil, "missing highlight text"
|
||||
end
|
||||
return {
|
||||
local body = {
|
||||
bookId = tostring(book_id),
|
||||
content = content,
|
||||
type = 1,
|
||||
range = range,
|
||||
abstract = abstract,
|
||||
chapterUid = tonumber(chapter_uid) or chapter_uid,
|
||||
}, nil
|
||||
}
|
||||
local private = Notes.reviewIsPrivate(annotation, book_secret)
|
||||
if private ~= nil then body.isPrivate = private end
|
||||
return body, nil
|
||||
end
|
||||
|
||||
--- KOReader 注解 → ``/web/review/edit`` 请求体。
|
||||
--- KOReader 注解 → ``/review/useredit`` 请求体。
|
||||
---@param book_id string
|
||||
---@param chapter_uid string|number
|
||||
---@param annotation table
|
||||
---@param book_secret integer|boolean|nil
|
||||
---@return table|nil body
|
||||
---@return string|nil err
|
||||
function Notes.toReviewEditBody(book_id, chapter_uid, annotation)
|
||||
function Notes.toReviewEditBody(book_id, chapter_uid, annotation, book_secret)
|
||||
local review_id = annotation.wr_review_id
|
||||
if type(review_id) ~= "string" and type(review_id) ~= "number" then
|
||||
return nil, "missing review id"
|
||||
end
|
||||
local body, err = Notes.toReviewBody(book_id, chapter_uid, annotation)
|
||||
local body, err = Notes.toReviewBody(book_id, chapter_uid, annotation, book_secret)
|
||||
if not body then return nil, err end
|
||||
body.reviewId = tostring(review_id)
|
||||
return body, nil
|
||||
|
||||
Reference in new issue
Block a user