feat:支持hexo本地访问不增加访问量配置
This commit is contained in:
parent
b2276d041d
commit
9a87940fe9
@ -45,8 +45,8 @@ public class ApplicationController {
|
||||
*/
|
||||
@GetMapping("/visit")
|
||||
@ResponseBody
|
||||
public void visit(HttpServletRequest request, HttpServletResponse response,
|
||||
@NotBlank(message = "回调函数不能为空") String callBack, @NotBlank(message = "key不能为空") String key) throws IOException {
|
||||
applicationService.visit(request, response, callBack, key);
|
||||
public void visit(HttpServletRequest request, HttpServletResponse response, @NotBlank(message = "回调函数不能为空") String callBack
|
||||
, @NotBlank(message = "key不能为空") String key, @NotBlank(message = "path不能为空") String path, boolean notAdd) throws IOException {
|
||||
applicationService.visit(request, response, callBack, key, path, notAdd);
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,10 @@ public interface ApplicationService {
|
||||
* @param response response
|
||||
* @param callBack callBack
|
||||
* @param key key
|
||||
* @param path path
|
||||
* @param notAdd 只返回,不计数
|
||||
* @author fanxb
|
||||
* date 2022/2/16 10:20
|
||||
*/
|
||||
void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key) throws IOException;
|
||||
void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key, String path, boolean notAdd) throws IOException;
|
||||
}
|
||||
|
@ -67,22 +67,7 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key) throws IOException {
|
||||
String refer = request.getHeader("Referer");
|
||||
if (StrUtil.isEmpty(refer)) {
|
||||
throw new CustomBaseException("未获取到来源路径");
|
||||
}
|
||||
String path;
|
||||
try {
|
||||
URL url = new URL(refer);
|
||||
path = StrUtil.isEmpty(url.getPath()) ? "/" : url.getPath();
|
||||
} catch (Exception e) {
|
||||
throw new CustomBaseException("url解析错误", e);
|
||||
}
|
||||
if (path.length() > 100) {
|
||||
throw new CustomBaseException("路径长度不能大于100," + path);
|
||||
}
|
||||
|
||||
public void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key, String path, boolean notAdd) throws IOException {
|
||||
int hostId = getHostId(key);
|
||||
HostPo hostData = hostDao.getUvPvById(hostId);
|
||||
DetailPagePo detailData = detailPageDao.getUvPvById(hostId, path);
|
||||
@ -90,7 +75,9 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
detailData = new DetailPagePo().setHostId(hostId).setPath(path).setUv(0).setPv(0);
|
||||
}
|
||||
//数据计算更新
|
||||
if (!notAdd) {
|
||||
updateData(NetUtil.getClientIp(request), hostData, detailData);
|
||||
}
|
||||
//写出
|
||||
UvPvVo uvPvVo = new UvPvVo(hostData.getUv(), hostData.getPv(), detailData.getUv(), detailData.getPv());
|
||||
String uvPvVoStr = JSON.toJSONString(uvPvVo);
|
||||
@ -101,7 +88,7 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* 更新数据,pv:每次都增加,uv:24小时内同一ip,0-24点只统计一次
|
||||
*
|
||||
* @param ip 来源ip
|
||||
* @param hostPo hostPo
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
(function () {
|
||||
var name = "qieziStatisticHtml";
|
||||
var callback = name + "CallBack";
|
||||
@ -42,14 +41,12 @@
|
||||
key = temp;
|
||||
}
|
||||
}
|
||||
var ignoreLocalhost = window.CONFIG !== undefined && window.CONFIG.web_analytics.qieziStatistics.ignore_local;
|
||||
console.log(requestHost, key);
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
script.src = requestHost +
|
||||
"/qiezi/api/application/visit?callBack=" +
|
||||
callback +
|
||||
"&key=" +
|
||||
key;
|
||||
var notAdd = ignoreLocalhost && ['127.0.0.1', 'localhost'].indexOf(window.location.hostname) > -1;
|
||||
script.src = `${requestHost}/qiezi/api/application/visit?callBack=${callback}&key=${key}&path=${encodeURIComponent(window.location.pathname)}¬Add=${notAdd}`;
|
||||
document.getElementsByTagName("head")[0].appendChild(script);
|
||||
})();
|
||||
|
@ -1 +1 @@
|
||||
(function(){var name="qieziStatisticHtml";var callback=name+"CallBack";window[callback]=function(a){var hostPvNode=document.getElementById(name+"HostPv");if(hostPvNode!=null){document.getElementById(name+"HostPvValue").innerText=a.totalPv;hostPvNode.style.display="inline"}var hostUvNode=document.getElementById(name+"HostUv");if(hostUvNode!=null){document.getElementById(name+"HostUvValue").innerText=a.totalUv;hostUvNode.style.display="inline"}var postNode=document.getElementById(name+"Post");if(postNode!=null){document.getElementById(name+"PostPv").innerText=a.pagePv;postNode.style.display="inline"}};var script=document.createElement("script");script.type="text/javascript";script.defer=true;var requestHost="https://qiezi.fleyx.com";if(window.qieziStatisticHost!=undefined&&window.qieziStatisticHost.trim().length>0){requestHost=window.qieziStatisticHost}else if(window.CONFIG&&window.CONFIG.web_analytics.qieziStatistics.app_host){var temp=window.CONFIG.web_analytics.qieziStatistics.app_host;if(temp.trim().length>0){requestHost=temp}}var key=null;if(window.qieziStatisticKey&&window.qieziStatisticKey.trim().length>0){key=window.qieziStatisticKey}else if(window.CONFIG&&window.CONFIG.web_analytics.qieziStatistics.app_key){var temp=window.CONFIG.web_analytics.qieziStatistics.app_key;if(temp.trim().length>0){key=temp}}console.log(requestHost,key);if(!key){return}script.src=requestHost+"/qiezi/api/application/visit?callBack="+callback+"&key="+key;document.getElementsByTagName("head")[0].appendChild(script)})();
|
||||
(function(){var name="qieziStatisticHtml";var callback=name+"CallBack";window[callback]=function(a){var hostPvNode=document.getElementById(name+"HostPv");if(hostPvNode!=null){document.getElementById(name+"HostPvValue").innerText=a.totalPv;hostPvNode.style.display="inline"}var hostUvNode=document.getElementById(name+"HostUv");if(hostUvNode!=null){document.getElementById(name+"HostUvValue").innerText=a.totalUv;hostUvNode.style.display="inline"}var postNode=document.getElementById(name+"Post");if(postNode!=null){document.getElementById(name+"PostPv").innerText=a.pagePv;postNode.style.display="inline"}};var script=document.createElement("script");script.type="text/javascript";script.defer=true;var requestHost="https://qiezi.fleyx.com";if(window.qieziStatisticHost!==undefined&&window.qieziStatisticHost.trim().length>0){requestHost=window.qieziStatisticHost}else if(window.CONFIG&&window.CONFIG.web_analytics.qieziStatistics.app_host){var temp=window.CONFIG.web_analytics.qieziStatistics.app_host;if(temp.trim().length>0){requestHost=temp}}var key=null;if(window.qieziStatisticKey&&window.qieziStatisticKey.trim().length>0){key=window.qieziStatisticKey}else if(window.CONFIG&&window.CONFIG.web_analytics.qieziStatistics.app_key){var temp=window.CONFIG.web_analytics.qieziStatistics.app_key;if(temp.trim().length>0){key=temp}}var ignoreLocalhost=window.CONFIG!==undefined&&window.CONFIG.web_analytics.qieziStatistics.ignore_local;console.log(requestHost,key);if(!key){return}var notAdd=ignoreLocalhost&&['127.0.0.1','localhost'].indexOf(window.location.hostname)>-1;script.src="".concat(requestHost,"/qiezi/api/application/visit?callBack=").concat(callback,"&key=").concat(key,"&path=").concat(encodeURIComponent(window.location.pathname),"¬Add=").concat(notAdd);document.getElementsByTagName("head")[0].appendChild(script)})();
|
||||
|
Loading…
x
Reference in New Issue
Block a user