Refactor lean-analytics.swig to use REST API to avoid conflicts with valine#381
Refactor lean-analytics.swig to use REST API to avoid conflicts with valine#381LEAFERx merged 4 commits intotheme-next:masterfrom LEAFERx:master
Conversation
| url: `https://api.leancloud.cn/1.1${url}`, | ||
| headers: { | ||
| 'X-LC-Id': "{{theme.leancloud_visitors.app_id}}", | ||
| 'X-LC-Key': "{{theme.leancloud_visitors.app_key}}", |
There was a problem hiding this comment.
建议使用 X-LC-Sign 来代替 X-LC-Key
https://leancloud.cn/docs/rest_api.html#hash-1794863242
There was a problem hiding this comment.
md5需要引入额外的库 我觉得在https下安全性是没有问题的 而且其实apikey是暴露的 也没有必要
| var Counter = function (method, url, data) { | ||
| return $.ajax({ | ||
| method: method, | ||
| url: `https://api.leancloud.cn/1.1${url}`, |
There was a problem hiding this comment.
api.leancloud.cn 这个域名在某些地区无法解析,建议换成应用专属的二级域名
https://forum.leancloud.cn/t/leancloud-api/16234
| $element.find('.leancloud-visitors-count').text(counter.time + 1); | ||
| }) | ||
| {% endif %} | ||
| .fail(function (error) { |
There was a problem hiding this comment.
这个 error 是 XHR 层面的异常了,LeanCloud 业务层面的异常还需要再拆一层,异常 response body 结构是这样的:
{"code":119,"error":"该操作已被禁止,请变更应用选项『数据存储』。"}
| } else if ($('.post-title-link').length > 1) { | ||
| showTime(Counter); | ||
| } | ||
| $.get('https://app-router.leancloud.cn/2/route?appId=' + "{{theme.leancloud_visitors.app_id}}") |
There was a problem hiding this comment.
其实只要把 xxx.api.lncld.net 前缀改成 APPID.slice(0, 8).toLowerCase() 就行了,没必要多发一次请求,就是不知道以后会不会变 @leeyeh
There was a problem hiding this comment.
还是有必要的,因为华东节点、美国节点用的域名不是 lncld.net。使用 app-router 机制动态获取域名也是为了避免之前写死了 api.leancloud.cn 被污染后没有任何办法的问题。
|
@Raincal 如果可以请approve或直接merge |
|
@Raincal 已解决 |
…valine (theme-next#381) * Refactor lean-analytics.swig to use REST API to avoid conflicts with valine * update api url * fix error message * distinguish index and post
…valine (theme-next#381) * Refactor lean-analytics.swig to use REST API to avoid conflicts with valine * update api url * fix error message * distinguish index and post
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number(s): #376
Does this PR introduce a breaking change?