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. * limitations under the License.
*/ */
import { httpQuery } from "../base"; 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({ const response = await httpQuery({
method, method,
json, json,
url, url: (HttpURL as { [key: string]: string })[path],
}); });
if (response.errors) { if (response.errors) {
response.errors = response.errors.map((e: { message: string }) => e.message).join(" "); 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 * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
export const ClusterNodes = `/status/cluster/nodes`;
export const ConfigTTL = `/status/config/ttl`; export const HttpURL = {
ClusterNodes: `/status/cluster/nodes`,
export const DebuggingConfigDump = `/debugging/config/dump`; ConfigTTL: `/status/config/ttl`,
DebuggingConfigDump: `/debugging/config/dump`,
};

View File

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