修复标签获取功能

现标签从用户最近1000条memo中提取
This commit is contained in:
游之
2025-02-27 15:36:47 +08:00
committed by GitHub
parent 1604fb7645
commit 4e7e0fd196
+7 -6
View File
@@ -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 += '<span class="item-container">#' + tag + '</span>';
});
tagDom += '<svg id="hideTag" class="hidetag" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M78.807 362.435c201.539 314.275 666.962 314.188 868.398-.241 16.056-24.99 13.143-54.241-4.04-62.54-17.244-8.377-40.504 3.854-54.077 24.887-174.484 272.338-577.633 272.41-752.19.195-13.573-21.043-36.874-33.213-54.113-24.837-17.177 8.294-20.06 37.545-3.978 62.536z" fill="#fff"/><path d="M894.72 612.67L787.978 494.386l38.554-34.785 106.742 118.251-38.554 34.816zM635.505 727.51l-49.04-147.123 49.255-16.41 49.054 147.098-49.27 16.435zm-236.18-12.001l-49.568-15.488 43.29-138.48 49.557 15.513-43.28 138.455zM154.49 601.006l-38.743-34.565 95.186-106.732 38.763 34.566-95.206 106.731z" fill="#fff"/></svg>'