Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

var variables modified to let variables #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 91 additions & 88 deletions app.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);

Expand Down
16 changes: 8 additions & 8 deletions views/files.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion views/player/player.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down