mirror of
https://github.com/Ravinou/borgwarehouse
synced 2024-05-17 21:16:39 +02:00
feat: display log from backend API to toast
This commit is contained in:
parent
1d1c4e01d6
commit
0e72f7a4cf
|
@ -178,7 +178,7 @@ export default function RepoManage(props) {
|
|||
},
|
||||
body: JSON.stringify(newRepo),
|
||||
})
|
||||
.then((response) => {
|
||||
.then(async (response) => {
|
||||
if (response.ok) {
|
||||
toast.success(
|
||||
'New repository added ! 🥳',
|
||||
|
@ -186,9 +186,13 @@ export default function RepoManage(props) {
|
|||
);
|
||||
router.replace('/');
|
||||
} else {
|
||||
toast.error('An error has occurred', toastOptions);
|
||||
const errorMessage = await response.json();
|
||||
toast.error(
|
||||
`An error has occurred : ${errorMessage.message}`,
|
||||
toastOptions
|
||||
);
|
||||
router.replace('/');
|
||||
console.log('Fail to post');
|
||||
console.log(`Fail to ${props.mode}`);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
@ -213,7 +217,7 @@ export default function RepoManage(props) {
|
|||
},
|
||||
body: JSON.stringify(dataEdited),
|
||||
})
|
||||
.then((response) => {
|
||||
.then(async (response) => {
|
||||
if (response.ok) {
|
||||
toast.success(
|
||||
'The repository #' +
|
||||
|
@ -223,9 +227,13 @@ export default function RepoManage(props) {
|
|||
);
|
||||
router.replace('/');
|
||||
} else {
|
||||
toast.error('An error has occurred', toastOptions);
|
||||
const errorMessage = await response.json();
|
||||
toast.error(
|
||||
`An error has occurred : ${errorMessage.message}`,
|
||||
toastOptions
|
||||
);
|
||||
router.replace('/');
|
||||
console.log('Fail to PUT');
|
||||
console.log(`Fail to ${props.mode}`);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
|
@ -65,17 +65,10 @@ export default async function handler(req, res) {
|
|||
//Find the absolute path of the shells directory
|
||||
const shellsDirectory = path.join(process.cwd(), '/helpers');
|
||||
//Exec the shell
|
||||
const { stdout, stderr } = await exec(
|
||||
const { stdout } = await exec(
|
||||
`${shellsDirectory}/shells/createRepo.sh "${newRepo.sshPublicKey}" ${newRepo.storageSize}`
|
||||
);
|
||||
if (stderr) {
|
||||
console.log('stderr:', stderr);
|
||||
res.status(500).json({
|
||||
status: 500,
|
||||
message: 'Error on creation, contact the administrator.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
newRepo.repositoryName = stdout.trim();
|
||||
|
||||
//Create the new repoList with the new repo
|
||||
|
@ -105,7 +98,7 @@ export default async function handler(req, res) {
|
|||
} else {
|
||||
res.status(500).json({
|
||||
status: 500,
|
||||
message: 'API error, contact the administrator',
|
||||
message: error.stdout,
|
||||
});
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -28,7 +28,6 @@ export default async function handler(req, res) {
|
|||
}
|
||||
|
||||
try {
|
||||
//console.log('API call (PUT)');
|
||||
//Find the absolute path of the json directory
|
||||
const jsonDirectory = path.join(process.cwd(), '/config');
|
||||
let repoList = await fs.readFile(
|
||||
|
@ -48,17 +47,9 @@ export default async function handler(req, res) {
|
|||
//Find the absolute path of the shells directory
|
||||
const shellsDirectory = path.join(process.cwd(), '/helpers');
|
||||
// //Exec the shell
|
||||
const { stderr } = await exec(
|
||||
await exec(
|
||||
`${shellsDirectory}/shells/updateRepo.sh ${repoList[repoIndex].repositoryName} "${sshPublicKey}" ${size}`
|
||||
);
|
||||
if (stderr) {
|
||||
console.log('stderr:', stderr);
|
||||
res.status(500).json({
|
||||
status: 500,
|
||||
message: 'Error on update, contact the administrator.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//Find the ID in the data and change the values transmitted by the form
|
||||
let newRepoList = repoList.map((repo) =>
|
||||
|
@ -97,7 +88,7 @@ export default async function handler(req, res) {
|
|||
} else {
|
||||
res.status(500).json({
|
||||
status: 500,
|
||||
message: 'API error, contact the administrator',
|
||||
message: error.stdout,
|
||||
});
|
||||
}
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue