From 8f6c25fbe4f4ead99f81f984b035b6e59aa0dd0f Mon Sep 17 00:00:00 2001 From: Season Shi Date: Thu, 23 Mar 2023 18:24:04 +0800 Subject: [PATCH] Add enable_sign to the basic storage struct. Can enable sign for every driver now. Bug: When sign enabled, in download page, Copy link doesn't contain a sign. (Not done yet) --- drivers/local/meta.go | 1 - internal/model/storage.go | 5 +++++ internal/op/driver.go | 7 ++++++- internal/sign/storage.go | 12 +----------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/local/meta.go b/drivers/local/meta.go index e15d50c5..efaad4c9 100644 --- a/drivers/local/meta.go +++ b/drivers/local/meta.go @@ -8,7 +8,6 @@ import ( type Addition struct { driver.RootPath Thumbnail bool `json:"thumbnail" required:"true" help:"enable thumbnail"` - Sign bool `json:"sign" default:"false" required:"false" help:"enable sign"` ShowHidden bool `json:"show_hidden" default:"true" required:"false" help:"show hidden directories and files"` MkdirPerm string `json:"mkdir_perm" default:"777"` } diff --git a/internal/model/storage.go b/internal/model/storage.go index 2be5fa33..f54acbd3 100644 --- a/internal/model/storage.go +++ b/internal/model/storage.go @@ -15,6 +15,11 @@ type Storage struct { Disabled bool `json:"disabled"` // if disabled Sort Proxy + Sign +} + +type Sign struct { + EnableSign bool `json:"enable_sign"` } type Sort struct { diff --git a/internal/op/driver.go b/internal/op/driver.go index 38946690..386ed5e1 100644 --- a/internal/op/driver.go +++ b/internal/op/driver.go @@ -122,9 +122,14 @@ func getMainItems(config driver.Config) []driver.Item { Type: conf.TypeSelect, Options: "front,back", }) + items = append(items, driver.Item{ + Name: "enable_sign", + Type: conf.TypeBool, + Default: "false", + Required: true, + }) return items } - func getAdditionalItems(t reflect.Type, defaultRoot string) []driver.Item { var items []driver.Item for i := 0; i < t.NumField(); i++ { diff --git a/internal/sign/storage.go b/internal/sign/storage.go index 8c5129e6..aabc8a7e 100644 --- a/internal/sign/storage.go +++ b/internal/sign/storage.go @@ -2,21 +2,11 @@ package sign import ( "github.com/alist-org/alist/v3/internal/op" - json "github.com/json-iterator/go" ) -type signType struct { - Sign bool `json:"sign"` -} - func IsStorageSigned(rawPath string) bool { - var jsonData signType storage := op.GetBalancedStorage(rawPath).GetStorage() - err := json.Unmarshal([]byte(storage.Addition), &jsonData) - if err != nil { - return false - } - if jsonData.Sign == true { + if storage.EnableSign == true { return true } return false