mirror of
https://github.com/Jonnyan404/memos-bber.git
synced 2026-08-23 00:41:39 +09:00
Fix tags display and Memos API compatibility issues
Fix the tags not displaying issue by querying both /tag/suggestion and /tag endpoints and merging results. Simplify v0.23 filter to avoid 400 errors from numeric ID requirements. Add v0.18.2 support via numeric ID fallback in getMemoUid. Improve v0.23+ resource URL handling and add better error handling with debug logging for tags and random features.
This commit is contained in:
@@ -249,10 +249,10 @@
|
||||
}
|
||||
|
||||
if (flavor === 'v023' && global.MemosApiV023) {
|
||||
const filterExpr = global.MemosApiV023.buildFilter({
|
||||
rowStatus: 'NORMAL',
|
||||
creator: 'users/' + info.userid
|
||||
})
|
||||
// v0.23 filter requires `creator == "users/{numericId}"`. Some stored userids are
|
||||
// usernames, which causes 400. Also `row_status` can cause 400 on some builds.
|
||||
// Let the server identify the current user from the token and return all visible memos.
|
||||
const filterExpr = global.MemosApiV023.buildFilter({})
|
||||
global.MemosApiV023.listMemos(
|
||||
info,
|
||||
{ pageSize: 1000, filterExpr: filterExpr },
|
||||
@@ -328,7 +328,10 @@
|
||||
|
||||
if (flavor === FLAVOR_V020_V021 && global.MemosApiV020V021) {
|
||||
global.MemosApiV020V021.listMemos(info, { limit: 1000, rowStatus: 'NORMAL' }, function (data) {
|
||||
if (success) success(keepLegacyVisibleMemos(extractMemos(data)))
|
||||
const raw = extractMemos(data)
|
||||
const filtered = keepLegacyVisibleMemos(raw)
|
||||
console.log('[memos-bber] v020-v021 random raw count:', raw.length, 'filtered count:', filtered.length)
|
||||
if (success) success(filtered)
|
||||
}, fail)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -201,22 +201,69 @@
|
||||
|
||||
function getTagSuggestion(info, success, fail) {
|
||||
const headers = { Authorization: 'Bearer ' + info.apiTokens }
|
||||
|
||||
function normalizeTagList(data) {
|
||||
const list = Array.isArray(data) ? data : Array.isArray(data.tags) ? data.tags : []
|
||||
return list
|
||||
.map(function (t) {
|
||||
if (!t) return ''
|
||||
if (typeof t === 'string') return t
|
||||
if (typeof t.name === 'string') return t.name
|
||||
if (typeof t.tag === 'string') return t.tag
|
||||
return ''
|
||||
})
|
||||
.map(function (s) {
|
||||
return String(s).replace(/^#/, '').trim()
|
||||
})
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
function normalizeSuggestionList(data) {
|
||||
const list = Array.isArray(data) ? data : []
|
||||
return list
|
||||
.map(function (s) {
|
||||
return String(s).replace(/^#/, '').trim()
|
||||
})
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
function mergeUnique(a, b) {
|
||||
return [...new Set((a || []).concat(b || []))]
|
||||
}
|
||||
|
||||
let suggestionList = []
|
||||
let listList = []
|
||||
let pending = 2
|
||||
|
||||
function finish() {
|
||||
if (--pending !== 0) return
|
||||
if (success) success(mergeUnique(suggestionList, listList))
|
||||
}
|
||||
|
||||
requestGet(
|
||||
info.apiUrl + 'api/v1/tag/suggestion',
|
||||
headers,
|
||||
function (data) {
|
||||
const list = Array.isArray(data) ? data : []
|
||||
const out = list
|
||||
.map(function (s) {
|
||||
return String(s).replace(/^#/, '').trim()
|
||||
})
|
||||
.filter(Boolean)
|
||||
if (success) success(out)
|
||||
suggestionList = normalizeSuggestionList(data)
|
||||
finish()
|
||||
},
|
||||
function (xhr) {
|
||||
// Ignore failures from the suggestion endpoint; the list endpoint may still work.
|
||||
if (xhr && xhr.status !== 404 && xhr.status !== 405 && fail) fail(xhr)
|
||||
else finish()
|
||||
}
|
||||
)
|
||||
|
||||
requestGet(
|
||||
info.apiUrl + 'api/v1/tag',
|
||||
headers,
|
||||
function (data) {
|
||||
listList = normalizeTagList(data)
|
||||
finish()
|
||||
},
|
||||
function (xhr) {
|
||||
// Some forks might only expose list.
|
||||
if (isNotFoundLikeXhr(xhr)) {
|
||||
getTagList(info, success, fail)
|
||||
finish()
|
||||
return
|
||||
}
|
||||
if (fail) fail(xhr)
|
||||
|
||||
Reference in New Issue
Block a user