improve the readability of the function generate_api_key (#12552)

This commit is contained in:
gakkiyomi 2025-01-09 21:30:17 +08:00 committed by GitHub
parent 140965b738
commit 989fb11fd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1405,9 +1405,8 @@ class ApiToken(db.Model): # type: ignore[name-defined]
def generate_api_key(prefix, n):
while True:
result = prefix + generate_string(n)
while db.session.query(ApiToken).filter(ApiToken.token == result).count() > 0:
result = prefix + generate_string(n)
if db.session.query(ApiToken).filter(ApiToken.token == result).count() > 0:
continue
return result