Repository navigation
fix: chat user login #7806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: chat user login #7806
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,8 @@ const displayName = computed(() => account.value?.nickName || account.value?.use | |
| // 配额尚未接入时保留空值展示,不将缺失数据表示为零用量。 | ||
| const tokenPercentage = computed(() => { | ||
| const quota = account.value?.token_quota | ||
| if (!quota) return 0 | ||
| return Math.min(100, Math.max(0, (quota.used_tokens / quota.total_tokens) * 100)) | ||
| if (!quota || quota.quota_type === QUOTA_TYPE.UNLIMITED || !quota.token_limit) return 0 | ||
| return Math.min(100, Math.max(0, (quota.used_tokens / quota.token_limit) * 100)) | ||
| }) | ||
|
|
||
| const userPwdDialogRef = useTemplateRef<InstanceType<typeof UserPwdDialog>>('userPwdDialogRef') | ||
|
|
@@ -71,7 +71,7 @@ const goLogin = () => { | |
| <span class="mr-3">Tokens</span> | ||
| <span class="text-primary">{{ formatTokenNumber(account?.token_quota?.used_tokens) }}</span> | ||
| <span class="text-N500"> | ||
| /{{ account?.token_quota?.quota_type === QUOTA_TYPE.UNLIMITED ? '不限' : formatTokenNumber(account?.token_quota?.total_tokens) }} | ||
| /{{ account?.token_quota?.quota_type === QUOTA_TYPE.UNLIMITED ? '不限' : formatTokenNumber(account?.token_quota?.token_limit) }} | ||
| </span> | ||
| </div> | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review1. Correctness / edge cases
if (!quota || quota.quota_type === QUOTA_TYPE.UNLIMITED) return 0
if (!quota.token_limit || quota.token_limit <= 0) return 0
const used = quota.used_tokens ?? 0Unlimited quota mapped to 0% is semantically odd. An "unlimited" plan rendered as an empty progress bar can read as "no usage" or "nothing available". Either hide the bar for unlimited (
2. Consistency / DRY
3. API / rename risk (
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the analysis of the provided code snippet:
1. Irregularities & Potential Issues
not portal.enable_authcheck. This implies the login policy limits are now applied even if authentication is disabled. If this is a security requirement, it's fine. If not, you might be enforcing lockouts on a system that isn't even using auth.("portal", 1, 5, 10)contains magic numbers. These should ideally match the defaults fromauth_settingfor consistency.Portal.objects.first()returns an object orNone. Theis Nonecheck is correct, but note that this queries the database every time_get_login_policyis called.2. Optimization Suggestions
.first()in a frequently accessed method (like login) causes unnecessary DB hits. Consider cachingPortal.auth_configusingfunctools.lru_cache, django's cache framework, or storing it in settings/environment variables if it rarely changes.auth_setting.3. Improved Code Suggestion
Key Takeaway
Ensure removing
enable_authfrom the condition is intended. Ifenable_auth=Falsemeans "no security," checkingportal is Noneonly might inadvertently apply lockout rules to non-auth environments.