diff options
| author | Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> | 2023-05-21 07:03:08 +0300 |
|---|---|---|
| committer | Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> | 2023-05-21 07:03:08 +0300 |
| commit | f82d0051b2cf827228b5c939d22622bd0d066149 (patch) | |
| tree | 0241a998df1f52f5170aec9bc263414e8a2a3e96 /web/global | |
| parent | 76267b23a03d3d3424d5e6b147825391ac5b37db (diff) | |
Update hashstorage functionality
Diffstat (limited to 'web/global')
| -rw-r--r-- | web/global/hashStorage.go | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/web/global/hashStorage.go b/web/global/hashStorage.go index 3d5a6a0d..9dfea169 100644 --- a/web/global/hashStorage.go +++ b/web/global/hashStorage.go @@ -6,7 +6,6 @@ import ( "regexp" "sync" "time" - "x-ui/util/common" ) type HashEntry struct { @@ -19,31 +18,17 @@ type HashStorage struct { sync.RWMutex Data map[string]HashEntry Expiration time.Duration - ForceSave bool + } -func NewHashStorage(expiration time.Duration, forceSave bool) *HashStorage { +func NewHashStorage(expiration time.Duration) *HashStorage { return &HashStorage{ Data: make(map[string]HashEntry), Expiration: expiration, - ForceSave: forceSave, } } -func (h *HashStorage) AddHash(query string) string { - if h.ForceSave { - return h.saveValue(query) - } - - // we only need to hash for more than 64 chars by default - if len(query) <= 64 { - return query - } - - return h.saveValue(query) -} - -func (h *HashStorage) saveValue(query string) string { +func (h *HashStorage) SaveHash(query string) string { h.Lock() defer h.Unlock() @@ -61,21 +46,17 @@ func (h *HashStorage) saveValue(query string) string { return md5HashString } -func (h *HashStorage) GetValue(hash string) (string, error) { + +func (h *HashStorage) GetValue(hash string) (string, bool) { h.RLock() defer h.RUnlock() entry, exists := h.Data[hash] - if !exists { - if h.isMD5(hash) { - return "", common.NewError("hash not found in storage!") - } - return hash, nil - } - return entry.Value, nil + + return entry.Value, exists } -func (h *HashStorage) isMD5(hash string) bool { +func (h *HashStorage) IsMD5(hash string) bool { match, _ := regexp.MatchString("^[a-f0-9]{32}$", hash) return match } |
