Revert "添加自动登录 | feat(login): automatically restore last logged-in account (#1980)"
Release Tag / validate-version (push) Canceled after 0s
Release Tag / trigger-release (push) Canceled after 0s

This reverts commit 31c45bf18e.
This commit is contained in:
手瓜一十雪 committed 2026-08-07 17:47:00 +08:00
1 parent 624ecf5b9a
commit 0fcd0e80e0
9 files changed
+119 -203

No files matched your search

@@ -1,37 +0,0 @@
import { Static, Type } from '@sinclair/typebox';
import { themeType } from '../types/theme';
import { getRandomToken } from '../utils/url';
export const WebUiConfigSchema = Type.Object({
host: Type.String({ default: '::' }),
port: Type.Number({ default: 6099 }),
token: Type.String({ default: getRandomToken(12) }),
loginRate: Type.Number({ default: 10 }),
autoLoginAccount: Type.String({ default: '' }),
lastLoginAccount: Type.String({ default: '' }),
theme: themeType,
disableWebUI: Type.Boolean({ default: false }),
accessControlMode: Type.Union([
Type.Literal('none'),
Type.Literal('whitelist'),
Type.Literal('blacklist'),
], { default: 'none' }),
ipWhitelist: Type.Array(Type.String(), { default: [] }),
ipBlacklist: Type.Array(Type.String(), { default: [] }),
enableXForwardedFor: Type.Boolean({ default: false }),
enable2FA: Type.Boolean({ default: false }),
totpSecret: Type.String({ default: '' }),
});
export type WebUiConfigType = Static<typeof WebUiConfigSchema>;
export function resolveAutoLoginAccount (
environmentAccount: string | undefined,
configuredAccount: string | undefined,
lastLoginAccount: string | undefined
): string | undefined {
return [environmentAccount, configuredAccount, lastLoginAccount]
.map(account => account?.trim())
.find((account): account is string => Boolean(account));
}
@@ -1,4 +1,5 @@
import { webUiPathWrapper, getInitialWebUiToken } from '@/napcat-webui-backend/index';
import { Type, Static } from '@sinclair/typebox';
import { TypeCompiler } from '@sinclair/typebox/compiler';
import { Value } from '@sinclair/typebox/value';
import fs, { constants } from 'node:fs/promises';
@@ -6,9 +7,39 @@ import fs, { constants } from 'node:fs/promises';
import { resolve } from 'node:path';
import { deepMerge } from '../utils/object';
import { WebUiConfigSchema, type WebUiConfigType } from './config-schema';
import { themeType } from '../types/theme';
import { getRandomToken } from '../utils/url';
export { resolveAutoLoginAccount, WebUiConfigSchema, type WebUiConfigType } from './config-schema';
// 限制尝试端口的次数,避免死循环
// 定义配置的类型
const WebUiConfigSchema = Type.Object({
host: Type.String({ default: '::' }),
port: Type.Number({ default: 6099 }),
token: Type.String({ default: getRandomToken(12) }),
loginRate: Type.Number({ default: 10 }),
autoLoginAccount: Type.String({ default: '' }),
theme: themeType,
// 是否关闭WebUI
disableWebUI: Type.Boolean({ default: false }),
// 网络访问控制模式: 'none' | 'whitelist' | 'blacklist'
accessControlMode: Type.Union([
Type.Literal('none'),
Type.Literal('whitelist'),
Type.Literal('blacklist'),
], { default: 'none' }),
// IP白名单列表
ipWhitelist: Type.Array(Type.String(), { default: [] }),
// IP黑名单列表
ipBlacklist: Type.Array(Type.String(), { default: [] }),
// 是否启用 X-Forwarded-For 获取真实IP
enableXForwardedFor: Type.Boolean({ default: false }),
// 是否启用双因素认证(2FA)
enable2FA: Type.Boolean({ default: false }),
// TOTP 密钥
totpSecret: Type.String({ default: '' }),
});
export type WebUiConfigType = Static<typeof WebUiConfigSchema>;
// 读取当前目录下名为 webui.json 的配置文件,如果不存在则创建初始化配置文件
export class WebUiConfigWrapper {
@@ -211,14 +242,6 @@ export class WebUiConfigWrapper {
await this.UpdateWebUIConfig({ autoLoginAccount: uin });
}
getLastLoginAccount (): string | undefined {
return this.WebUiConfigData?.lastLoginAccount;
}
async UpdateLastLoginAccount (uin: string): Promise<void> {
await this.UpdateWebUIConfig({ lastLoginAccount: uin });
}
// 获取主题内容
async GetTheme (): Promise<WebUiConfigType['theme']> {
const config = await this.GetWebUIConfig();