-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (34 loc) · 879 Bytes
/
server.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
const express = require('express');
const fs = require('fs');
const path = require('path');
const cors = require('cors');
const app = express();
app.use(cors());
const directoryPath = '/';
const getFiles = () => {
const files = fs.readdirSync(directoryPath);
return files.map((file) => ({
name: file,
active: true,
}));
};
let files = getFiles();
app.get('/list', (req, res) => {
res.send(files);
});
app.get('/scan', (req, res) => {
files = getFiles();
res.send({ message: 'Directory scanned successfully' });
});
app.get('/download-state', (req, res) => {
const dataStr =
'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(files));
res.setHeader(
'Content-Disposition',
'attachment; filename="file_state.json"'
);
res.send(dataStr);
});
app.listen(3001, () => {
console.log('Server running on port 3001');
});