mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
35 lines
777 B
TypeScript
35 lines
777 B
TypeScript
import { RootState } from 'app/store/store';
|
|
import { useAppSelector } from 'app/store/storeHooks';
|
|
import { useCallback } from 'react';
|
|
import { OpenAPI } from 'services/api';
|
|
|
|
export const getUrlAlt = (url: string, shouldTransformUrls: boolean) => {
|
|
if (OpenAPI.BASE && shouldTransformUrls) {
|
|
return [OpenAPI.BASE, url].join('/');
|
|
}
|
|
|
|
return url;
|
|
};
|
|
|
|
export const useGetUrl = () => {
|
|
const shouldTransformUrls = useAppSelector(
|
|
(state: RootState) => state.config.shouldTransformUrls
|
|
);
|
|
|
|
const getUrl = useCallback(
|
|
(url?: string) => {
|
|
if (OpenAPI.BASE && shouldTransformUrls) {
|
|
return [OpenAPI.BASE, url].join('/');
|
|
}
|
|
|
|
return url;
|
|
},
|
|
[shouldTransformUrls]
|
|
);
|
|
|
|
return {
|
|
shouldTransformUrls,
|
|
getUrl,
|
|
};
|
|
};
|