fetch config

This commit is contained in:
Fine 2025-05-27 17:23:47 +08:00
parent 82e0846893
commit 2c5f145f5c
3 changed files with 31 additions and 15 deletions

View File

@ -15,12 +15,13 @@
* limitations under the License.
*/
import { httpQuery } from "../base";
import { HttpURL } from "./url";
export default async function fetchQuery({ method, json, url }: { method: string; json?: unknown; url: string }) {
export default async function fetchQuery({ method, json, path }: { method: string; json?: unknown; path: string }) {
const response = await httpQuery({
method,
json,
url,
url: (HttpURL as { [key: string]: string })[path],
});
if (response.errors) {
response.errors = response.errors.map((e: { message: string }) => e.message).join(" ");

View File

@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const ClusterNodes = `/status/cluster/nodes`;
export const ConfigTTL = `/status/config/ttl`;
export const DebuggingConfigDump = `/debugging/config/dump`;
export const HttpURL = {
ClusterNodes: `/status/cluster/nodes`,
ConfigTTL: `/status/config/ttl`,
DebuggingConfigDump: `/debugging/config/dump`,
};

View File

@ -21,28 +21,42 @@ import type { Cluster } from "@/types/settings";
interface SettingsState {
loading: boolean;
nodes: Cluster[];
clusterNodes: Cluster[];
}
export const settingsStore = defineStore({
id: "settings",
state: (): SettingsState => ({
nodes: [],
clusterNodes: [],
loading: false,
}),
actions: {
async getNodes() {
async getClusterNodes() {
this.loading = true;
const res = await fetchQuery({
method: "get",
url: "",
path: "ClusterNodes",
});
this.loading = false;
return res.nodes;
},
async getConfigTTL() {
this.loading = true;
const res = await fetchQuery({
method: "get",
path: "ConfigTTL",
});
this.loading = false;
return res;
},
async getDebuggingConfigDump() {
this.loading = true;
const res = await fetchQuery({
method: "get",
path: "DebuggingConfigDump",
});
this.loading = false;
if (res.errors) {
return res;
}
return res.data;
},
},
});