Skip to content

Commit 4d38565

Browse files
authored
Update app.js
1 parent 3c1a89c commit 4d38565

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

app.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const cors = require('cors');
44
const { exec } = require('child_process');
55
const path = require('path');
66
const fs = require('fs');
7+
const mime = require('mime-types'); // To detect mime type based on file extension
78

89
const app = express();
910
const PORT = 3000;
@@ -64,12 +65,33 @@ app.post('/clone-repo', (req, res) => {
6465

6566
console.log(`Repository cloned successfully to ${repoPath}`);
6667

67-
// Return success response with URL to access the cloned repo
68+
// Generate a list of files in the cloned repository
69+
const files = [];
70+
function walkDir(dir) {
71+
const items = fs.readdirSync(dir);
72+
73+
items.forEach(item => {
74+
const itemPath = path.join(dir, item);
75+
const stats = fs.statSync(itemPath);
76+
77+
if (stats.isDirectory()) {
78+
walkDir(itemPath); // Recursively explore directories
79+
} else {
80+
// Store file path relative to the repo
81+
files.push(itemPath.replace(repoPath + '/', ''));
82+
}
83+
});
84+
}
85+
86+
walkDir(repoPath); // Start walking the cloned repo folder
87+
88+
// Return success response with URL to access the cloned repo and file paths
6889
const repoUrlPath = `https://sch-ai1z.onrender.com/websites/${repoName}`;
6990
res.status(200).json({
7091
message: 'Repository cloned successfully!',
7192
folderPath: repoPath,
7293
repoUrl: repoUrlPath,
94+
files: files, // List of files in the repo
7395
});
7496
});
7597
});

0 commit comments

Comments
 (0)