From 4e7e0fd196f9800debeeeecce806427e2e379cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=B8=E4=B9=8B?= <76784216+yozi9257@users.noreply.github.com> Date: Thu, 27 Feb 2025 15:36:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A0=87=E7=AD=BE=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现标签从用户最近1000条memo中提取 --- js/oper.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/js/oper.js b/js/oper.js index 5554a4e..14e4d2f 100644 --- a/js/oper.js +++ b/js/oper.js @@ -293,14 +293,12 @@ $('#opensite').click(function () { }) // 0.23.1版本 GET api/v1/{parent}/tags 接口已移除,参考 https://github.com/usememos/memos/issues/4161 -// TODO 可使用/api/v1/memos?filter=creator == 'users/1'&view=MEMO_VIEW_METADATA_ONLY 接口实现 $('#tags').click(function () { get_info(function (info) { if (info.apiUrl) { - var parent = "memos/-"; - // 如果不使用 user 过滤,会返回所有用户的标签 - var filter = "?filter=" + encodeURIComponent(`creator == 'users/${info.userid}'`); - var tagUrl = info.apiUrl + 'api/v1/' + parent + '/tags' + filter; + var parent = `users/${info.userid}`; + // 从最近的1000条memo中获取tags,因此不保证获取能全部的 + var tagUrl = info.apiUrl + 'api/v1/' + parent + '/memos?pageSize=1000'; var tagDom = ""; $.ajax({ url: tagUrl, @@ -309,7 +307,10 @@ $('#tags').click(function () { dataType: "json", headers: { 'Authorization': 'Bearer ' + info.apiTokens }, success: function (data) { - $.each(data.tagAmounts, function (tag, amount) { + // 提前并去重所有标签 + const allTags = data.memos.flatMap(memo => memo.tags); + const uniTags = [...new Set(allTags)]; + $.each(uniTags, function (_, tag) { tagDom += '#' + tag + ''; }); tagDom += ''