feat: display log from backend API to toast

This commit is contained in:
Ravinou 2023-09-03 15:39:57 +02:00
parent 1d1c4e01d6
commit 0e72f7a4cf
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
3 changed files with 19 additions and 27 deletions

View file

@ -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) => {

View file

@ -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;

View file

@ -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;