Files
NapCatQQ/packages/napcat-webui-backend/src/helper/config-schema.ts
T
叫我饼干ちゃん 31c45bf18e 添加自动登录 | feat(login): automatically restore last logged-in account (#1980)
* feat(login): automatically restore last logged-in account

* docs(shell): correct quick login argument examples
2026-08-06 20:01:40 +08:00

38 lines
1.3 KiB
TypeScript

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));
}