diff --git a/app.js b/app.js index c236cbf..fb1a83b 100644 --- a/app.js +++ b/app.js @@ -1,57 +1,57 @@ -const express = require('express'); -const path = require('path'); -const favicon = require('serve-favicon'); -const logger = require('morgan'); -const cookieParser = require('cookie-parser'); -const bodyParser = require('body-parser'); -const { WebSocketServer } = require('ws'); -const fs = require('fs'); -const {createServer} = require('http'); -const sessions = require('express-session'); -const _ = require('lodash'); +const express = require("express"); +const path = require("path"); +const favicon = require("serve-favicon"); +const logger = require("morgan"); +const cookieParser = require("cookie-parser"); +const bodyParser = require("body-parser"); +const { WebSocketServer } = require("ws"); +const fs = require("fs"); +const { createServer } = require("http"); +const sessions = require("express-session"); +const _ = require("lodash"); l = console.log; -const { deleteOldFiles } = require('./scripts/deleteTranscriptionUploads'); +const { deleteOldFiles } = require("./scripts/deleteTranscriptionUploads"); // Load the .env file -require('dotenv').config(); +require("dotenv").config(); -const { createWebSocketServer } = require('./lib/websockets'); +const { createWebSocketServer } = require("./lib/websockets"); -l('node env'); +l("node env"); l(process.env.NODE_ENV); // run stats gathering -require('./lib/stats'); +require("./lib/stats"); // Check if the .env file exists -if (!fs.existsSync('.env')) { - // If the .env file does not exist, copy the .env.sample file to .env - fs.copyFileSync('.env.sample', '.env'); +if (!fs.existsSync(".env")) { + // If the .env file does not exist, copy the .env.sample file to .env + fs.copyFileSync(".env.sample", ".env"); } const hourInMilliseconds = 1000 * 60 * 60; -function runDeleteLoop () { - setTimeout(() => { - deleteOldFiles(true); - runDeleteLoop(); - }, hourInMilliseconds); // repeat every 1000 milliseconds (1 second) +function runDeleteLoop() { + setTimeout(() => { + deleteOldFiles(true); + runDeleteLoop(); + }, hourInMilliseconds); // repeat every 1000 milliseconds (1 second) } -if (process.env.NODE_ENV === 'production') { - deleteOldFiles(true); - runDeleteLoop(); +if (process.env.NODE_ENV === "production") { + deleteOldFiles(true); + runDeleteLoop(); } l(`FILES PASSWORD: ${process.env.FILES_PASSWORD}`); -const routes = require('./routes/index'); -const users = require('./routes/users'); -const api = require('./routes/api'); -const stats = require('./routes/stats'); -const player = require('./routes/player'); -const transcribe = require('./routes/transcribe'); -const admin = require('./routes/admin'); +const routes = require("./routes/index"); +const users = require("./routes/users"); +const api = require("./routes/api"); +const stats = require("./routes/stats"); +const player = require("./routes/player"); +const transcribe = require("./routes/transcribe"); +const admin = require("./routes/admin"); const app = express(); const server = createServer(app); @@ -61,98 +61,101 @@ createWebSocketServer(server); l = console.log; // l = function(l) { -// var stack = (new Error()).stack.split(/\n/); +// let stack = (new Error()).stack.split(/\n/); // // Chrome includes a single "Error" line, FF doesn't. // if (stack[0].indexOf('Error') === 0) { // stack = stack.slice(1); // } -// var args = [].slice.apply(arguments).concat([stack[1].trim()]); +// let args = [].slice.apply(arguments).concat([stack[1].trim()]); // return console.log(console, args); // } -const port = process.env.PORT || '3000'; -app.set('port', port); +const port = process.env.PORT || "3000"; +app.set("port", port); // create folders if they don't exist yet // fs.mkdirSync('uploads', { recursive: true }) -fs.mkdirSync('uploads', { recursive: true }) -fs.mkdirSync('transcriptions', { recursive: true }) +fs.mkdirSync("uploads", { recursive: true }); +fs.mkdirSync("transcriptions", { recursive: true }); // view engine setup -app.set('views', path.join(__dirname, 'views')); -app.set('view engine', 'pug'); +app.set("views", path.join(__dirname, "views")); +app.set("view engine", "pug"); -app.use(favicon(path.join(__dirname,'public','images','favicon.ico'))); -app.use(logger('dev')); -app.use(bodyParser.json({ limit: '1mb' })); -app.use(bodyParser.urlencoded({ extended: true, limit: '1mb' })); +app.use(favicon(path.join(__dirname, "public", "images", "favicon.ico"))); +app.use(logger("dev")); +app.use(bodyParser.json({ limit: "1mb" })); +app.use(bodyParser.urlencoded({ extended: true, limit: "1mb" })); app.use(cookieParser()); -app.use(express.static(path.join(__dirname, 'public'))); +app.use(express.static(path.join(__dirname, "public"))); // assumes nginx // if(!isProd){ - // TODO: this isn't secure if the API key is there - app.use(express.static(__dirname)); +// TODO: this isn't secure if the API key is there +app.use(express.static(__dirname)); // } const oneWeek = 1000 * 60 * 60 * 24 * 7; //session middleware -app.use(sessions({ - secret: (Math.random() * 1000000000).toString(), - cookie: { maxAge: oneWeek }, - saveUninitialized: false, - resave: false -})); +app.use( + sessions({ + secret: (Math.random() * 1000000000).toString(), + cookie: { maxAge: oneWeek }, + saveUninitialized: false, + resave: false, + }) +); app.use(function (req, res, next) { - const ipAddress = req.headers['x-forwarded-for'] || req.socket.remoteAddress; - l('IP Address') - l(ipAddress); - next(); -}) - -app.use('/', routes); -app.use('/', api); -app.use('/users', users); -app.use('/', stats); -app.use('/', transcribe); -app.use('/', admin); -app.use('/', player); + const ipAddress = + req.headers["x-forwarded-for"] || req.socket.remoteAddress; + l("IP Address"); + l(ipAddress); + next(); +}); + +app.use("/", routes); +app.use("/", api); +app.use("/users", users); +app.use("/", stats); +app.use("/", transcribe); +app.use("/", admin); +app.use("/", player); // catch 404 and forward to error handler app.use(function (req, res, next) { - let err = new Error('Not Found'); - err.status = 404; - next(err); + let err = new Error("Not Found"); + err.status = 404; + next(err); }); // error handlers // development error handler // will print stacktrace -if (app.get('env') === 'development') { - app.use(function (err, req, res, next) { - l(err); - - res.status(err.status || 500); - res.render('error', { - message: err.message, - error: err - }); - }); +if (app.get("env") === "development") { + app.use(function (err, req, res, next) { + l(err); + + res.status(err.status || 500); + res.render("error", { + message: err.message, + error: err, + }); + }); } // production error handler // no stacktraces leaked to user app.use(function (err, req, res, next) { - l(err); - res.status(err.status || 500); - res.render('error', { - message: err.message, - error: {} - }); + l(err); + res.status(err.status || 500); + res.render("error", { + message: err.message, + error: {}, + }); }); -l(`Server listening on port ${port}`) +l(`Server listening on port ${port}`); server.listen(port); diff --git a/views/files.pug b/views/files.pug index 7175c60..0049d6e 100644 --- a/views/files.pug +++ b/views/files.pug @@ -54,17 +54,17 @@ block content } } - var table = document.getElementById("myTable"); - var currentSort = null; // Keep track of the current sort column + let table = document.getElementById("myTable"); + let currentSort = null; // Keep track of the current sort column table.addEventListener("click", function (event) { // Get the element that was clicked - var element = event.target; + let element = event.target; // If the element is a table header, sort the table by the corresponding column if (element.tagName == "TH") { // Get the index of the column that was clicked - var index = Array.prototype.indexOf.call(element.parentNode.children, element); + let index = Array.prototype.indexOf.call(element.parentNode.children, element); // If the same column was clicked twice, reverse the sort order if (currentSort === index) { @@ -80,16 +80,16 @@ block content function sortTable(table, column, sortOrder) { // Get the rows of the table - var rows = table.rows; + let rows = table.rows; // Convert the rows to an array (we'll need to sort this array) - var rowArray = Array.prototype.slice.call(rows, 1); + let rowArray = Array.prototype.slice.call(rows, 1); // Sort the array of rows according to the values in the specified column rowArray.sort(function (a, b) { // Get the text content of the cells in the specified column - var A = a.cells[column].getAttribute("data-sort-value"); - var B = b.cells[column].getAttribute("data-sort-value"); + let A = a.cells[column].getAttribute("data-sort-value"); + let B = b.cells[column].getAttribute("data-sort-value"); // Check if the values are numeric or not if (isNaN(A) || isNaN(B)) { diff --git a/views/player/player.pug b/views/player/player.pug index d3df743..7da3b5f 100644 --- a/views/player/player.pug +++ b/views/player/player.pug @@ -136,7 +136,7 @@ block content }); console.log("ready!"); - var controls = + let controls = [ 'progress', // The progress bar and scrubber for playback and buffering 'play-large', // The large play button in the center