修改: app/components/settings.tsx

修改:     app/components/ui-lib.tsx
	修改:     app/constant.ts
	修改:     app/utils/encryption.ts
This commit is contained in:
glay 2024-11-06 09:44:36 +08:00
parent c55cea5853
commit 952d8835a3
4 changed files with 36 additions and 3 deletions

View File

@ -997,6 +997,7 @@ export function Settings() {
(access) => (access.awsAccessKey = e.currentTarget.value), (access) => (access.awsAccessKey = e.currentTarget.value),
); );
}} }}
maskWhenShow={true}
/> />
</ListItem> </ListItem>
<ListItem <ListItem
@ -1013,6 +1014,7 @@ export function Settings() {
(access) => (access.awsSecretKey = e.currentTarget.value), (access) => (access.awsSecretKey = e.currentTarget.value),
); );
}} }}
maskWhenShow={true}
/> />
</ListItem> </ListItem>
<ListItem <ListItem
@ -1029,6 +1031,7 @@ export function Settings() {
(access) => (access.awsSessionToken = e.currentTarget.value), (access) => (access.awsSessionToken = e.currentTarget.value),
); );
}} }}
maskWhenShow={true}
/> />
</ListItem> </ListItem>
</> </>

View File

@ -11,6 +11,7 @@ import MaxIcon from "../icons/max.svg";
import MinIcon from "../icons/min.svg"; import MinIcon from "../icons/min.svg";
import Locale from "../locales"; import Locale from "../locales";
import { maskSensitiveValue } from "../utils/encryption";
import { createRoot } from "react-dom/client"; import { createRoot } from "react-dom/client";
import React, { import React, {
@ -266,13 +267,32 @@ export function Input(props: InputProps) {
} }
export function PasswordInput( export function PasswordInput(
props: HTMLProps<HTMLInputElement> & { aria?: string }, props: HTMLProps<HTMLInputElement> & {
aria?: string;
maskWhenShow?: boolean; // New prop to control masking behavior
},
) { ) {
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [displayValue, setDisplayValue] = useState(props.value as string);
useEffect(() => {
if (props.maskWhenShow && visible && props.value) {
setDisplayValue(maskSensitiveValue(props.value as string));
} else {
setDisplayValue(props.value as string);
}
}, [visible, props.value, props.maskWhenShow]);
function changeVisibility() { function changeVisibility() {
setVisible(!visible); setVisible(!visible);
} }
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (props.onChange) {
props.onChange(e);
}
};
return ( return (
<div className={"password-input-container"}> <div className={"password-input-container"}>
<IconButton <IconButton
@ -283,6 +303,8 @@ export function PasswordInput(
/> />
<input <input
{...props} {...props}
value={displayValue}
onChange={handleChange}
type={visible ? "text" : "password"} type={visible ? "text" : "password"}
className={"password-input"} className={"password-input"}
/> />
@ -543,6 +565,7 @@ export function Selector<T>(props: {
</div> </div>
); );
} }
export function FullScreen(props: any) { export function FullScreen(props: any) {
const { children, right = 10, top = 10, ...rest } = props; const { children, right = 10, top = 10, ...rest } = props;
const ref = useRef<HTMLDivElement>(); const ref = useRef<HTMLDivElement>();

View File

@ -121,8 +121,8 @@ export enum ServiceProvider {
Stability = "Stability", Stability = "Stability",
Iflytek = "Iflytek", Iflytek = "Iflytek",
XAI = "XAI", XAI = "XAI",
Bedrock = "Bedrock",
ChatGLM = "ChatGLM", ChatGLM = "ChatGLM",
Bedrock = "Bedrock",
} }
// Google API safety settings, see https://ai.google.dev/gemini-api/docs/safety-settings // Google API safety settings, see https://ai.google.dev/gemini-api/docs/safety-settings
@ -136,7 +136,6 @@ export enum GoogleSafetySettingsThreshold {
export enum ModelProvider { export enum ModelProvider {
Stability = "Stability", Stability = "Stability",
Bedrock = "Bedrock",
GPT = "GPT", GPT = "GPT",
GeminiPro = "GeminiPro", GeminiPro = "GeminiPro",
Claude = "Claude", Claude = "Claude",
@ -148,6 +147,7 @@ export enum ModelProvider {
Iflytek = "Iflytek", Iflytek = "Iflytek",
XAI = "XAI", XAI = "XAI",
ChatGLM = "ChatGLM", ChatGLM = "ChatGLM",
Bedrock = "Bedrock",
} }
export const Stability = { export const Stability = {

View File

@ -8,6 +8,7 @@ if (!SECRET_KEY || SECRET_KEY.length < 32) {
"ENCRYPTION_KEY environment variable must be set with at least 32 characters", "ENCRYPTION_KEY environment variable must be set with at least 32 characters",
); );
} }
export function encrypt(data: string): string { export function encrypt(data: string): string {
try { try {
return AES.encrypt(data, SECRET_KEY).toString(); return AES.encrypt(data, SECRET_KEY).toString();
@ -26,3 +27,9 @@ export function decrypt(encryptedData: string): string {
return encryptedData; // Fallback to the original data if decryption fails return encryptedData; // Fallback to the original data if decryption fails
} }
} }
export function maskSensitiveValue(value: string): string {
if (!value) return "";
if (value.length <= 4) return value;
return "*".repeat(value.length - 4) + value.slice(-4);
}