|
@@ -124,7 +124,7 @@ function wrapInFrame(content) {
|
|
|
|
|
|
|
|
function getNewestScreen() {
|
|
function getNewestScreen() {
|
|
|
const files = fs.readdirSync(CONTENT_DIR)
|
|
const files = fs.readdirSync(CONTENT_DIR)
|
|
|
- .filter(f => f.endsWith('.html'))
|
|
|
|
|
|
|
+ .filter(f => !f.startsWith('.') && f.endsWith('.html'))
|
|
|
.map(f => {
|
|
.map(f => {
|
|
|
const fp = path.join(CONTENT_DIR, f);
|
|
const fp = path.join(CONTENT_DIR, f);
|
|
|
return { path: fp, mtime: fs.statSync(fp).mtime.getTime() };
|
|
return { path: fp, mtime: fs.statSync(fp).mtime.getTime() };
|
|
@@ -152,9 +152,9 @@ function handleRequest(req, res) {
|
|
|
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
|
res.end(html);
|
|
res.end(html);
|
|
|
} else if (req.method === 'GET' && req.url.startsWith('/files/')) {
|
|
} else if (req.method === 'GET' && req.url.startsWith('/files/')) {
|
|
|
- const fileName = req.url.slice(7);
|
|
|
|
|
- const filePath = path.join(CONTENT_DIR, path.basename(fileName));
|
|
|
|
|
- if (!fs.existsSync(filePath)) {
|
|
|
|
|
|
|
+ const fileName = path.basename(req.url.slice(7));
|
|
|
|
|
+ const filePath = path.join(CONTENT_DIR, fileName);
|
|
|
|
|
+ if (fileName.startsWith('.') || !fs.existsSync(filePath)) {
|
|
|
res.writeHead(404);
|
|
res.writeHead(404);
|
|
|
res.end('Not found');
|
|
res.end('Not found');
|
|
|
return;
|
|
return;
|
|
@@ -276,14 +276,14 @@ function startServer() {
|
|
|
// macOS fs.watch reports 'rename' for both new files and overwrites,
|
|
// macOS fs.watch reports 'rename' for both new files and overwrites,
|
|
|
// so we can't rely on eventType alone.
|
|
// so we can't rely on eventType alone.
|
|
|
const knownFiles = new Set(
|
|
const knownFiles = new Set(
|
|
|
- fs.readdirSync(CONTENT_DIR).filter(f => f.endsWith('.html'))
|
|
|
|
|
|
|
+ fs.readdirSync(CONTENT_DIR).filter(f => !f.startsWith('.') && f.endsWith('.html'))
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
const server = http.createServer(handleRequest);
|
|
const server = http.createServer(handleRequest);
|
|
|
server.on('upgrade', handleUpgrade);
|
|
server.on('upgrade', handleUpgrade);
|
|
|
|
|
|
|
|
const watcher = fs.watch(CONTENT_DIR, (eventType, filename) => {
|
|
const watcher = fs.watch(CONTENT_DIR, (eventType, filename) => {
|
|
|
- if (!filename || !filename.endsWith('.html')) return;
|
|
|
|
|
|
|
+ if (!filename || filename.startsWith('.') || !filename.endsWith('.html')) return;
|
|
|
|
|
|
|
|
if (debounceTimers.has(filename)) clearTimeout(debounceTimers.get(filename));
|
|
if (debounceTimers.has(filename)) clearTimeout(debounceTimers.get(filename));
|
|
|
debounceTimers.set(filename, setTimeout(() => {
|
|
debounceTimers.set(filename, setTimeout(() => {
|