feat(admin): Bot Configuration — eye toggle to reveal masked values (token, secrets)
- compose: pass bot env (BOT_TOKEN, SUPPORT_LINK, ADMIN_IDS, SUPER_ADMIN_IDS, WG_*, ADMIN_*, GITEA_API_URL) to tg_shop_admin - settings API: reads real env values; POST /api/settings reveals secret value by key (auth required) - settings-page: eye/eye-off button on masked fields, shows real value on click (BOT_TOKEN, ADMIN_IDS, etc.)
This commit is contained in:
@@ -22,7 +22,7 @@ import {
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { toast } from "sonner";
|
||||
import { useAuthStore } from "@/stores/auth-store";
|
||||
import { Bot, Shield, Wrench, Save, AlertTriangle, Download, Upload, Database, Info } from "lucide-react";
|
||||
import { Bot, Shield, Wrench, Save, AlertTriangle, Download, Upload, Database, Info, Eye, EyeOff } from "lucide-react";
|
||||
|
||||
const MASKED_PLACEHOLDER = "\u25CF\u25CF\u25CF\u25CF\u25CF\u25CF\u25CF";
|
||||
|
||||
@@ -86,6 +86,8 @@ export function SettingsPage() {
|
||||
const [importing, setImporting] = useState(false);
|
||||
const [importDialogOpen, setImportDialogOpen] = useState(false);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [revealed, setRevealed] = useState<Record<string, string>>({});
|
||||
const [revealing, setRevealing] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/settings")
|
||||
@@ -121,6 +123,34 @@ export function SettingsPage() {
|
||||
setSettings((prev) => (prev ? { ...prev, [key]: value } : prev));
|
||||
};
|
||||
|
||||
// Показать/скрыть реальное значение секрета (глазик)
|
||||
const handleReveal = async (key: string) => {
|
||||
if (revealed[key] !== undefined) {
|
||||
// Повторный клик — скрыть
|
||||
setRevealed((prev) => {
|
||||
const next = { ...prev };
|
||||
delete next[key];
|
||||
return next;
|
||||
});
|
||||
return;
|
||||
}
|
||||
setRevealing(key);
|
||||
try {
|
||||
const res = await fetch("/api/settings", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ key }),
|
||||
});
|
||||
if (!res.ok) throw new Error();
|
||||
const data = await res.json();
|
||||
setRevealed((prev) => ({ ...prev, [key]: data.value ?? "" }));
|
||||
} catch {
|
||||
toast.error(`Failed to reveal ${KEY_META[key]?.label || key}`);
|
||||
} finally {
|
||||
setRevealing(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSwitchChange = (key: string, checked: boolean) => {
|
||||
setSettings((prev) => (prev ? { ...prev, [key]: checked } : prev));
|
||||
};
|
||||
@@ -259,12 +289,32 @@ export function SettingsPage() {
|
||||
</span>
|
||||
</div>
|
||||
) : isMasked ? (
|
||||
<Input
|
||||
id={key}
|
||||
value={MASKED_PLACEHOLDER}
|
||||
disabled
|
||||
className="max-w-md"
|
||||
/>
|
||||
<div className="flex gap-2 max-w-md">
|
||||
<Input
|
||||
id={key}
|
||||
value={revealed[key] !== undefined ? revealed[key] : MASKED_PLACEHOLDER}
|
||||
disabled={revealed[key] === undefined}
|
||||
onChange={(e) => handleChange(key, e.target.value)}
|
||||
className="flex-1 font-mono"
|
||||
type={revealed[key] !== undefined ? "text" : "password"}
|
||||
/>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="outline"
|
||||
className="shrink-0"
|
||||
onClick={() => handleReveal(key)}
|
||||
disabled={revealing === key}
|
||||
title={revealed[key] !== undefined ? "Hide value" : "Show value"}
|
||||
>
|
||||
{revealing === key ? (
|
||||
<span className="h-4 w-4 animate-pulse">...</span>
|
||||
) : revealed[key] !== undefined ? (
|
||||
<EyeOff className="h-4 w-4" />
|
||||
) : (
|
||||
<Eye className="h-4 w-4" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<Input
|
||||
id={key}
|
||||
|
||||
Reference in New Issue
Block a user