aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/index.js
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2024-08-19 17:58:55 +0800
committerHsiangNianian <i@jyunko.cn>2024-08-19 17:58:55 +0800
commitb5c3c046f17eb28555f9398bcbc741ae8240676b (patch)
tree6632d44cd46591fbf886290202321f7814463963 /index.js
parentcf2d0d388fc2a4b12a23cd0328fcd566ba19fd31 (diff)
downloadfiles-b5c3c046f17eb28555f9398bcbc741ae8240676b.tar.gz
files-b5c3c046f17eb28555f9398bcbc741ae8240676b.zip
chore: update content
Diffstat (limited to 'index.js')
-rw-r--r--index.js30
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