-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom hide error message by regexp (close #1468)
- Loading branch information
Showing
8 changed files
with
144 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package db | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/alist-org/alist/v3/internal/conf" | ||
"github.com/alist-org/alist/v3/internal/model" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type SettingItemHook struct { | ||
Hook func(item *model.SettingItem) error | ||
} | ||
|
||
var SettingItemHooks = map[string]SettingItemHook{ | ||
conf.VideoTypes: { | ||
Hook: func(item *model.SettingItem) error { | ||
conf.TypesMap[conf.VideoTypes] = strings.Split(item.Value, ",") | ||
return nil | ||
}, | ||
}, | ||
conf.AudioTypes: { | ||
Hook: func(item *model.SettingItem) error { | ||
conf.TypesMap[conf.AudioTypes] = strings.Split(item.Value, ",") | ||
return nil | ||
}, | ||
}, | ||
conf.ImageTypes: { | ||
Hook: func(item *model.SettingItem) error { | ||
conf.TypesMap[conf.ImageTypes] = strings.Split(item.Value, ",") | ||
return nil | ||
}, | ||
}, | ||
conf.TextTypes: { | ||
Hook: func(item *model.SettingItem) error { | ||
conf.TypesMap[conf.TextTypes] = strings.Split(item.Value, ",") | ||
return nil | ||
}, | ||
}, | ||
conf.OfficeTypes: { | ||
Hook: func(item *model.SettingItem) error { | ||
conf.TypesMap[conf.OfficeTypes] = strings.Split(item.Value, ",") | ||
return nil | ||
}, | ||
}, | ||
conf.ProxyTypes: { | ||
func(item *model.SettingItem) error { | ||
conf.TypesMap[conf.ProxyTypes] = strings.Split(item.Value, ",") | ||
return nil | ||
}, | ||
}, | ||
conf.PrivacyRegs: { | ||
Hook: func(item *model.SettingItem) error { | ||
regStrs := strings.Split(item.Value, "\n") | ||
regs := make([]*regexp.Regexp, 0, len(regStrs)) | ||
for _, regStr := range regStrs { | ||
reg, err := regexp.Compile(regStr) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
regs = append(regs, reg) | ||
} | ||
conf.PrivacyReg = regs | ||
return nil | ||
}, | ||
}, | ||
} | ||
|
||
func HandleSettingItem(item *model.SettingItem) (bool, error) { | ||
if hook, ok := SettingItemHooks[item.Key]; ok { | ||
return true, hook.Hook(item) | ||
} | ||
return false, nil | ||
} | ||
|
||
// func HandleSettingItems(items []model.SettingItem) error { | ||
// for i := range items { | ||
// if err := HandleSettingItem(&items[i]); err != nil { | ||
// return err | ||
// } | ||
// } | ||
// return nil | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters