From 71d5452610592a6f2d8f2583a0c6beb645b6b632 Mon Sep 17 00:00:00 2001 From: Yozi <76784216+yozi9257@users.noreply.github.com> Date: Fri, 21 Feb 2025 16:22:32 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=80=82=E9=85=8D=20memos=200.24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/oper.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/js/oper.js b/js/oper.js index 22d9dc2..66c910c 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) { + var resUid = data.name.split('/').pop() relistNow.push({ "name":data.name, - "uid":data.uid, + "uid":resUid, "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,6 +292,8 @@ $('#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) { @@ -668,4 +674,4 @@ function sendText() { }) } }) -} \ No newline at end of file +} From 5628aecd955f34cb8ad82c665e763a7aea678334 Mon Sep 17 00:00:00 2001 From: ShenqPerng Date: Fri, 21 Feb 2025 22:04:29 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E4=B8=8E=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD=E9=80=82=E9=85=8D=20v0.24=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E5=85=BC=E5=AE=B9=E6=97=A7=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/oper.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/js/oper.js b/js/oper.js index 66c910c..854a662 100644 --- a/js/oper.js +++ b/js/oper.js @@ -305,7 +305,7 @@ $('#tags').click(function () { $.ajax({ url: tagUrl, type: "GET", - contentType: "application/json;", + contentType: "application/json", dataType: "json", headers: { 'Authorization': 'Bearer ' + info.apiTokens }, success: function (data) { @@ -360,15 +360,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){ @@ -379,7 +380,8 @@ $('#search').click(function () { }) }else{ for(var i=0;i < searchData.length;i++){ - searchDom += '
'+dayjs(searchData.createTime).fromNow()+'
'+searchData[i].content.replace(/!\[.*?\]\((.*?)\)/g,' ').replace(/\[(.*?)\]\((.*?)\)/g,' $1 ')+'
' + var memosID = searchData[i].name.split('/').pop(); + searchDom += '
'+dayjs(searchData.createTime).fromNow()+'
'+searchData[i].content.replace(/!\[.*?\]\((.*?)\)/g,' ').replace(/\[(.*?)\]\((.*?)\)/g,' $1 ')+'
' if(searchData[i].resources && searchData[i].resources.length > 0){ var resources = searchData[i].resources; for(var j=0;j < resources.length;j++){ @@ -422,14 +424,15 @@ $('#search').click(function () { $('#random').click(function () { get_info(function (info) { - var filter = "?filter=" + encodeURIComponent(`creator == 'users/${info.userid}'`); + var parent = `users/${info.userid}`; + var filter = "?filter=" + encodeURIComponent(`visibility in ["PUBLIC","PROTECTED"]`); if (info.status) { $("#randomlist").html('').hide() - var randomUrl = info.apiUrl + 'api/v1/memos' + filter; + var randomUrl = info.apiUrl + "api/v1/" +parent + "/memos" + filter; $.ajax({ url:randomUrl, type:"GET", - contentType:"application/json;", + contentType:"application/json", dataType:"json", headers : {'Authorization':'Bearer ' + info.apiTokens}, success: function(data){ @@ -448,7 +451,8 @@ $('#random').click(function () { function randDom(randomData){ get_info(function (info) { - var randomDom = '
'+dayjs(randomData.createTime).fromNow()+'
'+randomData.content.replace(/!\[.*?\]\((.*?)\)/g,' ').replace(/\[(.*?)\]\((.*?)\)/g,' $1 ')+'
' + var memosID = randomData.name.split('/').pop(); + var randomDom = '
'+dayjs(randomData.createTime).fromNow()+'
'+randomData.content.replace(/!\[.*?\]\((.*?)\)/g,' ').replace(/\[(.*?)\]\((.*?)\)/g,' $1 ')+'
' if(randomData.resources && randomData.resources.length > 0){ var resources = randomData.resources; for(var j=0;j < resources.length;j++){ @@ -484,17 +488,17 @@ $(document).on("click","#random-link",function () { $(document).on("click","#random-delete",function () { get_info(function (info) { - var memoUid = $("#random-delete").data('uid'); + // var memoUid = $("#random-delete").data('uid'); var memosName = $("#random-delete").data('name'); var deleteUrl = info.apiUrl+'api/v1/'+memosName $.ajax({ url:deleteUrl, type:"PATCH", data:JSON.stringify({ - 'uid': memoUid, - 'rowStatus': "ARCHIVED" + // 'uid': memoUid, + 'state': "ARCHIVED" }), - contentType:"application/json;", + contentType:"application/json", dataType:"json", headers : {'Authorization':'Bearer ' + info.apiTokens}, success: function(result){ @@ -585,7 +589,7 @@ function getOne(memosId){ $.ajax({ url:getUrl, type:"GET", - contentType:"application/json;", + contentType:"application/json", dataType:"json", headers : {'Authorization':'Bearer ' + info.apiTokens}, success: function(data){ @@ -626,7 +630,7 @@ function sendText() { 'content': content, 'visibility': sendvisi }), - contentType:"application/json;", + contentType:"application/json", dataType:"json", headers : {'Authorization':'Bearer ' + info.apiTokens}, success: function(data){ @@ -638,7 +642,7 @@ function sendText() { data:JSON.stringify({ 'resources': info.resourceIdList || [], }), - contentType:"application/json;", + contentType:"application/json", dataType:"json", headers : {'Authorization':'Bearer ' + info.apiTokens}, success: function(res){ From 1604fb76454c855ee92e360716dba9c349ef2294 Mon Sep 17 00:00:00 2001 From: ShenqPerng Date: Fri, 21 Feb 2025 22:38:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=80=82=E9=85=8D=20v0.24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/oper.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/oper.js b/js/oper.js index 854a662..5554a4e 100644 --- a/js/oper.js +++ b/js/oper.js @@ -194,10 +194,10 @@ function uploadImageNow(base64String, file) { success: function (data) { // 0.24 版本+ 返回体uid已合并到name字段 if (data.name) { - var resUid = data.name.split('/').pop() + // 更新上传的文件信息并暂存浏览器本地 relistNow.push({ "name":data.name, - "uid":resUid, + "createTime":data.createTime, "type":data.type }) chrome.storage.sync.set( @@ -637,7 +637,7 @@ function sendText() { if(info.resourceIdList.length > 0 ){ //匹配图片 $.ajax({ - url:info.apiUrl+'api/v1/'+data.name+'/resources', + url:info.apiUrl+'api/v1/'+data.name, type:"PATCH", data:JSON.stringify({ 'resources': info.resourceIdList || [], @@ -653,7 +653,7 @@ function sendText() { getOne(data.name) } chrome.storage.sync.set( - { open_action: '', open_content: '',resourceIdList:''}, + { open_action: '', open_content: '',resourceIdList:[]}, function () { $.message({ message: chrome.i18n.getMessage("memoSuccess") @@ -664,7 +664,7 @@ function sendText() { ) },error:function(err){//清空open_action(打开时候进行的操作),同时清空open_content chrome.storage.sync.set( - { open_action: '', open_content: '',resourceIdList:'' }, + { open_action: '', open_content: '',resourceIdList:[] }, function () { $.message({ message: chrome.i18n.getMessage("memoFailed") 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 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E8=8E=B7=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 += ''