mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-31 19:22:15 +08:00
feat: block official provider switching during proxy takeover
Prevent users from switching to official providers (Anthropic/OpenAI/Google)
when proxy takeover is active, as using a proxy with official APIs may cause
account bans.
Defense-in-depth across 4 layers:
- Backend: ProviderService::switch(), hot_switch_provider(), switch_proxy_provider command
- Frontend: useProviderActions soft guard with error toast
- UI: ProviderActions button disabled with ShieldAlert icon
- Tray menu: official provider items disabled with ⛔ indicator
Also warns when enabling proxy takeover while current provider is official.
This commit is contained in:
+31
-1
@@ -270,7 +270,11 @@ function App() {
|
||||
deleteProvider,
|
||||
saveUsageScript,
|
||||
setAsDefaultModel,
|
||||
} = useProviderActions(activeApp, isProxyRunning);
|
||||
} = useProviderActions(
|
||||
activeApp,
|
||||
isProxyRunning,
|
||||
isProxyRunning && isCurrentAppTakeoverActive,
|
||||
);
|
||||
|
||||
const disableOmoMutation = useDisableCurrentOmo();
|
||||
const handleDisableOmo = () => {
|
||||
@@ -401,6 +405,32 @@ function App() {
|
||||
};
|
||||
}, [queryClient, t]);
|
||||
|
||||
// Listen for proxy-official-warning: warn when takeover is enabled with an official provider
|
||||
useEffect(() => {
|
||||
let unsubscribe: (() => void) | undefined;
|
||||
|
||||
const setup = async () => {
|
||||
unsubscribe = await listen("proxy-official-warning", (event) => {
|
||||
const { providerName } = event.payload as {
|
||||
appType: string;
|
||||
providerName: string;
|
||||
};
|
||||
toast.warning(
|
||||
t("notifications.proxyOfficialWarning", {
|
||||
name: providerName,
|
||||
defaultValue: `当前供应商 ${providerName} 是官方供应商,建议切换到第三方供应商后再使用代理接管`,
|
||||
}),
|
||||
{ duration: 8000 },
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
void setup();
|
||||
return () => {
|
||||
unsubscribe?.();
|
||||
};
|
||||
}, [t]);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
let unlistenResize: (() => void) | undefined;
|
||||
|
||||
Reference in New Issue
Block a user