diff --git a/README.md b/README.md index 8646224..51e48f6 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ You can make customization by editing `config.json` - type: `string` - default: `''` +- `authkeyExpiredTimeout` + - type: `int64` + - default: `30` + - `tempDir` - type: `string` - default: `./temp` diff --git a/README_zh.md b/README_zh.md index 0b1122f..95c09ac 100644 --- a/README_zh.md +++ b/README_zh.md @@ -64,6 +64,10 @@ clipboard-online 是一款可以帮你在 💻Windows 和 📱iOS 之间分享 - type: `string` - default: `''` +- `authkeyExpiredTimeout` + - type: `int64` + - default: `30` + - `tempDir` - type: `string` - default: `./temp` diff --git a/config.go b/config.go index 8d23db4..cae8adf 100644 --- a/config.go +++ b/config.go @@ -13,12 +13,13 @@ const LogFile = "log.txt" // Config represents configuration for applicaton type Config struct { - Port string `json:"port"` - Authkey string `json:"authkey"` - LogLevel log.Level `json:"logLevel"` - TempDir string `json:"tempDir"` - ReserveHistory bool `json:"reserveHistory"` - Notify ConfigNotify `json:"notify"` + Port string `json:"port"` + Authkey string `json:"authkey"` + AuthkeyExpiredTimeout int64 `json:"authkeyExpiredTimeout"` + LogLevel log.Level `json:"logLevel"` + TempDir string `json:"tempDir"` + ReserveHistory bool `json:"reserveHistory"` + Notify ConfigNotify `json:"notify"` } type ConfigNotify struct { @@ -28,11 +29,12 @@ type ConfigNotify struct { // DefaultConfig is a default configuration for application var DefaultConfig = Config{ - Port: "8086", - Authkey: "", - LogLevel: log.WarnLevel, - TempDir: "./temp", - ReserveHistory: false, + Port: "8086", + Authkey: "", + AuthkeyExpiredTimeout: 30, + LogLevel: log.WarnLevel, + TempDir: "./temp", + ReserveHistory: false, Notify: ConfigNotify{ Copy: false, Paste: false, diff --git a/server.go b/server.go index a3c7152..4ba35cb 100644 --- a/server.go +++ b/server.go @@ -26,8 +26,7 @@ import ( ) const ( - apiVersion = "1" - authAvailableTimeout int64 = 30 + apiVersion = "1" ) func setupRoute(engin *gin.Engine) { @@ -81,7 +80,7 @@ func auth() gin.HandlerFunc { reqAuth := c.GetHeader("X-Auth") timestamp := time.Now().Unix() - timeKey := timestamp / authAvailableTimeout + timeKey := timestamp / app.config.AuthkeyExpiredTimeout authCodeRaw := app.config.Authkey + "." + strconv.FormatInt(timeKey, 10) authCodeHash := md5.Sum([]byte(authCodeRaw))