mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-24 09:26:48 +08:00
feat: add /api/v1/language endpoint for Go/Python runtime detection (#16952)
Both backends serve GET /api/v1/language. Frontend calls it once and caches. By this way, front end can know the backend is go or python and thus can determine which part of logic to load. --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -181,6 +181,7 @@ export default {
|
||||
`${restAPIv1}/datasets/${datasetId}/ingestions/${logId}`,
|
||||
fetchPipelineDatasetLogs: (datasetId: string) =>
|
||||
`${restAPIv1}/datasets/${datasetId}/ingestions`,
|
||||
listPipelines: `${restAPIv1}/pipelines?type=builtin`,
|
||||
runIndex: (datasetId: string, indexType: string) =>
|
||||
`${restAPIv1}/datasets/${datasetId}/index?type=${indexType.toLowerCase()}`,
|
||||
traceIndex: (datasetId: string, indexType: string) =>
|
||||
|
||||
40
web/src/utils/backend-runtime.ts
Normal file
40
web/src/utils/backend-runtime.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Backend runtime language detection.
|
||||
*
|
||||
* Fetches /api/v1/language once at module load (app start) and caches the
|
||||
* result. Components subscribe via React's useSyncExternalStore; there is no
|
||||
* per-component fetch or useEffect.
|
||||
*
|
||||
* Pattern: module-level fetch + listener set, same subscription approach as
|
||||
* enterprise billingStatus.ts.
|
||||
*/
|
||||
|
||||
type Listener = () => void;
|
||||
const listeners = new Set<Listener>();
|
||||
|
||||
let backendLanguage: string | null = null;
|
||||
|
||||
// Kick off the fetch at module load — app start, not component mount.
|
||||
const promise: Promise<string> = fetch('/api/v1/language')
|
||||
.then((r) => r.json())
|
||||
.then((body: { data?: { language?: string } }) => {
|
||||
backendLanguage = body.data?.language === 'go' ? 'go' : 'python';
|
||||
listeners.forEach((fn) => fn());
|
||||
return backendLanguage;
|
||||
})
|
||||
.catch(() => {
|
||||
backendLanguage = 'python';
|
||||
listeners.forEach((fn) => fn());
|
||||
return 'python';
|
||||
});
|
||||
|
||||
export const fetchBackendLanguage = (): Promise<string> => promise;
|
||||
|
||||
export const getBackendLanguage = (): string | null => backendLanguage;
|
||||
|
||||
export const subscribeBackendLanguage = (listener: Listener): (() => void) => {
|
||||
listeners.add(listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user