update dependencies, move to use es6 modules imports, bind /data/video to /video for easier video displaying

This commit is contained in:
Reaby committed 2022-05-23 18:29:26 +03:00
1 parent 88dbbaa567
commit 04af03891b
28 files changed
+3499 -1639

No files matched your search

+1
View File
@@ -72,3 +72,4 @@ data/*.log
data/template.json
!data/bundles/default
!data/bundles/default/*
data/video/*.mp4
+51 -38
View File
@@ -1,29 +1,50 @@
let config = require("./config.js");
let express = require('express');
let createError = require('http-errors');
let logger = require('morgan');
let lessMiddleware = require('less-middleware');
let path = require('path');
let PluginManager = require("./modules/pluginManager");
const EventEmitter = require('events');
let cookieParser = require('cookie-parser')(config.sessionKey);
import EventEmitter from 'events';
class Dispatcher extends EventEmitter { }
const eventDispatcher = new Dispatcher();
let app = express();
let server = require('http').Server(app);
let io = require('socket.io')(server);
import config from './config.js';
import express from 'express';
import createError from 'http-errors';
import logger from 'morgan';
import lessMiddleware from 'less-middleware';
import path from 'path';
import PluginManager from './modules/pluginManager.js';
const app = express();
const server = Http.Server(app);
const io = new SocketIO(server);
let i18next = require("i18next");
let FilesystemBackend = require("i18next-node-fs-backend");
let i18nextMiddleware = require("i18next-express-middleware");
const pluginManager = new PluginManager(app, io, eventDispatcher);
import WebSocket from './modules/websocket.js';
const websocket = WebSocket(pluginManager, io, eventDispatcher);
import routerIndex from './routes/index.js';
const indexRouter = routerIndex(pluginManager, websocket, eventDispatcher);
import routerAdmin from './routes/admin.js';
const adminRouter = routerAdmin(pluginManager, websocket, eventDispatcher);
import routerAuth from './routes/auth.js';
const authRouter = routerAuth(websocket, eventDispatcher);
let passport = require('passport');
let LocalStrategy = require('passport-local').Strategy;
let User = require("./modules/db.js");
import CookieParser from 'cookie-parser';
import Http from 'http';
import { Server as SocketIO } from 'socket.io';
import i18next from 'i18next';
import FilesystemBackend from 'i18next-node-fs-backend';
import i18nextMiddleware from 'i18next-http-middleware';
import passport from 'passport';
import passportlocal from 'passport-local';
import NodeMediaServer from 'node-media-server';
import expressSession from 'express-session';
import sqlite3 from 'connect-sqlite3';
const SQLiteStore = sqlite3(expressSession);
const cookieParser = CookieParser(config.sessionKey);
const LocalStrategy = passportlocal.Strategy;
import User from './modules/db.js';
import { fileURLToPath } from 'url'
import { dirname } from 'path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
passport.serializeUser(function (user, cb) {
cb(null, user.id);
@@ -57,8 +78,6 @@ passport.use("local", new LocalStrategy({
}));
if (config.mediaServer) {
const NodeMediaServer = require('node-media-server');
const nodeServerConfig = {
logtype: 2,
rtmp: {
@@ -76,11 +95,11 @@ if (config.mediaServer) {
api: true,
api_user: config.admins[0].username,
api_pass: config.admins[0].password,
}
};
let nms = new NodeMediaServer(nodeServerConfig);
const nms = new NodeMediaServer(nodeServerConfig);
nms.run();
}
@@ -135,9 +154,8 @@ app.use(express.urlencoded({
app.use(cookieParser);
app.use(lessMiddleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
app.use("/video/",express.static(path.join(__dirname, 'data','video')));
var expressSession = require('express-session');
var SQLiteStore = require('connect-sqlite3')(expressSession);
var sessionStore = new SQLiteStore({
dir: "./data",
db: "sessions.db"
@@ -188,12 +206,6 @@ function onAuthorizeFail(data, message, error, accept) {
}
*/
let pluginManager = new PluginManager(app, io, eventDispatcher);
let websocket = require("./modules/websocket")(pluginManager, io, eventDispatcher);
let indexRouter = require('./routes/index.js')(pluginManager, websocket, eventDispatcher);
let adminRouter = require('./routes/admin.js')(pluginManager, websocket, eventDispatcher);
let authRouter = require('./routes/auth.js')(websocket, eventDispatcher);
app.use('/', authRouter);
app.use('/', indexRouter);
app.use('/admin', adminRouter);
@@ -214,9 +226,10 @@ app.use(function (err, req, res, next) {
res.render('error');
});
module.exports = {
app: app,
server: server,
io: io,
eventDispatcher: eventDispatcher
export {
app,
server,
io,
eventDispatcher
};
+4 -3
View File
@@ -1,14 +1,15 @@
#!/usr/bin/env node
var fs = require('fs');
import fs from 'fs';
import { daemon } from 'daemon';
var stdoutFd = fs.openSync('./data/output.log', 'a');
var stderrFd = fs.openSync('./data/errors.log', 'a');
var proc2 = require('daemon').daemon("./bin/infoscreen3",
var proc2 = daemon("./bin/infoscreen3",
"",
{
cwd: process.cwd(),
stdout: stdoutFd,
stderr: stderrFd,
stderr: stderrFd,
});
console.log(proc2.pid);
+4 -6
View File
@@ -3,11 +3,10 @@
/**
* Module dependencies.
*/
let cli = require('../modules/cli');
let chalk = require('chalk');
let debug = require('debug')('screen-info:server');
let config = require('../config.js');
let app = require('../app').app;
import cli from '../modules/cli.js';
import chalk from 'chalk';
import config from '../config.js';
import { app, server } from "../app.js";
/**
@@ -21,7 +20,6 @@ app.set('port', port);
* Create HTTP server.
*/
let server = require("../app").server;
/**
* Listen on provided port, on all network interfaces.
+14 -6
View File
@@ -1,6 +1,4 @@
let displays = require(`./data/displays.json`);
module.exports = {
export default {
"serverListenPort": process.env.PORT || 8000,
"serverHost": process.env.HOST || "127.0.0.1",
"serverUrl": "http://" + (process.env.HOST || "127.0.0.1"), // used for web client
@@ -10,8 +8,8 @@ module.exports = {
"mediaServer": false, // local streaming server for rtmp, see docs how to use
"defaultLocale": "en", // currently supported values are: "en","fi"
/*
* Plugins
/*
* Plugins
*/
"plugins": [
"profiler", // display memory statistics at console.
@@ -46,5 +44,15 @@ module.exports = {
}
}
],
"displays": displays
"displays":
[
{
"name": "Main Screen",
"bundle": "default"
},
{
"name": "Secondary Screen",
"bundle": "default"
},
]
};
-14
View File
@@ -1,14 +0,0 @@
[
{
"name": "Big Screen",
"bundle": "default"
},
{
"name": "Secondary Screen",
"bundle": "default"
},
{
"name": "Kiosk",
"bundle": "default"
}
]
View File
Whitespace-only changes.
+20 -26
View File
@@ -1,7 +1,6 @@
let fs = require("fs");
let config = require(`../config.js`);
let cli = require(`./cli.js`);
import fs from 'fs';
import config from '../config.js';
import cli from './cli.js';
/** Generate an uuid
* @url https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript#2117523 **/
@@ -15,7 +14,7 @@ function uuidv4() {
/**
*
*/
class admin {
export default class admin {
/**
* @param sharedIO
@@ -225,11 +224,11 @@ class admin {
self.screenView.overrideSlide(data.json, null, data.duration, data.transition);
}
});
socket.on('admin.overrideVideo', function (data) {
if (data.displayId === null) {
if (data.displayId === null) {
dispatcher.emit("all.override", data);
} else {
} else {
self.screenView.overrideSlide(data.json, null, data.json.duration, null);
}
});
@@ -315,8 +314,8 @@ class admin {
}
socket.emit("callback.webpage", {bundleData: bundleData, json: json});
});
socket.on('edit.saveLink', function (data) {
let filename = data.filename;
@@ -379,16 +378,16 @@ class admin {
}
socket.emit("callback.video", {bundleData: bundleData, json: json});
});
socket.on('edit.saveVideo', function (data) {
let filename = data.filename;
if (filename === "") {
filename = uuidv4();
}
if (data.duration === "") {
if (data.duration === "") {
socket.emit("callback.saveVideo", {erro: "Video duration is not known. Remember to load metadata!"});
return;
}
@@ -398,8 +397,8 @@ class admin {
let template = {
uuid: filename,
name: data.name,
duration: data.duration,
name: data.name,
duration: data.duration,
enabled: true,
displayTime: data.displayTime,
type: "video",
@@ -415,8 +414,8 @@ class admin {
bundle.allSlides.push(template);
} else {
obj.url = data.url;
obj.name = data.name;
obj.duration = data.duration;
obj.name = data.name;
obj.duration = data.duration;
obj.displayTime = data.displayTime;
obj.mute = data.mute;
obj.loop = data.loop;
@@ -476,11 +475,11 @@ class admin {
});
socket.on('edit.saveTemplate', function (data) {
let templates = {};
let templates = {};
if (fs.existsSync("./data/template.json")) {
templates = JSON.parse(fs.readFileSync("./data/template.json").toString());
}
}
templates[data.name] = data.json;
try {
fs.writeFileSync("./data/template.json", JSON.stringify(templates));
@@ -683,8 +682,3 @@ class admin {
// admin
}
/**
* @type {admin}
*/
module.exports = admin;
+7 -11
View File
@@ -1,6 +1,6 @@
let cli = require(`./cli.js`);
import cli from './cli.js'
class adminLobby {
export default class adminLobby {
/**
* @param sharedIO
@@ -66,11 +66,11 @@ class adminLobby {
cli.error("error while duplicating slide", err);
}
});
socket.on('admin.moveSlide', function (data) {
try {
let bundle = bundleManager.moveSlide(data.from, data.to, data.uuid, data.position);
socket.emit("callback.updateBundleData");
try {
let bundle = bundleManager.moveSlide(data.from, data.to, data.uuid, data.position);
socket.emit("callback.updateBundleData");
updateSlides(data.from, bundle);
} catch (err) {
cli.error("error while moving slide", err);
@@ -83,7 +83,7 @@ class adminLobby {
let bundle = bundleManager.getBundle(data.bundleName);
bundle.setName(data.uuid, data.name);
updateSlides(data.bundleName, bundle);
socket.emit("callback.updateBundleData");
socket.emit("callback.updateBundleData");
} catch (err) {
cli.error("error while renaming slide", err);
}
@@ -144,7 +144,3 @@ class adminLobby {
}
}
module.exports = adminLobby;
+5 -11
View File
@@ -1,10 +1,10 @@
let cli = require("./cli.js");
let fs = require("fs");
import fs from 'fs';
import cli from './cli.js';
/**
* @module infoscreen3/bundle
*/
class bundleClass {
export default class bundleClass {
constructor(name, data, slides) {
this.name = name;
@@ -85,11 +85,11 @@ class bundleClass {
if (fs.existsSync(path + "/slides/" + uuid)) {
fs.renameSync(path + "/slides/" + uuid, toPath + "/slides/" + uuid);
}
let slideData = clone(slide);
let slideData = clone(slide);
this.removeUuid(uuid);
return slideData;
} catch (err) {
cli.error("error while moving file:" + uuid, err);
cli.error("error while moving file:" + uuid, err);
return null;
}
}
@@ -231,9 +231,3 @@ function uuidv4() {
return v.toString(16);
});
}
/**
*
* @type {bundleClass}
*/
module.exports = bundleClass;
+7 -12
View File
@@ -1,11 +1,11 @@
const bundle = require(`./bundle.js`);
let fs = require("fs");
let cli = require(`./cli.js`);
import fs from 'fs';
import cli from './cli.js';
import bundle from './bundle.js';
/**
* @module infoscreen3/bundleManager
*/
class bundleManager {
export default class bundleManager {
constructor() {
this.syncBundles();
@@ -49,15 +49,15 @@ class bundleManager {
}
}
moveSlide(fromBundle, toBundle, uuid, position) {
let slideData = this.getBundle(fromBundle).moveTo(toBundle, uuid);
moveSlide(fromBundle, toBundle, uuid, position) {
let slideData = this.getBundle(fromBundle).moveTo(toBundle, uuid);
let bundle = this.getBundle(toBundle);
slideData.index = position;
if (slideData) {
bundle.allSlides.push(slideData);
bundle.save();
}
}
reorderSlides(bundleName, sortedIDs) {
@@ -105,8 +105,3 @@ function getDirectories(path) {
function getJson(file) {
return JSON.parse(fs.readFileSync(file).toString());
}
/**
* @type {bundleManager}
*/
module.exports = bundleManager;
+2 -2
View File
@@ -1,7 +1,7 @@
let chalk = require('chalk');
import chalk from 'chalk';
let lastStamp = "";
module.exports = {
export default {
error: function (error, title) {
if (title == null) {
title = "";
+4 -2
View File
@@ -1,6 +1,8 @@
const records = require(`../config.js`).admins;
import config from '../config.js'
module.exports = {
const records = config.admins;
export default {
findById: function (id, cb) {
process.nextTick(function () {
+3 -8
View File
@@ -1,11 +1,10 @@
'use strict'
let fs = require("fs");
let cli = require(`./cli.js`);
import fs from 'fs';
import cli from './cli.js';
/**
* handles one display instance
*/
class display {
export default class display {
/**
* @param {object} sharedIO - socketIO
@@ -273,7 +272,3 @@ class display {
}
}
/**
* @type {display}
*/
module.exports = display;
+18 -20
View File
@@ -1,6 +1,6 @@
let express = require('express');
let Twig = require('twig');
let fs = require('fs');
import express from 'express';
import Twig from 'twig';
import fs from 'fs';
/**
* Base plugin class
@@ -8,11 +8,11 @@ let fs = require('fs');
* Strucure of plugin:
* D /public/ -- serves files statically at http path: /data/pluginName/
* D /views/ -- directory for twig templates
* F /plugin.js -- pluginfile which will be loaded
*
* F /plugin.js -- pluginfile which will be loaded
*
* if you need external libs, just add `package.json` to the plugin dir, and call npm install :)
*/
class plugin {
export default class plugin {
constructor(pluginName, app, io, dispatcher) {
this.pluginName = pluginName;
@@ -35,33 +35,33 @@ class plugin {
return Twig.twig({ data: fs.readFileSync("plugins/" + this.pluginName + "/views/" + template + ".twig").toString() }).render(data);
}
/**
/**
* Called at infoscreen init-phase
*
* the example will render a view from `pluginName/Views/test.twig` to route `/admin/test`
* @example
*
* the example will render a view from `pluginName/Views/test.twig` to route `/admin/test`
* @example
* let self = this;
* router.get("/test", function (req, res, next) {
* res.send(self.renderPluginView("test", { test: "hello!" }));
* // res.render(); will render from infoscreen/views/*.twig
* });
* @param {express.Router} router
* });
* @param {express.Router} router
*/
onAdminRouter(router) {
}
/**
/**
* Called at infoscreen init-phase
*
*
* the example will render a view from `pluginName/Views/test.twig` to route `/test`
*
*
* @example
* router.get("/test", function (req, res) {
* res.render("test", { test: "hello!" });
* });
*
* @param {express.Router} router
*
* @param {express.Router} router
*/
onPluginRouter(router) {
@@ -72,12 +72,10 @@ class plugin {
}
/**
* Inserts html to display views
*
*
* @returns {string} HTML to be added to display View
*/
setDisplayViewAdditions() {
return "";
}
}
exports.default = plugin;
+13 -11
View File
@@ -1,17 +1,22 @@
let fs = require("fs");
let cli = require(`./cli.js`);
let config = require(`../config.js`);
import fs from 'fs';
import cli from './cli.js'
import config from '../config.js';
class pluginManager {
export default class pluginManager {
constructor(app, io, eventDispatcher) {
this.plugins = {};
this.dispatcher = eventDispatcher;
cli.info("Initializing plugins...");
for (let pluginName of config.plugins) {
this.load(app, io, eventDispatcher);
}
async load(app, io, eventDispatcher) {
for (const pluginName of config.plugins) {
try {
let pluginclass = require("../plugins/" + pluginName + "/plugin.js").default;
let pluginInstance = new pluginclass(pluginName, app, io, eventDispatcher);
const pluginclass = await import("../plugins/" + pluginName + "/plugin.js");
const plugin = pluginclass.default;
let pluginInstance = new plugin(pluginName, app, io, eventDispatcher);
cli.info("" + pluginName, 'plugin');
this.plugins[pluginName] = pluginInstance;
} catch (err) {
@@ -19,7 +24,6 @@ class pluginManager {
}
}
}
callMethod(method, params) {
this.dispatcher.emit("plugin." + method, params);
}
@@ -32,6 +36,4 @@ class pluginManager {
return additions;
}
}
module.exports = pluginManager;
}
+10 -12
View File
@@ -1,14 +1,12 @@
let config = require(`../config.js`);
import config from '../config.js';
let availableDisplays = config.displays;
let display = require(`./display.js`);
let admin = require(`./admin.js`);
let adminLobby = require(`./adminLobby.js`);
let cli = require(`./cli.js`);
let _bundleManager = require(`./bundleManager.js`);
let chalk = require('chalk');
let fs = require('fs');
import display from './display.js';
import admin from './admin.js';
import adminLobby from './adminLobby.js';
import cli from './cli.js';
import _bundleManager from './bundleManager.js';
import chalk from 'chalk';
import fs from 'fs';
/**
* @param server
@@ -17,7 +15,7 @@ let fs = require('fs');
* @param dispatcher
* @return {{screenView: display[], adminView: admin[], bundleManager: bundleManager}}
*/
module.exports = function (pluginManager, io, dispatcher) {
export default function (pluginManager, io, dispatcher) {
/**
* @type {display[]}
*/
@@ -36,7 +34,7 @@ module.exports = function (pluginManager, io, dispatcher) {
cli.error("data directory (./data) is not writable", err);
process.exit(1);
}
try {
fs.accessSync("./tmp", fs.W_OK);
cli.success("temp directory (./tmp) is writable ");
+3259 -1374
View File
File diff suppressed because it is too large. Load diff
+31 -29
View File
@@ -1,42 +1,44 @@
{
"name": "infoscreen3",
"version": "1.4.1",
"version": "1.5.0",
"private": true,
"type": "module",
"exports": "./bin/infoscreen3.js",
"scripts": {
"start": "node --expose-gc ./bin/infoscreen3",
"daemon": "node --expose-gc ./bin/daemon"
"start": "node --expose-gc ./bin/infoscreen3.js",
"daemon": "node --expose-gc ./bin/daemon.js"
},
"dependencies": {
"basic-auth": "^2.0.1",
"bufferutil": "^4.0.3",
"chalk": "^4.1.0",
"connect-busboy": "^0.0.2",
"connect-ensure-login": "^0.1.1",
"connect-sqlite3": "^0.9.11",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"basic-auth": "2.0.1",
"bufferutil": "4.0.6",
"chalk": "5.0.1",
"connect-busboy": "1.0.0",
"connect-ensure-login": "0.1.1",
"connect-sqlite3": "0.9.13",
"cookie-parser": "1.4.6",
"cors": "2.8.5",
"daemon": "1.1.0",
"debug": "4.2.0",
"express": "^4.17.1",
"express-session": "^1.17.1",
"http-errors": "1.8.0",
"i18next": "19.7.0",
"i18next-express-middleware": "2.0.0",
"debug": "4.3.4",
"express": "4.18.1",
"express-session": "1.17.3",
"http-errors": "2.0.0",
"i18next": "21.8.4",
"i18next-http-middleware": "3.2.0",
"i18next-node-fs-backend": "2.1.3",
"less-middleware": "^2.2.1",
"lodash": "^4.17.21",
"minimist": "1.2.5",
"less-middleware": "3.1.0",
"lodash": "4.17.21",
"minimist": "1.2.6",
"morgan": "1.10.0",
"node-media-server": "2.3.8",
"node-media-server": "2.3.9",
"node.extend": "2.0.2",
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"passport.socketio": "^3.7.0",
"rate-limiter-flexible": "^2.2.3",
"socket.io": "^4.1.3",
"sqlite3": "^4.2.0",
"passport": "0.6.0",
"passport-local": "1.0.0",
"passport.socketio": "3.7.0",
"rate-limiter-flexible": "2.3.7",
"socket.io": "4.5.1",
"sqlite3": "5.0.8",
"twig": "1.15.4",
"utf-8-validate": "5.0.5",
"xmlhttprequest-ssl": ">=1.6.2"
"utf-8-validate": "5.0.9",
"xmlhttprequest-ssl": "2.0.0"
}
}
+3 -5
View File
@@ -1,7 +1,7 @@
let plugin = require("../../modules/plugin.js").default;
import plugin from "../../modules/plugin.js";
export default class overlayPlugin extends plugin {
class overlayPlugin extends plugin {
setDisplayViewAdditions() {
return `<style type="text/css">
html, body {
@@ -13,5 +13,3 @@ class overlayPlugin extends plugin {
</style>`;
}
}
exports.default = overlayPlugin;
+5 -8
View File
@@ -1,6 +1,6 @@
let plugin = require("../../modules/plugin.js").default;
let config = require(__dirname + "/config.json");
let exec = require('child_process').exec;
import plugin from "../../modules/plugin.js";
import exec from 'child_process';
import config from './settings.js';
function ping_getTime() {
let d = new Date();
@@ -8,7 +8,7 @@ function ping_getTime() {
}
class myTestPlugin extends plugin {
export default class myTestPlugin extends plugin {
onInit() {
this.cache = 0;
@@ -19,7 +19,7 @@ class myTestPlugin extends plugin {
let self = this;
router.get("/ajax/ping", function (req, res) {
if ((ping_getTime() - self.lastStamp) <= 5 * 1000) {
if ((ping_getTime() - self.lastStamp) <= 5 * 1000) {
return res.json({ ping: self.cache });
}
@@ -43,7 +43,4 @@ class myTestPlugin extends plugin {
setDisplayViewAdditions() {
return this.renderPluginView("pingWidget");
}
}
exports.default = myTestPlugin;
@@ -1,3 +1,3 @@
{
export default {
"host": "localhost"
}
};
+6 -7
View File
@@ -1,12 +1,13 @@
let plugin = require("../../modules/plugin.js").default;
let cli = require('../../modules/cli.js');
let chalk = require('chalk');
import plugin from "../../modules/plugin.js";
import cli from "../../modules/cli.js";
import chalk from 'chalk';
let prevValue = 0;
let startValue = (process.memoryUsage().rss / 1048576).toFixed(1);
function tickHeapDump() {
setImmediate(function () {
var memMB = (process.memoryUsage().rss / 1048576).toFixed(1);
let memMB = (process.memoryUsage().rss / 1048576).toFixed(1);
if (prevValue != memMB) {
let prefix = chalk.bold.red("▲");
if (memMB < prevValue) {
@@ -18,7 +19,7 @@ function tickHeapDump() {
});
}
class profilerPlugin extends plugin {
export default class profilerPlugin extends plugin {
onInit() {
tickHeapDump();
setInterval(() => {
@@ -26,5 +27,3 @@ class profilerPlugin extends plugin {
}, 5000);
}
}
exports.default = profilerPlugin;
+1 -2
View File
@@ -420,7 +420,6 @@ async function preloadImages(data) {
if (count == 0) {
setBackground(bundleData.background);
if (checkStream(serverOptions) === false) {
console.log(".");
nextSlide(data);
}
return;
@@ -445,7 +444,7 @@ async function reloadImage(data) {
/** not in use */
/*
/*
async function checkImages(allSlides) {
let fluxIds = [];
let allIds = [];
+10 -10
View File
@@ -1,10 +1,10 @@
let express = require('express');
let router = express.Router();
let cli = require("../modules/cli.js");
let fs = require('fs');
let path = require('path');
let config = require("../config.js");
let busboy = require("connect-busboy");
import express from 'express';
const router = express.Router();
import cli from '../modules/cli.js';
import fs from 'fs';
import path from 'path';
import config from '../config.js';
import busboy from 'connect-busboy'
function getFiles(path) {
return fs.readdirSync(path).filter(function (file) {
@@ -26,7 +26,7 @@ function ensureIsAdmin(req, res, next) {
next();
}
module.exports = function (pluginManager, websocket, dispatcher) {
export default function (pluginManager, websocket, dispatcher) {
var bundleManager = websocket.bundleManager;
router.use(ensureIsAdmin);
@@ -90,7 +90,7 @@ module.exports = function (pluginManager, websocket, dispatcher) {
req.busboy.on('file', function (fieldname, file, filename, encoding, mimeType) {
if (fieldname === "newBackground")
if (filename.length > 0 && (mimeType === "image/jpeg" || mimeType === "video/mp4" || mimeType === "image/png")) {
if (filename.length > 0 && (mimeType === "image/jpeg" || mimeType === "video/mp4" || mimeType === "image/png")) {
let fstream = fs.createWriteStream('./data/backgrounds/' + filename);
file.pipe(fstream);
} else {
@@ -139,7 +139,7 @@ module.exports = function (pluginManager, websocket, dispatcher) {
bundleData.styleText.fill = fields.textFill;
bundleData.styleText.stroke = fields.textStroke;
bundleData.styleText.strokeWidth = parseInt(fields.textStrokeSize) || 0;
bundle.setBundleData(bundleData);
bundle.save();
+7 -6
View File
@@ -1,7 +1,8 @@
let passport = require("passport");
let express = require('express');
let router = express.Router();
const {RateLimiterMemory} = require('rate-limiter-flexible');
import passport from 'passport';
import express from 'express';
import { RateLimiterMemory } from 'rate-limiter-flexible';
const router = express.Router();
const maxWrongAttemptsByIPperDay = 30;
const maxConsecutiveFailsByUsernameAndIP = 5;
@@ -19,7 +20,7 @@ const limiterConsecutiveFailsByUsernameAndIP = new RateLimiterMemory({
const getUsernameIPkey = (username, ip) => `${username}_${ip}`;
module.exports = function (websocket, dispatcher) {
export default function (websocket, dispatcher) {
router.get('/login', function (req, res, next) {
res.render('auth/login');
@@ -104,6 +105,6 @@ module.exports = function (websocket, dispatcher) {
router.get('/empty', function (req, res, next) {
res.render('empty');
});
return router;
};
+9 -10
View File
@@ -1,10 +1,9 @@
let express = require('express');
let router = express.Router();
let fs = require("fs");
let config = require("../config.js");
let availableDisplays = config.displays;
const cli = require('../modules/cli.js');
const {RateLimiterMemory} = require('rate-limiter-flexible');
import express from 'express';
const router = express.Router();
import config from '../config.js';
import cli from '../modules/cli.js';
import { RateLimiterMemory } from 'rate-limiter-flexible';
const rateLimiter = new RateLimiterMemory({
points: 100, // Number of points
@@ -35,8 +34,9 @@ function ensureIsAdmin(req, res, next) {
}
next();
}
const availableDisplays = config.displays;
module.exports = function (pluginManager, websocket, dispatcher) {
export default function (pluginManager, websocket, dispatcher) {
router.use(ensureIsAdmin);
router.use(rateLimit);
@@ -65,7 +65,7 @@ module.exports = function (pluginManager, websocket, dispatcher) {
});
});
router.get('/display/:id/css', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
let idx = parseInt(req.params.id);
@@ -170,6 +170,5 @@ module.exports = function (pluginManager, websocket, dispatcher) {
});
});
return router;
};
+3 -4
View File
@@ -36,13 +36,12 @@
for (var i in data.displays) {
var display = data.displays[i];
var html = `
<div class="ui card">
<div class="ui card">
<h3 class="ui center aligned top attached header ">${display.name}</h3>
<div onclick="window.location='display/${index.toString()}'" class="image" style="background: black;">
<img src="${data.previewImages[i]}" />
<div onclick="window.location='display/${index.toString()}'" class="image" style="background: black;">
<img src="${data.previewImages[i]}" />
</div>
<div class="content">
<div class="ui attached buttons">
<a href="/display/${index.toString()}" class="ui positive button">{{ t("index.normal") }}</a>
<div class="or" data-text="{{ t("index.splitter") }}"></div>