-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (35 loc) · 1.02 KB
/
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
const express = require("express");
const app = express();
const path = require("path");
const fs = require("fs");
const config = require("./config.json");
const port = config.port;
// Get videos from webserver assets folder
app.get("/dir", (req, res) => {
providedPath = req.query.path;
let filePath = "public/assets";
if (providedPath) {
filePath = `${filePath}/${providedPath}`;
}
const directoryPath = path.join(__dirname, filePath);
const dirList = [];
fs.readdir(directoryPath, function (err, files) {
if (err) {
return console.log("FS Error: " + err);
}
files.forEach(function (file) {
if (file[0] === ".") return; // ignore hidden files.
const filePath = path.join(directoryPath, file);
dirList.push({
file,
isDir: fs.statSync(filePath).isDirectory(),
});
});
res.send(dirList);
});
});
app.use("/", express.static(__dirname + "/public"));
// Start server
app.listen(port, function () {
console.log("Video server running on " + port + "...");
});