Compare commits

..

2 Commits

Author SHA1 Message Date
hoteas b7131603c4 增加备注功能 2022-10-08 17:32:37 +08:00
hoteas 2f3a5a0a59 增加壁纸及壁纸地址缓存 2022-10-08 16:52:42 +08:00
3 changed files with 57 additions and 1 deletions
+3 -1
View File
@@ -683,7 +683,9 @@ func setMakeCodeListener(name string, appIns *Application) {
if context.RouterString[1] == "hotime" && context.RouterString[2] == "config" {
return isFinished
}
if context.RouterString[1] == "hotime" && context.RouterString[2] == "wallpaper" {
return isFinished
}
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
context.Display(2, "你还没有登录")
return true
+48
View File
@@ -6,6 +6,7 @@ import (
"github.com/360EntSecGroup-Skylar/excelize"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"time"
@@ -907,6 +908,53 @@ var TptProject = Proj{
that.Display(0, conf)
},
//壁纸
"wallpaper": func(that *Context) {
random := ObjToCeilInt(that.Req.FormValue("random")) //壁纸随机,0为默认,1,为随机
tp := ObjToCeilInt(that.Req.FormValue("type")) //返回类型,0,json,1,302跳转到图片
images := that.Application.Cache("wallpaper").ToSlice()
if images == nil || len(images) == 0 {
url := "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=7&mkt=zh-CN"
res, e := http.Get(url)
if e != nil {
that.Display(4, "无法取得数据0")
return
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
if err != nil {
that.Display(4, "无法取得数据1")
return
}
w := ObjToMap(string(b))
if len(w) == 0 {
that.Display(4, "无法取得数据2")
return
}
images = w.GetSlice("images")
that.Application.Cache("wallpaper", images)
}
if random == 1 {
random = RandX(0, len(images)-1)
}
img := images.GetMap(random)
if !strings.Contains(img.GetString("url"), "http") {
img["url"] = "https://cn.bing.com" + img.GetString("url")
}
if tp == 0 {
that.Display(0, img)
return
}
that.Resp.Header().Set("Location", img.GetString("url"))
that.Resp.WriteHeader(302)
},
},
}
+6
View File
@@ -193,6 +193,12 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
if indexNum > -1 {
coloum["label"] = info.GetString("label")[:indexNum]
}
psStart := strings.Index(info.GetString("label"), "{")
psEnd := strings.Index(info.GetString("label"), "}")
if psStart != -1 && psEnd > psStart {
coloum["ps"] = info.GetString("label")[psStart+1 : psEnd]
}
//去除数据信息,是用:号分割的
indexNum = strings.Index(coloum.GetString("label"), ":")
if indexNum > -1 {