diff --git a/js/oper.js b/js/oper.js index 22d9dc2..14e4d2f 100644 --- a/js/oper.js +++ b/js/oper.js @@ -192,10 +192,12 @@ function uploadImageNow(base64String, file) { dataType: 'json', headers: { 'Authorization': 'Bearer ' + info.apiTokens }, success: function (data) { - if (data.uid) { + // 0.24 版本+ 返回体uid已合并到name字段 + if (data.name) { + // 更新上传的文件信息并暂存浏览器本地 relistNow.push({ "name":data.name, - "uid":data.uid, + "createTime":data.createTime, "type":data.type }) chrome.storage.sync.set( @@ -253,13 +255,15 @@ $('#saveKey').click(function () { }; $.ajax(settings).done(function (response) { - if (response && response.id) { - // 如果响应包含用户 ID,存储 apiUrl 和 apiTokens + // 0.24 版本后无 id 字段,改为从 name 字段获取和判断认证是否成功 + if (response && response.name) { + // 如果响应包含用户name "users/{id}",存储 apiUrl 和 apiTokens + var userid = parseInt(response.name.split('/').pop(), 10) chrome.storage.sync.set( { apiUrl: apiUrl, apiTokens: apiTokens, - userid: response.id + userid: userid }, function () { $.message({ @@ -288,22 +292,25 @@ $('#opensite').click(function () { }) }) +// 0.23.1版本 GET api/v1/{parent}/tags 接口已移除,参考 https://github.com/usememos/memos/issues/4161 $('#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, type: "GET", - contentType: "application/json;", + contentType: "application/json", 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 += '' @@ -354,15 +361,16 @@ $(document).on("click",".item-lock",function () { $('#search').click(function () { get_info(function (info) { const pattern = $("textarea[name=text]").val() - var filter = "?filter=" + encodeURIComponent(`creator == 'users/${info.userid}' && visibilities == ['PUBLIC', 'PROTECTED'] && content_search == ['${pattern}']`); + var parent = `users/${info.userid}`; + var filter = "?filter=" + encodeURIComponent(`visibility in ["PUBLIC","PROTECTED"] && content.contains("${pattern}")`); if (info.status) { $("#randomlist").html('').hide() var searchDom = "" if(pattern){ $.ajax({ - url:info.apiUrl+"api/v1/memos"+filter, + url:info.apiUrl+"api/v1/"+parent+"/memos"+filter, type:"GET", - contentType:"application/json;", + contentType:"application/json", dataType:"json", headers : {'Authorization':'Bearer ' + info.apiTokens}, success: function(data){ @@ -373,7 +381,8 @@ $('#search').click(function () { }) }else{ for(var i=0;i < searchData.length;i++){ - searchDom += '