2025-02-03 22:20:50 +00:00
|
|
|
// Copyright 2025, Command Line Inc.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
|
|
import { getApi } from "@/app/store/global";
|
|
|
|
|
import { getWebServerEndpoint } from "@/util/endpoints";
|
|
|
|
|
|
|
|
|
|
type EndpointInfo = {
|
|
|
|
|
uri: string;
|
|
|
|
|
fileMatch: Array<string>;
|
|
|
|
|
schema: object;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const allFilepaths: Map<string, Array<string>> = new Map();
|
|
|
|
|
allFilepaths.set(`${getWebServerEndpoint()}/schema/settings.json`, [`${getApi().getConfigDir()}/settings.json`]);
|
2025-02-04 23:48:42 +00:00
|
|
|
allFilepaths.set(`${getWebServerEndpoint()}/schema/connections.json`, [`${getApi().getConfigDir()}/connections.json`]);
|
2025-02-07 22:56:11 +00:00
|
|
|
allFilepaths.set(`${getWebServerEndpoint()}/schema/aipresets.json`, [`${getApi().getConfigDir()}/presets/ai.json`]);
|
2025-02-03 22:20:50 +00:00
|
|
|
|
|
|
|
|
async function getSchemaEndpointInfo(endpoint: string): Promise<EndpointInfo> {
|
|
|
|
|
let schema: Object;
|
|
|
|
|
try {
|
|
|
|
|
const data = await fetch(endpoint);
|
2025-02-04 23:48:42 +00:00
|
|
|
schema = await data.json();
|
2025-02-03 22:20:50 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
console.log("cannot find schema:", e);
|
|
|
|
|
schema = {};
|
|
|
|
|
}
|
|
|
|
|
const fileMatch = allFilepaths.get(endpoint) ?? [];
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
uri: endpoint,
|
|
|
|
|
fileMatch,
|
|
|
|
|
schema,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SchemaEndpoints = Array.from(allFilepaths.keys());
|
|
|
|
|
|
|
|
|
|
export { getSchemaEndpointInfo, SchemaEndpoints };
|