refactor(code): Cleaned-up the code base
This commit is contained in:
49
lib/server/retention.go
Normal file
49
lib/server/retention.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"warpbox/lib/boxstore"
|
||||
"warpbox/lib/models"
|
||||
)
|
||||
|
||||
func (app *App) retentionAllowed(key string) bool {
|
||||
key = strings.TrimSpace(key)
|
||||
if key == "" {
|
||||
return true
|
||||
}
|
||||
for _, option := range app.retentionOptions() {
|
||||
if option.Key == key {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (app *App) retentionOptions() []models.RetentionOption {
|
||||
allOptions := boxstore.RetentionOptions()
|
||||
options := make([]models.RetentionOption, 0, len(allOptions))
|
||||
for _, option := range allOptions {
|
||||
if option.Key == boxstore.OneTimeDownloadRetentionKey && !app.config.OneTimeDownloadsEnabled {
|
||||
continue
|
||||
}
|
||||
if option.Seconds > 0 && app.config.MaxGuestExpirySeconds > 0 && option.Seconds > app.config.MaxGuestExpirySeconds {
|
||||
continue
|
||||
}
|
||||
options = append(options, option)
|
||||
}
|
||||
if len(options) == 0 {
|
||||
return allOptions[:1]
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
func (app *App) defaultRetentionOption() models.RetentionOption {
|
||||
options := app.retentionOptions()
|
||||
for _, option := range options {
|
||||
if option.Seconds == app.config.DefaultGuestExpirySeconds {
|
||||
return option
|
||||
}
|
||||
}
|
||||
return options[0]
|
||||
}
|
||||
Reference in New Issue
Block a user