mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-26 14:35:22 +08:00
e7badb1a24
* refactor(ui): simplify UpdateBadge to minimal dot indicator * feat(provider): add individual test and proxy config for providers Add support for provider-specific model test and proxy configurations: - Add ProviderTestConfig and ProviderProxyConfig types in Rust and TypeScript - Create ProviderAdvancedConfig component with collapsible panels - Update stream_check service to merge provider config with global config - Proxy config UI follows global proxy style (single URL input) Provider-level configs stored in meta field, no database schema changes needed. * feat(ui): add failover toggle and improve proxy controls - Add FailoverToggle component with slide animation - Simplify ProxyToggle style to match FailoverToggle - Add usage statistics button when proxy is active - Fix i18n parameter passing for failover messages - Add missing failover translation keys (inQueue, addQueue, priority) - Replace AboutSection icon with app logo * fix(proxy): support system proxy fallback and provider-level proxy config - Remove no_proxy() calls in http_client.rs to allow system proxy fallback - Add get_for_provider() to build HTTP client with provider-specific proxy - Update forwarder.rs and stream_check.rs to use provider proxy config - Fix EditProviderDialog.tsx to include provider.meta in useMemo deps - Add useEffect in ProviderAdvancedConfig.tsx to sync expand state Fixes #636 Fixes #583 * fix(ui): sync toast theme with app setting * feat(settings): add log config management Fixes #612 Fixes #514 * fix(proxy): increase request body size limit to 200MB Fixes #666 * docs(proxy): update timeout config descriptions and defaults Fixes #612 * fix(proxy): filter x-goog-api-key header to prevent duplication * fix(proxy): prevent proxy recursion when system proxy points to localhost Detect if HTTP_PROXY, HTTPS_PROXY, or ALL_PROXY environment variables point to loopback addresses (localhost, 127.0.0.1), and bypass system proxy in such cases to avoid infinite request loops. * fix(i18n): add providerAdvanced i18n keys and fix failover toast parameter - Add providerAdvanced.* i18n keys to en.json, zh.json, and ja.json - Fix failover toggleFailed toast to pass detail parameter - Remove Chinese fallback text from UI for English/Japanese users * fix(tray): restore tray-provider events and enable Auto failover properly - Emit provider-switched event on tray provider click (backward compatibility) - Auto button now: starts proxy, takes over live config, enables failover * fix(log): enable dynamic log level and single file mode - Initialize log at Trace level for dynamic adjustment - Change rotation strategy to KeepSome(1) for single file - Set max file size to 1GB - Delete old log file on startup for clean start * fix(tray): fix clippy uninlined format args warning Use inline format arguments: {app_type_str} instead of {} * fix(provider): allow typing :// in endpoint URL inputs Change input type from "url" to "text" to prevent browser URL validation from blocking :// input. Closes #681 * fix(stream-check): use Gemini native streaming API format - Change endpoint from OpenAI-compatible to native streamGenerateContent - Add alt=sse parameter for SSE format response - Use x-goog-api-key header instead of Bearer token - Convert request body to Gemini contents/parts format * feat(proxy): add request logging for debugging Add debug logs for outgoing requests including URL and body content with byte size, matching the existing response logging format. * fix(log): prevent usize underflow in KeepSome rotation strategy KeepSome(n) internally computes n-2, so n=1 causes underflow. Use KeepSome(2) as the minimum safe value.
177 lines
5.7 KiB
TypeScript
177 lines
5.7 KiB
TypeScript
import { useTranslation } from "react-i18next";
|
|
import { useState } from "react";
|
|
import type { ReactNode } from "react";
|
|
import {
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from "@/components/ui/form";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Button } from "@/components/ui/button";
|
|
import { ArrowLeft } from "lucide-react";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogTrigger,
|
|
DialogClose,
|
|
} from "@/components/ui/dialog";
|
|
import { ProviderIcon } from "@/components/ProviderIcon";
|
|
import { IconPicker } from "@/components/IconPicker";
|
|
import { getIconMetadata } from "@/icons/extracted/metadata";
|
|
import type { UseFormReturn } from "react-hook-form";
|
|
import type { ProviderFormData } from "@/lib/schemas/provider";
|
|
|
|
interface BasicFormFieldsProps {
|
|
form: UseFormReturn<ProviderFormData>;
|
|
/** Slot to render content between icon and name fields */
|
|
beforeNameSlot?: ReactNode;
|
|
}
|
|
|
|
export function BasicFormFields({
|
|
form,
|
|
beforeNameSlot,
|
|
}: BasicFormFieldsProps) {
|
|
const { t } = useTranslation();
|
|
const [iconDialogOpen, setIconDialogOpen] = useState(false);
|
|
|
|
const currentIcon = form.watch("icon");
|
|
const currentIconColor = form.watch("iconColor");
|
|
const providerName = form.watch("name") || "Provider";
|
|
const effectiveIconColor =
|
|
currentIconColor ||
|
|
(currentIcon ? getIconMetadata(currentIcon)?.defaultColor : undefined);
|
|
|
|
const handleIconSelect = (icon: string) => {
|
|
const meta = getIconMetadata(icon);
|
|
form.setValue("icon", icon);
|
|
form.setValue("iconColor", meta?.defaultColor ?? "");
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{/* 图标选择区域 - 顶部居中,可选 */}
|
|
<div className="flex justify-center mb-6">
|
|
<Dialog open={iconDialogOpen} onOpenChange={setIconDialogOpen}>
|
|
<DialogTrigger asChild>
|
|
<button
|
|
type="button"
|
|
className="w-20 h-20 p-3 rounded-xl border-2 border-muted hover:border-primary transition-colors cursor-pointer bg-muted/30 hover:bg-muted/50 flex items-center justify-center"
|
|
title={
|
|
currentIcon
|
|
? t("providerIcon.clickToChange", {
|
|
defaultValue: "点击更换图标",
|
|
})
|
|
: t("providerIcon.clickToSelect", {
|
|
defaultValue: "点击选择图标",
|
|
})
|
|
}
|
|
>
|
|
<ProviderIcon
|
|
icon={currentIcon}
|
|
name={providerName}
|
|
color={effectiveIconColor}
|
|
size={48}
|
|
/>
|
|
</button>
|
|
</DialogTrigger>
|
|
<DialogContent
|
|
variant="fullscreen"
|
|
zIndex="top"
|
|
overlayClassName="bg-[hsl(var(--background))] backdrop-blur-0"
|
|
className="p-0 sm:rounded-none"
|
|
>
|
|
<div className="flex h-full flex-col">
|
|
<div className="flex-shrink-0 py-4 border-b border-border-default bg-muted/40">
|
|
<div className="px-6 flex items-center gap-4">
|
|
<DialogClose asChild>
|
|
<Button type="button" variant="outline" size="icon">
|
|
<ArrowLeft className="h-4 w-4" />
|
|
</Button>
|
|
</DialogClose>
|
|
<p className="text-lg font-semibold leading-tight">
|
|
{t("providerIcon.selectIcon", {
|
|
defaultValue: "选择图标",
|
|
})}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div className="flex-1 overflow-y-auto">
|
|
<div className="space-y-2 px-6 py-6 w-full">
|
|
<IconPicker
|
|
value={currentIcon}
|
|
onValueChange={handleIconSelect}
|
|
color={effectiveIconColor}
|
|
/>
|
|
<div className="flex justify-end gap-2">
|
|
<DialogClose asChild>
|
|
<Button type="button" variant="outline">
|
|
{t("common.done", { defaultValue: "完成" })}
|
|
</Button>
|
|
</DialogClose>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</div>
|
|
|
|
{/* Slot for additional fields between icon and name */}
|
|
{beforeNameSlot}
|
|
|
|
{/* 基础信息 - 网格布局 */}
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<FormField
|
|
control={form.control}
|
|
name="name"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t("provider.name")}</FormLabel>
|
|
<FormControl>
|
|
<Input {...field} placeholder={t("provider.namePlaceholder")} />
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<FormField
|
|
control={form.control}
|
|
name="notes"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t("provider.notes")}</FormLabel>
|
|
<FormControl>
|
|
<Input
|
|
{...field}
|
|
placeholder={t("provider.notesPlaceholder")}
|
|
/>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
</div>
|
|
|
|
<FormField
|
|
control={form.control}
|
|
name="websiteUrl"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t("provider.websiteUrl")}</FormLabel>
|
|
<FormControl>
|
|
<Input
|
|
{...field}
|
|
placeholder={t("providerForm.websiteUrlPlaceholder")}
|
|
/>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
</>
|
|
);
|
|
}
|