-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectnamecheck.js
71 lines (57 loc) · 2.21 KB
/
projectnamecheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const router = require('express').Router();
const { exec } = require('child_process');
const path = require('path');
const logger = require('./loggerProject');
const scriptPath = 'folderexist.bat';
async function checkFolderExists(folderPath) {
return new Promise((resolve, reject) => {
// Execute the batch script to check if the folder exists
exec(`${scriptPath} "${folderPath}"`, (error, stdout, stderr) => {
if (error) {
// An error occurred while executing the script
logger.error("Error executing batch script. We are not able to find if folder exists")
//console.error(`exec error: ${error}`);
const jsonError = JSON.stringify(error);
logger.debug(jsonError);
reject(error);
} else {
// Check if the output contains the folder name
logger.info("Batch script executed successfully to finder folder exits. Result: Folder exists");
//console.log('folder exists')
const folderExists = stdout.includes("ankur1455h5j44h34");
resolve(folderExists);
}
});
});
}
router.get('/',async (req,res)=>{
const path = req.query.projectPath;
// check if folder exists
const finalPath = `..\\Projects\\${path}`;
await checkFolderExists(finalPath)
.then((folderExists) => {
if (folderExists) {
logger.info(`Folder ${finalPath} exists`);
// console.log(`Folder "${finalPath}" exists.`);
return res.status(200).json({
ans: 'true'
})
} else {
logger.info(`Folder "${finalPath}" does not exist`);
//console.log(`Folder "${finalPath}" does not exist.`)
return res.status(200).json({
ans: 'false'
})
}
})
.catch((error) => {
logger.error("An error has occured in checking if Folder exits. Ignoring error Process will continue..");
const jsonError = JSON.stringify(error);
logger.debug(jsonError);
// console.error('An error occurred:', error);
return res.status(500).json({
ans: 'false'
})
});
})
module.exports = router;