feat: support proxy provider update
This commit is contained in:
parent
2bcaf90fc8
commit
b4cce23ef4
86
src/components/proxy/provider-button.tsx
Normal file
86
src/components/proxy/provider-button.tsx
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import dayjs from "dayjs";
|
||||||
|
import useSWR, { mutate } from "swr";
|
||||||
|
import { useState } from "react";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
IconButton,
|
||||||
|
List,
|
||||||
|
ListItem,
|
||||||
|
ListItemText,
|
||||||
|
} from "@mui/material";
|
||||||
|
import { RefreshRounded } from "@mui/icons-material";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useLockFn } from "ahooks";
|
||||||
|
import { getProviders, providerUpdate } from "@/services/api";
|
||||||
|
import { BaseDialog } from "../base";
|
||||||
|
|
||||||
|
export const ProviderButton = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { data } = useSWR("getProviders", getProviders);
|
||||||
|
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
const hasProvider = Object.keys(data || {}).length > 0;
|
||||||
|
|
||||||
|
const handleUpdate = useLockFn(async (key: string) => {
|
||||||
|
await providerUpdate(key);
|
||||||
|
await mutate("getProxies");
|
||||||
|
await mutate("getProviders");
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hasProvider) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
sx={{ textTransform: "capitalize" }}
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
|
>
|
||||||
|
{t("Provider")}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<BaseDialog
|
||||||
|
open={open}
|
||||||
|
title={t("Proxy Provider")}
|
||||||
|
contentSx={{ width: 400 }}
|
||||||
|
disableOk
|
||||||
|
cancelBtn={t("Cancel")}
|
||||||
|
onClose={() => setOpen(false)}
|
||||||
|
onCancel={() => setOpen(false)}
|
||||||
|
>
|
||||||
|
<List sx={{ py: 0, minHeight: 250 }}>
|
||||||
|
{Object.entries(data || {}).map(([key, item]) => {
|
||||||
|
const time = dayjs(item.updatedAt);
|
||||||
|
return (
|
||||||
|
<ListItem sx={{ p: 0 }}>
|
||||||
|
<ListItemText
|
||||||
|
primary={key}
|
||||||
|
secondary={
|
||||||
|
<div>
|
||||||
|
<span style={{ marginRight: "4em" }}>
|
||||||
|
Type: {item.vehicleType}
|
||||||
|
</span>
|
||||||
|
<span title={time.format("YYYY-MM-DD HH:mm:ss")}>
|
||||||
|
Updated: {time.fromNow()}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
color="inherit"
|
||||||
|
title="Update Provider"
|
||||||
|
onClick={() => handleUpdate(key)}
|
||||||
|
>
|
||||||
|
<RefreshRounded />
|
||||||
|
</IconButton>
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</List>
|
||||||
|
</BaseDialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
@ -48,6 +48,7 @@ const Layout = () => {
|
|||||||
mutate("getProxies");
|
mutate("getProxies");
|
||||||
mutate("getVersion");
|
mutate("getVersion");
|
||||||
mutate("getClashConfig");
|
mutate("getClashConfig");
|
||||||
|
mutate("getProviders");
|
||||||
});
|
});
|
||||||
|
|
||||||
// update the verge config
|
// update the verge config
|
||||||
|
@ -2,7 +2,7 @@ import useSWR from "swr";
|
|||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Button, ButtonGroup, Paper } from "@mui/material";
|
import { Box, Button, ButtonGroup, Paper } from "@mui/material";
|
||||||
import {
|
import {
|
||||||
closeAllConnections,
|
closeAllConnections,
|
||||||
getClashConfig,
|
getClashConfig,
|
||||||
@ -12,6 +12,7 @@ import { patchClashConfig } from "@/services/cmds";
|
|||||||
import { useVerge } from "@/hooks/use-verge";
|
import { useVerge } from "@/hooks/use-verge";
|
||||||
import { BasePage } from "@/components/base";
|
import { BasePage } from "@/components/base";
|
||||||
import { ProxyGroups } from "@/components/proxy/proxy-groups";
|
import { ProxyGroups } from "@/components/proxy/proxy-groups";
|
||||||
|
import { ProviderButton } from "@/components/proxy/provider-button";
|
||||||
|
|
||||||
const ProxyPage = () => {
|
const ProxyPage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -53,6 +54,9 @@ const ProxyPage = () => {
|
|||||||
contentStyle={{ height: "100%" }}
|
contentStyle={{ height: "100%" }}
|
||||||
title={t("Proxy Groups")}
|
title={t("Proxy Groups")}
|
||||||
header={
|
header={
|
||||||
|
<Box display="flex" alignItems="center" gap={1}>
|
||||||
|
<ProviderButton />
|
||||||
|
|
||||||
<ButtonGroup size="small">
|
<ButtonGroup size="small">
|
||||||
{modeList.map((mode) => (
|
{modeList.map((mode) => (
|
||||||
<Button
|
<Button
|
||||||
@ -65,6 +69,7 @@ const ProxyPage = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
))}
|
))}
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
|
</Box>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Paper
|
<Paper
|
||||||
|
@ -169,6 +169,11 @@ export const providerHealthCheck = async (name: string) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const providerUpdate = async (name: string) => {
|
||||||
|
const instance = await getAxios();
|
||||||
|
return instance.put(`/providers/proxies/${encodeURIComponent(name)}`);
|
||||||
|
};
|
||||||
|
|
||||||
export const getConnections = async () => {
|
export const getConnections = async () => {
|
||||||
const instance = await getAxios();
|
const instance = await getAxios();
|
||||||
const result = await instance.get("/connections");
|
const result = await instance.get("/connections");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user