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