add nanostore for open API schema

This commit is contained in:
Mary Hipp 2024-01-26 16:36:24 -05:00 committed by psychedelicious
parent 55e91b97be
commit de20711637
4 changed files with 26 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import { $customStarUI } from 'app/store/nanostores/customStarUI';
import { $galleryHeader } from 'app/store/nanostores/galleryHeader'; import { $galleryHeader } from 'app/store/nanostores/galleryHeader';
import { $isDebugging } from 'app/store/nanostores/isDebugging'; import { $isDebugging } from 'app/store/nanostores/isDebugging';
import { $logo } from 'app/store/nanostores/logo'; import { $logo } from 'app/store/nanostores/logo';
import { $openAPISchemaUrl } from 'app/store/nanostores/openAPISchemaUrl';
import { $projectId } from 'app/store/nanostores/projectId'; import { $projectId } from 'app/store/nanostores/projectId';
import { $queueId, DEFAULT_QUEUE_ID } from 'app/store/nanostores/queueId'; import { $queueId, DEFAULT_QUEUE_ID } from 'app/store/nanostores/queueId';
import { $store } from 'app/store/nanostores/store'; import { $store } from 'app/store/nanostores/store';
@ -28,6 +29,7 @@ const ThemeLocaleProvider = lazy(() => import('./ThemeLocaleProvider'));
interface Props extends PropsWithChildren { interface Props extends PropsWithChildren {
apiUrl?: string; apiUrl?: string;
openAPISchemaUrl?: string;
token?: string; token?: string;
config?: PartialAppConfig; config?: PartialAppConfig;
customNavComponent?: ReactNode; customNavComponent?: ReactNode;
@ -47,6 +49,7 @@ interface Props extends PropsWithChildren {
const InvokeAIUI = ({ const InvokeAIUI = ({
apiUrl, apiUrl,
openAPISchemaUrl,
token, token,
config, config,
customNavComponent, customNavComponent,
@ -123,6 +126,16 @@ const InvokeAIUI = ({
}; };
}, [customNavComponent]); }, [customNavComponent]);
useEffect(() => {
if (openAPISchemaUrl) {
$openAPISchemaUrl.set(openAPISchemaUrl);
}
return () => {
$openAPISchemaUrl.set(undefined);
};
}, [openAPISchemaUrl]);
useEffect(() => { useEffect(() => {
if (galleryHeader) { if (galleryHeader) {
$galleryHeader.set(galleryHeader); $galleryHeader.set(galleryHeader);

View File

@ -45,7 +45,9 @@ export const useSocketIO = () => {
const socketOptions = useMemo(() => { const socketOptions = useMemo(() => {
const options: Partial<ManagerOptions & SocketOptions> = { const options: Partial<ManagerOptions & SocketOptions> = {
timeout: 60000, timeout: 60000,
path: baseUrl ? '/ws/socket.io' : `${window.location.pathname}ws/socket.io`, path: baseUrl
? '/ws/socket.io'
: `${window.location.pathname}ws/socket.io`,
autoConnect: false, // achtung! removing this breaks the dynamic middleware autoConnect: false, // achtung! removing this breaks the dynamic middleware
forceNew: true, forceNew: true,
}; };

View File

@ -0,0 +1,3 @@
import { atom } from 'nanostores';
export const $openAPISchemaUrl = atom<string | undefined>(undefined);

View File

@ -1,4 +1,5 @@
import { createAsyncThunk } from '@reduxjs/toolkit'; import { createAsyncThunk } from '@reduxjs/toolkit';
import { $openAPISchemaUrl } from 'app/store/nanostores/openAPISchemaUrl';
function getCircularReplacer() { function getCircularReplacer() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -26,9 +27,12 @@ export const receivedOpenAPISchema = createAsyncThunk(
'nodes/receivedOpenAPISchema', 'nodes/receivedOpenAPISchema',
async (_, { rejectWithValue }) => { async (_, { rejectWithValue }) => {
try { try {
const response = await fetch( const openAPISchemaUrl = $openAPISchemaUrl.get();
`${window.location.href.replace(/\/$/, '')}/openapi.json`
); const url = openAPISchemaUrl
? openAPISchemaUrl
: `${window.location.href.replace(/\/$/, '')}/openapi.json`;
const response = await fetch(url);
const openAPISchema = await response.json(); const openAPISchema = await response.json();
const schemaJSON = JSON.parse( const schemaJSON = JSON.parse(