fix: improve vendor string parsing in CryptoVendor class

This commit is contained in:
halo
2026-07-10 16:03:53 +08:00
committed by feng626
parent 721ccc0745
commit 92c8f73ade
2 changed files with 10 additions and 8 deletions

View File

@@ -10,14 +10,15 @@ class CryptoVendor(Enum):
SCTU = "sctu"
@classmethod
def from_str(cls, name: str):
try:
return cls[name.upper()]
except KeyError:
for vendor in cls:
if vendor.value.lower() == name.lower():
return vendor
raise ValueError(f"Unknown GM Vendor: {name}")
def from_str(cls, name: str | None):
if name is None or not name.strip():
return cls.PIICO
name = name.strip().lower()
for vendor in cls:
if name in (vendor.name.lower(), vendor.value.lower()):
return vendor
raise ValueError(f"Unknown GM Vendor: {name}")
def open_gm_device(vendor: CryptoVendor) -> Device:

View File

@@ -237,6 +237,7 @@ DJANGO_REDIS_SCAN_ITERSIZE = 1000
# GM DEVICE
GM_DEVICE_ENABLE = CONFIG.GM_DEVICE_ENABLE
GM_VENDOR_NAME = CONFIG.GM_VENDOR_NAME
GM_DRIVER_PATH = CONFIG.GM_DRIVER_PATH
LEAK_PASSWORD_DB_PATH = CONFIG.LEAK_PASSWORD_DB_PATH