Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
soxft committed May 18, 2022
2 parents a4f3045 + 7678b6f commit 2ed37ff
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/middleware/access_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func AccessControl() gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", config.C.Web.AcAo)
c.Header("Server", "busuanzi-by-xcsoft/2.0")
c.Header("Server", "busuanzi-by-xcsoft/2.2")
if c.Request.Method == "OPTIONS" {
c.Header("Access-Control-Allow-Methods", "GET,POST,HEAD,OPTIONS")
c.Header("Access-Control-Allow-Headers", "x-bsz-referer")
Expand Down
14 changes: 9 additions & 5 deletions core/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ func Count(host string, path string, ip string) (int, int, int, int) {

siteUv, _ := redis.Int(_redis.Do("SCARD", siteUvKey))
pageUv, _ := redis.Int(_redis.Do("SCARD", pageUvKey))
setExpire(_redis, sitePvKey, siteUvKey, pagePvKey, pageUvKey)
go setExpire(sitePvKey, siteUvKey, pagePvKey, pageUvKey)

return sitePv, siteUv, pagePv, pageUv
}

func setExpire(redis redis.Conn, key ...string) {
func setExpire(key ...string) {
var _redis = redisutil.Pool.Get()
defer func(_redis redis.Conn) {
_ = _redis.Close()
}(_redis)
// multi-set expire
_, _ = redis.Do("MULTI")
_, _ = _redis.Do("MULTI")
for _, k := range key {
_, _ = redis.Do("EXPIRE", k, config.C.Bsz.Expire)
_, _ = _redis.Do("EXPIRE", k, config.C.Bsz.Expire)
}
_, _ = redis.Do("EXEC")
_, _ = _redis.Do("EXEC")
}
9 changes: 3 additions & 6 deletions dist/busuanzi.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(function () {
var url = "http://127.0.0.1:8080/api";
var tags = ["site_pv", "site_uv", "page_pv", "page_uv"];
var url = "http://127.0.0.1:8080/api", tags = ["site_pv", "site_uv", "page_pv", "page_uv"], current = document.currentScript, pjax = current.hasAttribute("data-pjax"), api = current.getAttribute("data-api") || url;
var bsz_send = function () {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.open("POST", api, true);
xhr.setRequestHeader("x-bsz-referer", window.location.href);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
Expand All @@ -22,9 +21,7 @@
xhr.send();
};
bsz_send();
var current = document.currentScript;
var pjax = current.hasAttribute("data-pjax");
if (pjax === true) {
if (!!pjax) {
var history_pushState_1 = window.history.pushState;
window.history.pushState = function () {
history_pushState_1.apply(this, arguments);
Expand Down
14 changes: 7 additions & 7 deletions dist/busuanzi.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
(function (){
let url: string = "http://127.0.0.1:8080/api";
let tags: string[] = ["site_pv", "site_uv", "page_pv", "page_uv"];
let url: string = "http://127.0.0.1:8080/api",
tags: string[] = ["site_pv", "site_uv", "page_pv", "page_uv"],
current: HTMLOrSVGScriptElement = document.currentScript,
pjax: boolean = current.hasAttribute("data-pjax"),
api: string = current.getAttribute("data-api") || url;

let bsz_send: Function = function () {
let xhr: XMLHttpRequest = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.open("POST", api, true);

xhr.setRequestHeader("x-bsz-referer", window.location.href);
xhr.onreadystatechange = function () {
Expand All @@ -24,10 +27,7 @@
};
bsz_send();

let current: HTMLOrSVGScriptElement = document.currentScript;
let pjax: boolean = current.hasAttribute("data-pjax");

if (pjax === true) {
if (!!pjax) {
let history_pushState: Function = window.history.pushState;
window.history.pushState = function () {
history_pushState.apply(this, arguments);
Expand Down

0 comments on commit 2ed37ff

Please sign in to comment.