diff options
| author | 2024-08-19 17:58:55 +0800 | |
|---|---|---|
| committer | 2024-08-19 17:58:55 +0800 | |
| commit | b5c3c046f17eb28555f9398bcbc741ae8240676b (patch) | |
| tree | 6632d44cd46591fbf886290202321f7814463963 /index.js | |
| parent | cf2d0d388fc2a4b12a23cd0328fcd566ba19fd31 (diff) | |
| download | files-b5c3c046f17eb28555f9398bcbc741ae8240676b.tar.gz files-b5c3c046f17eb28555f9398bcbc741ae8240676b.zip | |
chore: update content
Diffstat (limited to 'index.js')
| -rw-r--r-- | index.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/index.js b/index.js new file mode 100644 index 0000000..51c542b --- /dev/null +++ b/index.js @@ -0,0 +1,30 @@ +const express = require('express'); +const fs = require('fs'); +const path = require('path'); + +const app = express(); +const PORT = 3000; + +app.use(express.static('public')); + +app.get('/api/files', (req, res) => { + const directoryPath = path.join(__dirname, 'files'); + const getDirectoryTree = (dirPath) => { + const files = fs.readdirSync(dirPath); + return files.map(file => { + const filePath = path.join(dirPath, file); + const isDirectory = fs.statSync(filePath).isDirectory(); + return { + name: file, + path: filePath, + isDirectory, + children: isDirectory ? getDirectoryTree(filePath) : [] + }; + }); + }; + res.json(getDirectoryTree(directoryPath)); +}); + +app.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); +});
\ No newline at end of file |
