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:
jonny
2026-08-05 17:07:59 +08:00
parent afbb7ac5cc
commit 1361cc15db
10 changed files with 301 additions and 61 deletions
+56 -9
View File
@@ -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)