@@ -4,6 +4,7 @@ const cors = require('cors');
4
4
const { exec } = require ( 'child_process' ) ;
5
5
const path = require ( 'path' ) ;
6
6
const fs = require ( 'fs' ) ;
7
+ const mime = require ( 'mime-types' ) ; // To detect mime type based on file extension
7
8
8
9
const app = express ( ) ;
9
10
const PORT = 3000 ;
@@ -64,12 +65,33 @@ app.post('/clone-repo', (req, res) => {
64
65
65
66
console . log ( `Repository cloned successfully to ${ repoPath } ` ) ;
66
67
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
68
89
const repoUrlPath = `https://sch-ai1z.onrender.com/websites/${ repoName } ` ;
69
90
res . status ( 200 ) . json ( {
70
91
message : 'Repository cloned successfully!' ,
71
92
folderPath : repoPath ,
72
93
repoUrl : repoUrlPath ,
94
+ files : files , // List of files in the repo
73
95
} ) ;
74
96
} ) ;
75
97
} ) ;
0 commit comments