Skip to content
2 changes: 1 addition & 1 deletion controllers/backend/uploading.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ exports.postFileUpload = async(req, res) => {

uploadLogger.info('Update users push notifications', logObject);

// user
// do email notifications for the user
updateUsersEmailNotifications(user, upload, req.host);

uploadLogger.info('Update users email notifications', logObject);
Expand Down
36 changes: 29 additions & 7 deletions controllers/frontend/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SocialPost = require('../../models/index').SocialPost;
const Subscription = require('../../models/index').Subscription;
const PushSubscription = require('../../models/index').PushSubscription;
const EmailSubscription = require('../../models/index').EmailSubscription;

const LastWatchedTime = require('../../models/index').LastWatchedTime;
const PushEndpoint = require('../../models/index').PushEndpoint;

const RSS = require('rss');
Expand Down Expand Up @@ -503,6 +503,24 @@ exports.getChannel = async(req, res) => {

user.totalViews = totalViews;

for(const upload in uploads){
console.log(uploads[upload].durationInSeconds);
let lastWatchedTime;
if(uploads[upload].durationInSeconds >= 900){
console.log('This watch');
console.log(uploads[upload]._id);
console.log(user._id);
lastWatchedTime = await LastWatchedTime.findOne({
user : req.user._id,
upload: uploads[upload]._id
});
}
if(lastWatchedTime !== undefined && lastWatchedTime !== null){
uploads[upload].lastWatchedTime = lastWatchedTime.secondsWatched;
console.log(lastWatchedTime.secondsWatched);
}
}

user.uploads = uploads;

// for(const upload of uploads){
Expand All @@ -513,19 +531,23 @@ exports.getChannel = async(req, res) => {

const joinedTimeAgo = timeAgoEnglish.format(user.createdAt);

const pushSubscriptionSearchQuery = {
subscribedToUser : user._id,
subscribingUser: req.user._id,
active: true
}

let existingPushSub;
if(req.user){
const pushSubscriptionSearchQuery = {
subscribedToUser : user._id,
subscribingUser: req.user._id,
active: true
};
existingPushSub = await PushSubscription.findOne(pushSubscriptionSearchQuery);
}

let existingEmailSub;
if(req.user){
const pushSubscriptionSearchQuery = {
subscribedToUser : user._id,
subscribingUser: req.user._id,
active: true
};
existingEmailSub = await EmailSubscription.findOne(pushSubscriptionSearchQuery);
}

Expand Down
75 changes: 65 additions & 10 deletions controllers/frontend/mediaBrowsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const User = require('../../models/index').User;
const Upload = require('../../models/index').Upload;
const SearchQuery = require('../../models/index').SearchQuery;
const View = require('../../models/index').View;

const LastWatchedTime = require('../../models/index').LastWatchedTime;
const uploadHelpers = require('../../lib/helpers/settings');
const uploadServer = uploadHelpers.uploadServer;
const getFromCache = require('../../caching/getFromCache');
const uploadFilters = require('../../lib/mediaBrowsing/helpers');

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

const getSensitivityFilter = uploadFilters.getSensitivityFilter;
Expand Down Expand Up @@ -40,17 +40,38 @@ if(!process.env.FILE_HOST || process.env.FILE_HOST == 'false'){

const pageLimit = 42;

async function addLastTimeWatched(upload, user){
console.log("AddLastWatchedTime")
console.log(upload.durationInSeconds)
let lastWatchedTime;
if(upload.durationInSeconds >= 900){
console.log("This watch")
console.log(upload._id)
console.log(user._id)
lastWatchedTime = await LastWatchedTime.findOne({
user : user._id,
upload: upload._id
});
}
if(lastWatchedTime !== undefined && lastWatchedTime !== null){
// uploads[upload].lastWatchedTime = lastWatchedTime.secondsWatched
console.log(lastWatchedTime.secondsWatched)
return lastWatchedTime.secondsWatched
}

}

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

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
server = server.substr(1);

const uploadLocation = `${server}/${channelUrl}/${upload.uniqueTag + upload.fileExtension}`;

try {
const duration = await getUploadDuration(uploadLocation, upload.fileType);
// console.log(duration);
Expand All @@ -59,13 +80,13 @@ async function addValuesIfNecessary(upload, channelUrl){

uploadDocument.durationInSeconds = Math.round(duration.seconds);
uploadDocument.formattedDuration = duration.formattedTime;

const value = Math.round(duration.seconds);
const saveDocument = await uploadDocument.save();
// console.log(saveDocument);

// console.log("saveDocument")
return value;
} catch(err){
/** if the file has been deleted then it won't blow up **/
// console.log(err);
console.log(err);
}

// console.log('have to add');
Expand Down Expand Up @@ -134,6 +155,14 @@ exports.recentUploads = async(req, res) => {

// console.log('rendering');

if(uploads && uploads.length){
for(const upload in uploads){
// console.log(uploads[upload]);
uploads[upload].durationInSeconds = await addValuesIfNecessary(uploads[upload], uploads[upload].uploader && uploads[upload].uploader.channelUrl);
uploads[upload].lastWatchedTime = await addLastTimeWatched(uploads[upload], req.user)
}
}

res.render('mediaBrowsing/recentUploads', {
title: 'Recent Uploads',
uploads,
Expand Down Expand Up @@ -316,10 +345,28 @@ exports.popularUploads = async(req, res) => {

if(uploads && uploads.length){
for(const upload in uploads){
// console.log(upload);
addValuesIfNecessary(upload, upload.uploader && upload.uploader.channelUrl);
// console.log(uploads[upload]);
uploads[upload].durationInSeconds = await addValuesIfNecessary(uploads[upload], uploads[upload].uploader && uploads[upload].uploader.channelUrl);
uploads[upload].lastWatchedTime = await addLastTimeWatched(uploads[upload], req.user)
}
}
// console.log(uploads)
// for(const upload in uploads){
// // console.log(uploads[upload]._id)
// let lastWatchedTime;
// if(uploads[upload].lastWatchedTime === undefined){
// lastWatchedTime = await LastWatchedTime.findOne({
// user : req.user._id,
// upload: uploads[upload]._id
// });
// }
// if(lastWatchedTime !== null){
// uploads[upload].lastWatchedTime = lastWatchedTime.secondsWatched
// // console.log(lastWatchedTime.secondsWatched)
// }
// // console.log(uploads[upload].durationInSeconds);
// }


res.render('mediaBrowsing/popularUploads', {
title: 'Popular Uploads',
Expand Down Expand Up @@ -524,6 +571,14 @@ exports.search = async(req, res) => {
// error
}

if(uploads && uploads.length){
for(const upload in uploads){
// console.log(uploads[upload]);
uploads[upload].durationInSeconds = await addValuesIfNecessary(uploads[upload], uploads[upload].uploader && uploads[upload].uploader.channelUrl);
uploads[upload].lastWatchedTime = await addLastTimeWatched(uploads[upload], req.user)
}
}

const siteVisitor = req.siteVisitor;

const media = mediaType || 'all';
Expand Down
42 changes: 38 additions & 4 deletions views/account/channel.pug
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ block content
if user
div(style="margin-top:12px")
// TODO: this should create a push subsciption, and it will also send a query to see if it should create a new service worker
h2.share-button.pushNotificationIcon(style="display:inline")
h2.fw.share-button.pushNotificationIcon(style="display:inline")
i.share-icon.fas.fa-bell(aria-hidden="true" style="cursor:pointer;font-size:25px;margin-left:0px;color:white;")
h2.share-button.emailNotificationIcon(style="display:inline")
h2.fw.share-button.emailNotificationIcon(style="display:inline")
i.share-icon.fas.fa-envelope(aria-hidden="true" style="cursor:pointer;font-size:25px;margin-left:10px;color:white;")
else
div(style="margin-top:12px")
// TODO: this should create a push subsciption, and it will also send a query to see if it should create a new service worker
h2.fw.share-button.pushNotificationIcon(style="display:inline")
i.share-icon.fas.fa-bell(aria-hidden="true" style="cursor:pointer;font-size:25px;margin-left:0px;color:white;")
h2.fw.share-button.emailNotificationIcon(style="display:inline")
i.share-icon.fas.fa-envelope(aria-hidden="true" style="cursor:pointer;font-size:25px;margin-left:10px;color:white;")

// todo: else
Expand Down Expand Up @@ -149,7 +156,7 @@ block content
//button.undelete-account.btn.btn-warning Undelete Account And Unban Ip
if user.role == 'admin'
button.delete-ips.btn.btn-warning Undelete All Accounts / Unban All Ips


div

Expand Down Expand Up @@ -259,7 +266,7 @@ block content
$(document).ready(function(){

var alreadyHaveEmailNotifsOn = '#{alreadySubscribedForEmails}' == 'true'

console.log('already have email notis on')

if (alreadyHaveEmailNotifsOn) {
Expand Down Expand Up @@ -434,6 +441,33 @@ block content
main();
})

$('.emailNotificationIcon').click(function () {
// TODO: How to make it so that the user immediately gets email subs after
// signing in.
Swal.mixin({
title: 'Choose method of email subscription',
showCancelButton: true,
}).queue([
{
html: '<hr>' +
'<p>Please <a href="/login">sign in</a> to continue.</p>',
confirmButtonText: 'Subscribe without sign in',
},
{
title: 'Choose method of email subscription',
confirmButtonText: 'Subscribe',
input: 'email',
inputLabel: 'Get updates without sign in',
inputPlaceholder: 'Enter your email address'
}
]).then((result) => {
console.log('result', result.value)
if (result.value) {
const email = result.value[1]
}
})
})




Expand Down
27 changes: 26 additions & 1 deletion views/admin/adminOverview.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,33 @@ extends ../layout

block content
div
div
div.col-sm-3
h2
a(href="/admin/users") Users
h2
a(href="/admin/subscriptions") Subscriptions
h2
a(href="/admin/comments") Comments
h2
a(href="/admin/uploads") Uploads
h2
a(href="/admin/dailyStats") Daily stats
h2
a(href="/admin/reacts") Reacts
h2
a(href="/admin/siteVisitors") Site Visitors
h2
a(href="/admin/notifications") Notifications
h2
a(href="/admin/adminAudit") Admin audit
h2
a(href="/admin/createSocialPost") Create Social Post
h2
a(href="/admin/oneOffSocialPost") One off social post
h2
a(href="/pending") Pending requests
h2
a(href="/support/emails") Support emails
h2
a(href="/support/reports") Support reports

1 change: 1 addition & 0 deletions views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ html
link(rel='manifest', href='/manifest.json')
link(rel='alternate', type='application/rss+xml', href='/media/recent/rss')
link(href='https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css', rel='stylesheet')
link(href='https://cdn.plyr.io/3.6.2/plyr.css', rel='stylesheet')
block extra_css

script(src='/js/lib/jquery-3.1.1.min.js')
Expand Down
Loading