Skip to content

Commit

Permalink
v3.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
fesiong committed Jun 2, 2024
1 parent 848320f commit 0db8c8c
Show file tree
Hide file tree
Showing 23 changed files with 723 additions and 137 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# 更新日志

## v3.3.6 `anqicms` `2024-06-02`

- [新增] AI批量写作增加讯飞星火大模型支持
- [优化] 优化闭站功能,调整默认闭站界面显示内容
- [优化] 优化文档标签功能,增加批量导入标签操作
- [修复] 修复文件缓存过期时间失效的问题
- [修复] 修复后台文档统计数据统计不全的问题
- [修复] 修复文档删除,Sitemap不自动更新的问题
- [修复] 修复API发布接口发布到草稿箱无效的问题

## v3.3.5 `anqicms` `2024-05-01`

- [新增] 网站迁移功能增加帝国CMS,增加可选迁移功能
Expand Down
16 changes: 15 additions & 1 deletion config/aiGenerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@ type AiGenerateConfig struct {
StartHour int `json:"start_hour"` //每天开始时间
EndHour int `json:"end_hour"` //每天结束时间
DailyLimit int `json:"daily_limit"` //每日限额
UseSelfKey bool `json:"use_self_key"` // 使用自有key
AiEngine string `json:"ai_engine"` // ai 引擎,default 官方接口,openai 自定义openai,spark 星火大模型
OpenAIKeys []OpenAIKey `json:"open_ai_keys"` // self openai key
ApiValid bool `json:"api_valid"` // api地址是否可用
KeyIndex int `json:"-"` // 上一次调用的key id
Spark SparkSetting `json:"spark"`
}

type OpenAIKey struct {
Key string `json:"key"`
Invalid bool `json:"invalid"` // 是否不可用
}

type SparkSetting struct {
Version string `json:"version"`
AppID string `json:"app_id"`
APISecret string `json:"api_secret"`
APIKey string `json:"api_key"`
}

const (
AiEngineDefault = ""
AiEngineOpenAI = "openai"
AiEngineSpark = "spark"
)
2 changes: 1 addition & 1 deletion config/constant.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package config

const Version = "3.3.5"
const Version = "3.3.6"

const (
StatusOK = 0
Expand Down
56 changes: 42 additions & 14 deletions controller/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func InternalServerError(ctx iris.Context) {
}
}

func CheckCloseSite(ctx iris.Context) {
func CheckCloseSite(ctx iris.Context) bool {
currentSite := provider.CurrentSite(ctx)
if !strings.HasPrefix(ctx.GetCurrentRoute().Path(), "/system") {
// 闭站
Expand All @@ -163,19 +163,20 @@ func CheckCloseSite(ctx iris.Context) {
ctx.ViewData("webInfo", webInfo)
}

ctx.StatusCode(403)
err := ctx.View(GetViewPath(ctx, tplName))
if err != nil {
ShowMessage(ctx, closeTips, nil)
}
return
return true
}
// 禁止蜘蛛抓取
if currentSite.System.BanSpider == 1 {
ua := strings.ToLower(ctx.GetHeader("User-Agent"))
if strings.Contains(ua, "spider") || strings.Contains(ua, "bot") {
ctx.StatusCode(400)
ctx.StatusCode(403)
ShowMessage(ctx, currentSite.Lang("您已被禁止访问"), nil)
return
return true
}
}
// UA 禁止
Expand All @@ -188,9 +189,9 @@ func CheckCloseSite(ctx iris.Context) {
continue
}
if strings.Contains(ua, v) {
ctx.StatusCode(400)
ctx.StatusCode(403)
ShowMessage(ctx, currentSite.Lang("您已被禁止访问"), nil)
return
return true
}
}
}
Expand All @@ -212,16 +213,16 @@ func CheckCloseSite(ctx iris.Context) {
v = strings.TrimSuffix(v, ".0")
}
if strings.HasPrefix(ip, v) {
ctx.StatusCode(400)
ctx.StatusCode(403)
ShowMessage(ctx, currentSite.Lang("您已被禁止访问"), nil)
return
return true
}
}
}
}
}

ctx.Next()
return false
}

