Skip to content

Commit

Permalink
feat: new configuration option: authkeyExpiredTimeout
Browse files Browse the repository at this point in the history
close #18
  • Loading branch information
YanxinTang committed Nov 7, 2021
1 parent 65ca11a commit a9932f7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 4 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ clipboard-online 是一款可以帮你在 💻Windows 和 📱iOS 之间分享
- type: `string`
- default: `''`

- `authkeyExpiredTimeout`
- type: `int64`
- default: `30`

- `tempDir`
- type: `string`
- default: `./temp`
Expand Down
24 changes: 13 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
)

const (
apiVersion = "1"
authAvailableTimeout int64 = 30
apiVersion = "1"
)

func setupRoute(engin *gin.Engine) {
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit a9932f7

Please sign in to comment.