mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
feat(edge/templates): introduce edge specific settings [EE-6276] (#10609)
This commit is contained in:
parent
68950fbb24
commit
e43d076269
42 changed files with 885 additions and 319 deletions
44
app/react/edge/edge-stacks/queries/useParseRegistries.ts
Normal file
44
app/react/edge/edge-stacks/queries/useParseRegistries.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { useMutation } from 'react-query';
|
||||
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
import { RegistryId } from '@/react/portainer/registries/types';
|
||||
import axios, {
|
||||
json2formData,
|
||||
parseAxiosError,
|
||||
} from '@/portainer/services/axios';
|
||||
|
||||
import { buildUrl } from './buildUrl';
|
||||
|
||||
export function useParseRegistries() {
|
||||
return useMutation(parseRegistries, {
|
||||
...withError('Failed parsing registries'),
|
||||
});
|
||||
}
|
||||
|
||||
export async function parseRegistries(props: {
|
||||
file?: File;
|
||||
fileContent?: string;
|
||||
}) {
|
||||
if (!props.file && !props.fileContent) {
|
||||
throw new Error('File or fileContent must be provided');
|
||||
}
|
||||
|
||||
let currentFile = props.file;
|
||||
if (!props.file && props.fileContent) {
|
||||
currentFile = new File([props.fileContent], 'registries.yml');
|
||||
}
|
||||
try {
|
||||
const { data } = await axios.post<Array<RegistryId>>(
|
||||
buildUrl(undefined, 'parse_registries'),
|
||||
json2formData({ file: currentFile }),
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
}
|
||||
);
|
||||
return data;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue