mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 11:42:21 +08:00
feat: add some clash api
This commit is contained in:
parent
433716cf33
commit
4bb9e10946
|
@ -1,5 +1,23 @@
|
|||
import { useEffect } from "react";
|
||||
import { Box, Typography } from "@mui/material";
|
||||
import services from "../services";
|
||||
|
||||
const LogPage = () => {
|
||||
return <h1>Log</h1>;
|
||||
useEffect(() => {
|
||||
const sourcePromise = services.getLogs(console.log);
|
||||
|
||||
return () => {
|
||||
sourcePromise.then((src) => src.cancel());
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
|
||||
<Typography variant="h4" component="h1" sx={{ py: 2 }}>
|
||||
Logs
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default LogPage;
|
||||
|
|
56
src/services/common.ts
Normal file
56
src/services/common.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
import axios from "axios";
|
||||
import axiosIns from "./base";
|
||||
|
||||
/// Get Version
|
||||
export async function getVersion() {
|
||||
return axiosIns.get("/version") as Promise<{
|
||||
premium: boolean;
|
||||
version: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface ConfigType {
|
||||
port: number;
|
||||
mode: string;
|
||||
"socket-port": number;
|
||||
"allow-lan": boolean;
|
||||
"log-level": string;
|
||||
"mixed-port": number;
|
||||
}
|
||||
|
||||
/// Get current base configs
|
||||
export async function getConfigs() {
|
||||
return axiosIns.get("/configs") as Promise<ConfigType>;
|
||||
}
|
||||
|
||||
/// Update current configs
|
||||
export async function updateConfigs(config: Partial<ConfigType>) {
|
||||
return axiosIns.patch("/configs", config);
|
||||
}
|
||||
|
||||
interface RuleItem {
|
||||
type: string;
|
||||
payload: string;
|
||||
proxy: string;
|
||||
}
|
||||
|
||||
/// Get current rules
|
||||
export async function getRules() {
|
||||
return axiosIns.get("/rules") as Promise<RuleItem[]>;
|
||||
}
|
||||
|
||||
/// Get logs stream
|
||||
export async function getLogs(callback: (t: any) => void) {
|
||||
const source = axios.CancelToken.source();
|
||||
|
||||
axiosIns.get("/logs", {
|
||||
cancelToken: source.token,
|
||||
onDownloadProgress: (progressEvent) => {
|
||||
const data = progressEvent.currentTarget.response || "";
|
||||
const lastData = data.slice(data.trim().lastIndexOf("\n") + 1);
|
||||
callback(JSON.parse(lastData));
|
||||
},
|
||||
});
|
||||
|
||||
return source;
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
import * as common from "./common";
|
||||
import * as proxy from "./proxy";
|
||||
import * as traffic from "./traffic";
|
||||
|
||||
export default {
|
||||
...common,
|
||||
...proxy,
|
||||
...traffic,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user