17971a10cc
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
30 lines
792 B
TypeScript
30 lines
792 B
TypeScript
import { useQuery } from 'react-query';
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
import { withError } from '@/react-tools/react-query';
|
|
|
|
import { StackFile, StackId } from '../types';
|
|
|
|
import { stacksQueryKeys } from './query-keys';
|
|
import { buildStackUrl } from './buildUrl';
|
|
|
|
export function useStackFile(stackId?: StackId) {
|
|
return useQuery(
|
|
stacksQueryKeys.stackFile(stackId || 0),
|
|
() => getStackFile(stackId!),
|
|
{
|
|
...withError('Unable to retrieve stack'),
|
|
enabled: !!stackId,
|
|
}
|
|
);
|
|
}
|
|
|
|
async function getStackFile(stackId: StackId) {
|
|
try {
|
|
const { data } = await axios.get<StackFile>(buildStackUrl(stackId, 'file'));
|
|
return data;
|
|
} catch (err) {
|
|
throw parseAxiosError(err, 'Unable to retrieve stack file');
|
|
}
|
|
}
|