func Common(ctx iris.Context) {
Expand Down Expand Up @@ -316,7 +317,6 @@ func Inspect(ctx iris.Context) {

ctx.Values().Set("webInfo", &response.WebInfo{Title: siteName, NavBar: 0})
ctx.ViewData("website", website)

ctx.Next()
}

Expand Down Expand Up @@ -353,13 +353,16 @@ func FileServe(ctx iris.Context) bool {

func ReRouteContext(ctx iris.Context) {
params, _ := parseRoute(ctx)
defer LogAccess(ctx)
// 先验证文件是否真的存在,如果存在,则fileServe
exists := FileServe(ctx)
if exists {
return
}

defer LogAccess(ctx)
closed := CheckCloseSite(ctx)
if closed {
return
}
for i, v := range params {
if len(i) == 0 {
continue
Expand Down Expand Up @@ -823,6 +826,10 @@ func SafeVerify(ctx iris.Context, req map[string]string, returnType string, from
if currentSite.Safe.Captcha == 1 {
captchaId := ctx.PostValueTrim("captcha_id")
captchaValue := ctx.PostValueTrim("captcha")
if req != nil {
captchaId = req["captcha_id"]
captchaValue = req["captcha"]
}
// 验证 captcha
if captchaId == "" {
if returnType == "json" {
Expand All @@ -849,6 +856,9 @@ func SafeVerify(ctx iris.Context, req map[string]string, returnType string, from
}
// 内容长度现在 ContentLimit
content := ctx.PostValueTrim("content")
if req != nil {
content = req["content"]
}
if currentSite.Safe.ContentLimit > 0 {
if utf8.RuneCountInString(content) < currentSite.Safe.ContentLimit {
if returnType == "json" {
Expand Down Expand Up @@ -881,6 +891,24 @@ func SafeVerify(ctx iris.Context, req map[string]string, returnType string, from
}
return false
}
if req != nil {
// 对于req的所有内容都进行判断
for _, rv := range req {
if len(rv) == 0 {
continue
}
if strings.Contains(rv, v) {
if returnType == "json" {
ctx.JSON(iris.Map{
"code": config.StatusFailed,
"msg": currentSite.Lang("您提交的内容包含有不允许的字符"),
})
} else {
ShowMessage(ctx, currentSite.Lang("您提交的内容包含有不允许的字符"), nil)
}
}
}
}
}
}

Expand Down Expand Up @@ -916,10 +944,10 @@ func SafeVerify(ctx iris.Context, req map[string]string, returnType string, from
if returnType == "json" {
ctx.JSON(iris.Map{
"code": config.StatusFailed,
"msg": currentSite.Lang("请不要在短时间内多次提交"),
"msg": currentSite.Lang("非法请求"),
})
} else {
ShowMessage(ctx, currentSite.Lang("请不要在短时间内多次提交"), nil)
ShowMessage(ctx, currentSite.Lang("非法请求"), nil)
}
return false
}
Expand Down
10 changes: 10 additions & 0 deletions controller/manageController/pluginAiGenerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func HandleAiGenerateGetPlans(ctx iris.Context) {
pageSize := ctx.URLParamIntDefault("pageSize", 20)
aiType := uint(ctx.URLParamIntDefault("type", 0))
status := ctx.URLParamIntDefault("status", 0)
keyword := ctx.URLParam("keyword")

var total int64
var plans []*model.AiArticlePlan
Expand All @@ -120,6 +121,9 @@ func HandleAiGenerateGetPlans(ctx iris.Context) {
if status != 0 {
tx = tx.Where("`status` = ?", status)
}
if len(keyword) > 0 {
tx = tx.Where("`keyword` like ?", keyword+"%")
}
offset := 0
if currentPage > 0 {
offset = (currentPage - 1) * pageSize
Expand All @@ -131,6 +135,12 @@ func HandleAiGenerateGetPlans(ctx iris.Context) {
archive, err := currentSite.GetArchiveById(plans[i].ArticleId)
if err == nil {
plans[i].Title = archive.Title
} else {
// 来自草稿
archiveDraft, err := currentSite.GetArchiveDraftById(plans[i].ArticleId)
if err == nil {
plans[i].Title = archiveDraft.Title
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions controller/manageController/pluginSitemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func PluginSitemapForm(ctx iris.Context) {
if req.Type != "xml" {
req.Type = "txt"
}
oldType := currentSite.PluginSitemap.Type
currentSite.PluginSitemap.AutoBuild = req.AutoBuild
currentSite.PluginSitemap.Type = req.Type

Expand All @@ -47,6 +48,10 @@ func PluginSitemapForm(ctx iris.Context) {
})
return
}
// 当新旧Sitemap不一致的时候,就清理Sitemap
if oldType != req.Type {
currentSite.DeleteSitemap(oldType)
}

currentSite.AddAdminLog(ctx, fmt.Sprintf("更新SItemap配置"))

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/gomarkdown/markdown v0.0.0-20231222211730-1d6d20845b47
github.com/gorilla/websocket v1.5.0
github.com/huichen/sego v0.0.0-20210824061530-c87651ea5c76
github.com/huichen/wukong v0.0.0-20210824074240-ecbd39fa0b56
github.com/jinzhu/now v1.1.5
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25d
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
Expand Down
11 changes: 11 additions & 0 deletions library/fileCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"strings"
"sync"
"time"
)

type FileCache struct {
Expand All @@ -28,18 +29,28 @@ func (m *FileCache) Get(key string, val any) error {
}

cacheFile := m.cachePath + key + m.suffix
info, err := os.Stat(cacheFile)
if err != nil {
return err
}

buf, err := os.ReadFile(cacheFile)
if err != nil {
return err
}
var fileData FileCacheData
if err = json.Unmarshal(buf, &fileData); err != nil {
_ = os.Remove(cacheFile)
return err
}
if fileData.Expire > 0 && info.ModTime().Before(time.Now().Add(-time.Duration(fileData.Expire)*time.Second)) {
err = os.Remove(cacheFile)
return errors.New("cache-expire")
}
// 这里实际上应该还需要对数据进行还原
err = json.Unmarshal(fileData.Data, val)
if err != nil {
_ = os.Remove(cacheFile)
return err
}
return nil
Expand Down
11 changes: 11 additions & 0 deletions provider/aiArticlePlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ func (w *Website) GetAiArticlePlanByReqId(reqId uint) (*model.AiArticlePlan, err
return &plan, nil
}

func (w *Website) GetAiArticlePlanByKeyword(planType int, keyword string) (*model.AiArticlePlan, error) {
var plan model.AiArticlePlan
err := w.DB.Where("`type` = ? and `keyword` = ?", planType, keyword).Take(&plan).Error

if err != nil {
return nil, err
}

return &plan, nil
}

func (w *Website) SaveAiArticlePlan(resp *AnqiAiResult, useSelf bool) (*model.AiArticlePlan, error) {
if resp.ReqId > 0 {
plan, err := w.GetAiArticlePlanByReqId(resp.ReqId)
Expand Down
Loading

0 comments on commit 0db8c8c

Please sign in to comment.