mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-11 10:47:27 +03:00
24 lines
652 B
JavaScript
24 lines
652 B
JavaScript
import ShlinkApiClient from './ShlinkApiClient';
|
|
|
|
const apiClients = {};
|
|
|
|
const getSelectedServerFromState = (getState) => {
|
|
const { selectedServer } = getState();
|
|
|
|
return selectedServer;
|
|
};
|
|
|
|
const buildShlinkApiClient = (axios) => (getStateOrSelectedServer) => {
|
|
const { url, apiKey } = typeof getStateOrSelectedServer === 'function'
|
|
? getSelectedServerFromState(getStateOrSelectedServer)
|
|
: getStateOrSelectedServer;
|
|
const clientKey = `${url}_${apiKey}`;
|
|
|
|
if (!apiClients[clientKey]) {
|
|
apiClients[clientKey] = new ShlinkApiClient(axios, url, apiKey);
|
|
}
|
|
|
|
return apiClients[clientKey];
|
|
};
|
|
|
|
export default buildShlinkApiClient;
|