Skip to content

Commit

Permalink
feat: add a save limits (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeessy2 authored Oct 8, 2024
1 parent 7520de4 commit 9cfa5f7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions web/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@ import (
"backup-x/client"
"backup-x/entity"
"backup-x/util"
"fmt"
"log"
"net/http"
"strconv"
"strings"
"time"
)

// 服务启动时间
var startTime = time.Now()

// 保存限制时间
var saveLimit = time.Duration(30 * time.Minute)

// Save 保存
func Save(writer http.ResponseWriter, request *http.Request) {
oldConf, _ := entity.GetConfigCache()
conf := &entity.Config{}

if oldConf.Password == "" {
if time.Since(startTime) > saveLimit {
writer.Write([]byte(fmt.Sprintf("需在 %s 之前完成用户名密码设置,请重启backup-x", startTime.Add(saveLimit).Format("2006-01-02 15:04:05"))))
return
}
}

conf.EncryptKey = oldConf.EncryptKey
if conf.EncryptKey == "" {
encryptKey, err := util.GenerateEncryptKey()
Expand Down

0 comments on commit 9cfa5f7

Please sign in to comment.