Skip to content

Commit

Permalink
fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeaux committed May 22, 2020
1 parent fb4c69d commit 8c766c5
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lib/
loading-bar.js
testing
testing
public/js/three.js
1 change: 0 additions & 1 deletion caching/getFromCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ async function getRecentUploads(limit, offset, mediaType, filter, category, subc

uploads = filterUploadsByCategory(uploads, category);


// IF THERE IS NO CATEGORY
} else {

Expand Down
2 changes: 1 addition & 1 deletion controllers/backend/internalApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ exports.editUpload = async(req, res, next) => {
// load upload changes
upload.title = req.body.title;
upload.description = req.body.description;
if(upload.uploader.plan == "plus")
if(upload.uploader.plan == 'plus')
upload.visibility = req.body.visibility;
upload.rating = req.body.rating;
upload.category = req.body.category;
Expand Down
20 changes: 8 additions & 12 deletions controllers/frontend/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const { userCanUploadContentOfThisRating } = require('../../lib/uploading/helper

const validator = require('email-validator');

const { getUploadDuration } = require('../../lib/mediaBrowsing/helpers')
const { getUploadDuration } = require('../../lib/mediaBrowsing/helpers');

const javascriptTimeAgo = require('javascript-time-ago');
javascriptTimeAgo.locale(require('javascript-time-ago/locales/en'));
Expand All @@ -47,14 +47,13 @@ const timeAgoEnglish = new javascriptTimeAgo('en-US');

const secondsToFormattedTime = timeHelper.secondsToFormattedTime;


// TODO: pull this function out
async function addValuesIfNecessary(upload, channelUrl) {
if (upload.fileType == 'video' || upload.fileType == 'audio') {
if (!upload.durationInSeconds || !upload.formattedDuration) {
async function addValuesIfNecessary(upload, channelUrl){
if(upload.fileType == 'video' || upload.fileType == 'audio'){
if(!upload.durationInSeconds || !upload.formattedDuration){

var server = uploadServer;
if (server.charAt(0) == "/") // the slash confuses the file reading, because host root directory is not the same as machine root directory
if(server.charAt(0) == '/') // the slash confuses the file reading, because host root directory is not the same as machine root directory
server = server.substr(1);

const uploadLocation = `${server}/${channelUrl}/${upload.uniqueTag + upload.fileExtension}`;
Expand All @@ -70,8 +69,7 @@ async function addValuesIfNecessary(upload, channelUrl) {

await uploadDocument.save();


} catch (err) {
} catch(err){
/** if the file has been deleted then it won't blow up **/
// console.log(err);
}
Expand Down Expand Up @@ -234,9 +232,7 @@ exports.getChannelRss = async(req, res) => {
const xml = feed.xml({indent: true});
res.send(xml);

//res.send(uploads);


// res.send(uploads);

} catch(err){
console.log(err);
Expand Down Expand Up @@ -510,7 +506,7 @@ exports.getChannel = async(req, res) => {

user.uploads = uploads;

for(const upload of uploads) {
for(const upload of uploads){
addValuesIfNecessary(upload, user.channelUrl);
}

Expand Down
3 changes: 1 addition & 2 deletions controllers/frontend/livestream.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const domainNameAndTLD = process.env.DOMAIN_NAME_AND_TLD;
const User = require('../../models/index').User;


/**
* GET /live/${channelUrl}
* Get RTMP viewing page (current livestream page)
*/
exports.getLiveRTMP = async (req, res) => {
exports.getLiveRTMP = async(req, res) => {

// TODO: this is backwards
const channelUrl = req.params.user;
Expand Down
17 changes: 8 additions & 9 deletions controllers/frontend/mediaBrowsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const uploadServer = uploadHelpers.uploadServer;
const getFromCache = require('../../caching/getFromCache');
const uploadFilters = require('../../lib/mediaBrowsing/helpers');

const { getUploadDuration } = require('../../lib/mediaBrowsing/helpers')
const { getUploadDuration } = require('../../lib/mediaBrowsing/helpers');

const getSensitivityFilter = uploadFilters.getSensitivityFilter;
const categories = require('../../config/categories');
Expand All @@ -39,12 +39,12 @@ if(!process.env.FILE_HOST || process.env.FILE_HOST == 'false'){
const pageLimit = 42;

// TODO: pull this function out
async function addValuesIfNecessary(upload, channelUrl) {
if (upload.fileType == 'video' || upload.fileType == 'audio') {
if (!upload.durationInSeconds || !upload.formattedDuration) {
async function addValuesIfNecessary(upload, channelUrl){
if(upload.fileType == 'video' || upload.fileType == 'audio'){
if(!upload.durationInSeconds || !upload.formattedDuration){

var server = uploadServer;
if (server.charAt(0) == "/") // the slash confuses the file reading, because host root directory is not the same as machine root directory
if(server.charAt(0) == '/') // the slash confuses the file reading, because host root directory is not the same as machine root directory
server = server.substr(1);

const uploadLocation = `${server}/${channelUrl}/${upload.uniqueTag + upload.fileExtension}`;
Expand All @@ -61,8 +61,7 @@ async function addValuesIfNecessary(upload, channelUrl) {
const saveDocument = await uploadDocument.save();
// console.log(saveDocument);


} catch (err) {
} catch(err){
/** if the file has been deleted then it won't blow up **/
// console.log(err);
}
Expand Down Expand Up @@ -126,7 +125,7 @@ exports.recentUploads = async(req, res) => {
const uploads = await getFromCache.getRecentUploads(limit, skipAmount, mediaType, filter, category, subcategory);

if(category && category !== 'overview'){
for(const upload of uploads) {
for(const upload of uploads){
addValuesIfNecessary(upload, upload.uploader.channelUrl);
}
}
Expand Down Expand Up @@ -314,7 +313,7 @@ exports.popularUploads = async(req, res) => {
// console.log('getting popular uploads');

if(uploads && uploads.length){
for(const upload in uploads) {
for(const upload in uploads){
// console.log(upload);
addValuesIfNecessary(upload, upload.uploader && upload.uploader.channelUrl);
}
Expand Down
2 changes: 0 additions & 2 deletions controllers/frontend/mediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ function getFormattedFileSize(upload){
return formattedFileSizeString;
}



/**
* GET /$user/$uploadUniqueTag
* Media player page
Expand Down
8 changes: 4 additions & 4 deletions controllers/frontend/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ if(!process.env.FILE_HOST || process.env.FILE_HOST == 'false'){
*/
exports.index = async(req, res) => {

const title = "Home";
const title = 'Home';

if(defaultLandingPage == "globe") {
if(defaultLandingPage == 'globe'){

// get 150 most popular uploads in last 24h that are sfw and from any category
let uploads = await getFromCache.getPopularUploads("24hour", 150, 0, "all", "SFW", "all", "");
let uploads = await getFromCache.getPopularUploads('24hour', 150, 0, 'all', 'SFW', 'all', '');

res.render('public/globe', {
title,
Expand Down Expand Up @@ -77,7 +77,7 @@ exports.index = async(req, res) => {
*/
exports.globe = async(req, res) => {

let uploads = await getFromCache.getPopularUploads("24hour", 150, 0, "all", "SFW", "all", "");
let uploads = await getFromCache.getPopularUploads('24hour', 150, 0, 'all', 'SFW', 'all', '');

res.render('public/globe', {
title: 'Globe',
Expand Down
1 change: 0 additions & 1 deletion middlewares/shared/socialRedirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ async function middleware(req, res, next){
res.redirect('https://www.facebook.com/NewTube-114869126871911');
}


next();
}

Expand Down
15 changes: 6 additions & 9 deletions middlewares/shared/viewCounting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ const View = require('../../models').View;

async function checkWhetherToCountView(siteVisitorId, uploadID){


const existingViewsForThisUpload = await View.find({
siteVisitor : siteVisitorId, // req.siteVisitor._id,
upload : uploadID //upload._id
upload : uploadID // upload._id
});

// console.log(existingViewsForThisUpload.length)


// calculate if doing fraud helper
// calculate if doing fraud helper

let countViewCount = false;

let last1hViews = 0;
let last24hViews = 0;

// console.log(existingViewsForThisUpload);
// console.log(existingViewsForThisUpload);

// loop through all views for the upload per that user
for(const view of existingViewsForThisUpload){
Expand Down Expand Up @@ -47,11 +45,11 @@ async function checkWhetherToCountView(siteVisitorId, uploadID){
// if it has happened within the last 24h
}

if (timeDiffInH < 24 ) {
if(timeDiffInH < 24 ){

// console.log('less than 24h')

last24hViews++
last24hViews++;
}
}

Expand All @@ -68,8 +66,7 @@ async function checkWhetherToCountView(siteVisitorId, uploadID){

// console.log(countViewCount);

return countViewCount

return countViewCount;

}

Expand Down
1 change: 0 additions & 1 deletion models/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const uploadSchema = new mongoose.Schema({
// such as https://domain.com/path/$channelUrl/$uniqueTag.$fileExtension
uploadServer: { type: String },


// viralServer follows the same pattern as uploadServer (https://domain.com/path/) and supercedes uploadServer
// meant to be used to send the most popular uploads to another server for bandwidth
viralServerOn: Boolean,
Expand Down
1 change: 0 additions & 1 deletion models/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ viewSchema.index({upload: 1, siteVisitor: 1}, {name: 'Views Per Upload And Site

viewSchema.index({upload: 1 }, {name: 'View Count'});


const View = mongoose.model('View', viewSchema);

module.exports = View;
Expand Down

0 comments on commit 8c766c5

Please sign in to comment.