diff --git a/config/protonmailTransport.js b/config/protonmailTransport.js index cb4aae5e..c61d386e 100644 --- a/config/protonmailTransport.js +++ b/config/protonmailTransport.js @@ -1,20 +1,20 @@ -const pm = require('protonmail-api'); +// const pm = require('protonmail-api'); -let protonMailTransport; -(async function(){ - protonMailTransport = await pm.connect({ - username: process.env.PROTONMAIL_USERNAME, - password: process.env.PROTONMAIL_PASSWORD - }); +// let protonMailTransport; +// (async function(){ +// protonMailTransport = await pm.connect({ +// username: process.env.PROTONMAIL_USERNAME, +// password: process.env.PROTONMAIL_PASSWORD +// }); - console.log('Protonmail setup'); -})() +// console.log('Protonmail setup'); +// })() -async function sendProtonMail(mailOptions){ - const response = await protonMailTransport.sendEmail(mailOptions); - return response; -} +// async function sendProtonMail(mailOptions){ +// const response = await protonMailTransport.sendEmail(mailOptions); +// return response; +// } -module.exports = { - sendProtonMail -}; +// module.exports = { +// sendProtonMail +// }; diff --git a/controllers/frontend/account.js b/controllers/frontend/account.js index 68bbfc7b..cd37c5b9 100644 --- a/controllers/frontend/account.js +++ b/controllers/frontend/account.js @@ -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'); @@ -53,6 +53,22 @@ const timeAgoEnglish = new javascriptTimeAgo('en-US'); const secondsToFormattedTime = timeHelper.secondsToFormattedTime; +// Searching for last time watched value, for videos longer then 15 minutes +async function addLastTimeWatched(upload, user){ + let lastWatchedTime; + if(upload.durationInSeconds >= 900){ + lastWatchedTime = await LastWatchedTime.findOne({ + user : user._id, + upload: upload._id + }); + } + // Check if user watched the video + if(lastWatchedTime !== undefined && lastWatchedTime !== null){ + return lastWatchedTime.secondsWatched + } + +} + // TODO: pull this function out async function addValuesIfNecessary(upload, channelUrl){ if(upload.fileType == 'video' || upload.fileType == 'audio'){ @@ -63,22 +79,24 @@ async function addValuesIfNecessary(upload, channelUrl){ server = server.substr(1); const uploadLocation = `${server}/${channelUrl}/${upload.uniqueTag + upload.fileExtension}`; - + try { const duration = await getUploadDuration(uploadLocation, upload.fileType); - console.log(duration); + // console.log(duration); let uploadDocument = await Upload.findOne({uniqueTag: upload.uniqueTag}); - uploadDocument.durationInSeconds = duration.seconds; + uploadDocument.durationInSeconds = Math.round(duration.seconds); uploadDocument.formattedDuration = duration.formattedTime; - - await uploadDocument.save(); - + const saveDocument = await uploadDocument.save(); + + const value = Math.round(duration.seconds) + 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'); } } @@ -503,6 +521,18 @@ exports.getChannel = async(req, res) => { user.totalViews = totalViews; + if(uploads && uploads.length){ + for(const upload in uploads){ + if(!uploads[upload].durationInSeconds) + uploads[upload].durationInSeconds = await addValuesIfNecessary(uploads[upload], uploads[upload].uploader && uploads[upload].uploader.channelUrl); + + uploads[upload].lastWatchedTime = await addLastTimeWatched(uploads[upload], req.user) + + if(uploads[upload].lastWatchedTime) + uploads[upload].formattedLastWatchedTime = timeHelper.secondsToFormattedTime(uploads[upload].lastWatchedTime) + } + } + user.uploads = uploads; // for(const upload of uploads){ diff --git a/controllers/frontend/mediaBrowsing.js b/controllers/frontend/mediaBrowsing.js index c86b28f9..3fd11bb6 100644 --- a/controllers/frontend/mediaBrowsing.js +++ b/controllers/frontend/mediaBrowsing.js @@ -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; @@ -40,6 +40,22 @@ if(!process.env.FILE_HOST || process.env.FILE_HOST == 'false'){ const pageLimit = 42; +// Searching for last time watched value, for videos longer then 15 minutes +async function addLastTimeWatched(upload, user){ + let lastWatchedTime; + if(upload.durationInSeconds >= 900){ + lastWatchedTime = await LastWatchedTime.findOne({ + user : user._id, + upload: upload._id + }); + } + // Check if user watched the video + if(lastWatchedTime !== undefined && lastWatchedTime !== null){ + return lastWatchedTime.secondsWatched + } + +} + // TODO: pull this function out async function addValuesIfNecessary(upload, channelUrl){ if(upload.fileType == 'video' || upload.fileType == 'audio'){ @@ -50,7 +66,7 @@ async function addValuesIfNecessary(upload, channelUrl){ server = server.substr(1); const uploadLocation = `${server}/${channelUrl}/${upload.uniqueTag + upload.fileExtension}`; - + try { const duration = await getUploadDuration(uploadLocation, upload.fileType); // console.log(duration); @@ -59,13 +75,13 @@ async function addValuesIfNecessary(upload, channelUrl){ uploadDocument.durationInSeconds = Math.round(duration.seconds); uploadDocument.formattedDuration = duration.formattedTime; - const saveDocument = await uploadDocument.save(); - // console.log(saveDocument); - + + const value = Math.round(duration.seconds) + 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'); @@ -134,6 +150,18 @@ exports.recentUploads = async(req, res) => { // console.log('rendering'); + if(uploads && uploads.length){ + for(const upload in uploads){ + if(!uploads[upload].durationInSeconds) + uploads[upload].durationInSeconds = await addValuesIfNecessary(uploads[upload], uploads[upload].uploader && uploads[upload].uploader.channelUrl); + + uploads[upload].lastWatchedTime = await addLastTimeWatched(uploads[upload], req.user) + + if(uploads[upload].lastWatchedTime) + uploads[upload].formattedLastWatchedTime = timeHelper.secondsToFormattedTime(uploads[upload].lastWatchedTime) + } + } + res.render('mediaBrowsing/recentUploads', { title: 'Recent Uploads', uploads, @@ -311,16 +339,20 @@ exports.popularUploads = async(req, res) => { const popularTimeViews = 'viewsWithin' + within; // console.log(popularTimeViews); - // - // console.log('getting popular uploads'); if(uploads && uploads.length){ for(const upload in uploads){ - // console.log(upload); - addValuesIfNecessary(upload, upload.uploader && upload.uploader.channelUrl); + if(!uploads[upload].durationInSeconds) + uploads[upload].durationInSeconds = await addValuesIfNecessary(uploads[upload], uploads[upload].uploader && uploads[upload].uploader.channelUrl); + + uploads[upload].lastWatchedTime = await addLastTimeWatched(uploads[upload], req.user) + + if(uploads[upload].lastWatchedTime) + uploads[upload].formattedLastWatchedTime = timeHelper.secondsToFormattedTime(uploads[upload].lastWatchedTime) } } + res.render('mediaBrowsing/popularUploads', { title: 'Popular Uploads', uploads, @@ -524,6 +556,18 @@ exports.search = async(req, res) => { // error } + if(uploads && uploads.length){ + for(const upload in uploads){ + if(!uploads[upload].durationInSeconds) + uploads[upload].durationInSeconds = await addValuesIfNecessary(uploads[upload], uploads[upload].uploader && uploads[upload].uploader.channelUrl); + + uploads[upload].lastWatchedTime = await addLastTimeWatched(uploads[upload], req.user) + + if(uploads[upload].lastWatchedTime) + uploads[upload].formattedLastWatchedTime = timeHelper.secondsToFormattedTime(uploads[upload].lastWatchedTime) + } + } + const siteVisitor = req.siteVisitor; const media = mediaType || 'all'; diff --git a/views/admin/adminOverview.pug b/views/admin/adminOverview.pug index 22aafe2c..1ce8f416 100644 --- a/views/admin/adminOverview.pug +++ b/views/admin/adminOverview.pug @@ -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 + diff --git a/views/layout.pug b/views/layout.pug index 29104bd4..e9e4189f 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -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') diff --git a/views/media.pug b/views/media.pug index c84f4739..88c15715 100644 --- a/views/media.pug +++ b/views/media.pug @@ -1,7 +1,7 @@ extends layout -block content +block content if !upload.description style. @media (min-width: 900px) { @@ -399,11 +399,36 @@ block content if upload.fileType === 'video' && upload.status !== 'processing' div.display-div.magnetic(style="min-width:50%;min-height:50%;margin:0 auto;margin-top: -25px;") // margin-top:46px; - - video#media_player.display-element(playsinline poster=`${uploadServer}/${upload.uploader.channelUrl}/${upload.thumbnails.generated || upload.thumbnails.medium}` controls='', style="max-width:100%;background-color:black;") + + //- video#my_video_1.video-js.vjs-default-skin(controls='' data-setup='{}') + //- source(src=`${serverToUse}/${upload.uploader.channelUrl}/${upload.uniqueTag}.mp4`, type='video/mp4') + + //- script. + //- videojs.autoSetup(); + + //- videojs('my_video_1).ready(function(){ + //- console.log(this.options()); + + + //- var myPlayer = this, id = myPlayer.id(); + + //- var aspectRatio = 264/640; + + //- function resizeVideoJS(){ + //- var width = document.getElementById(id).parentElement.offsetWidth; + //- myPlayer.width(width).height( width * aspectRatio ); + + //- } + + + //- resizeVideoJS(); + + //- window.onresize = resizeVideoJS; + //- }); + video#media_player.display-element(playsinline autoplayposter=`${uploadServer}/${upload.uploader.channelUrl}/${upload.thumbnails.generated || upload.thumbnails.medium}` controls='', style="max-width:100%;background-color:black;") // to source.video-source(src=`${serverToUse}/${upload.uploader.channelUrl}/${upload.uniqueTag}.mp4`, type='video/mp4') - + // TODO: load captions programatically if upload.webVTTPath track(kind='captions', label='English captions', src=`${uploadServer}/${upload.uploader.channelUrl}/${upload.webVTTPath}`, srclang='en', default='') @@ -489,11 +514,11 @@ block content // TODO: show this if it's pending or not - if upload.visibility != 'pending' - if alreadySubbed - button.subscribe.btn.fw.btn-danger.op80.unsubscribeButton(style="border-radius:4px;") Unsubscribe (#{subscriberAmount}) - else - button.subscribe.btn.fw.btn-success.op80.subscribeButton(style="border-radius:4px;") Subscribe (#{subscriberAmount}) + + if alreadySubbed + button.subscribe.btn.fw.btn-danger.op80.unsubscribeButton(style="border-radius:4px;") Unsubscribe (#{subscriberAmount}) + else + button.subscribe.btn.fw.btn-success.op80.subscribeButton(style="border-radius:4px;") Subscribe (#{subscriberAmount}) if user div(style="margin-top:12px") @@ -670,7 +695,12 @@ block content if ( upload.durationInSeconds > (15 * 60) ) && user if lastWatchedTime - p.fw.fileSizeText(style="margin-top:15px;color:a5a5a5;") Last Watched Time: #{formattedLastWatchedTime} + p.fw.fileSizeText(style="margin-top:15px;color:a5a5a5;") Las Watched Time: #{formattedLastWatchedTime} + script. + document.getElementById('media_player').addEventListener('loadedmetadata', function() { + this.currentTime = lastWatchedTime; + }, false); + //- document.getElementById('media_player').src = '' + serverToUse + '/' + upload.uploader.channelUrl + '/' upload.uniqueTag + '.mp4#t=00:00:' + lastWatchedTime else p.fw.fileSizeText(style="margin-top:15px;color:a5a5a5;") No Last Watched Time @@ -859,7 +889,7 @@ block extra_js if user script. - + $(document).ready(function(){ var alreadyHaveEmailNotifsOn = '#{alreadySubscribedForEmails}' == 'true' @@ -1015,9 +1045,10 @@ block extra_js // when show less button is clicked showLessButton.click(function () { uploadDescriptionText.height('194'); - + showMoreButton.show() showLessButton.hide() + document.getElementsByTagName('h2')[2].scrollIntoView(); }) diff --git a/views/mediaBrowsing/popularUploads.pug b/views/mediaBrowsing/popularUploads.pug index f1332f46..589ba02c 100644 --- a/views/mediaBrowsing/popularUploads.pug +++ b/views/mediaBrowsing/popularUploads.pug @@ -54,7 +54,7 @@ block content each upload in uploads div.col-xs-12.col-sm-6.col-md-6.col-lg-4(style="text-align:center;height:340px;margin-bottom:34px;") - + include ../viewPartials/uploadThumbnail include ../viewPartials/uploadDetails diff --git a/views/nodeTubeCss.pug b/views/nodeTubeCss.pug index 7a235807..501a7691 100644 --- a/views/nodeTubeCss.pug +++ b/views/nodeTubeCss.pug @@ -162,7 +162,7 @@ style. max-width: 405px; height: 210px; max-height: 210px; - border-radius: 7px; + max-width:100%; /*border:1px solid white;*/ } @@ -291,6 +291,7 @@ style. } .image-container { + height: 220px; display:inline-block; border:1px solid #5b5a5a; margin:0 auto; @@ -304,7 +305,7 @@ style. /*transform: scale(1.05) translate(0px, 30px);*/ - transform: scale(1.12); + transform: scale(1.05); -webkit-filter: brightness(120%); } diff --git a/views/viewPartials/uploadDetails.pug b/views/viewPartials/uploadDetails.pug index 9c152bc4..97978863 100644 --- a/views/viewPartials/uploadDetails.pug +++ b/views/viewPartials/uploadDetails.pug @@ -22,9 +22,10 @@ div.underThing // all the details including title if ( upload.fileType == 'audio' || upload.fileType == 'video') && upload.formattedDuration div.duration(style="display:inline;height:26px;max-width:70px;text-align:center;position:relative;bottom:0;right:0;opacity:1;margin: 0 auto;border-radius: 5px") - span.durationTime(style="margin-right:7px;font-size:15px;") #{upload.formattedDuration} - - + if upload.formattedLastWatchedTime + span.durationTime(style="margin-right:7px;font-size:15px;") #{upload.formattedLastWatchedTime} / #{upload.formattedDuration} + else + span.durationTime(style="margin-right:7px;font-size:15px;") #{upload.formattedDuration} if upload.fileType == 'video' i.fa.fa-video-camera(aria-hidden='true' style="margin:0 auto;text-align:center;display:inline;") else if upload.fileType == 'audio' diff --git a/views/viewPartials/uploadThumbnail.pug b/views/viewPartials/uploadThumbnail.pug index 349c5f2f..96be1ec9 100644 --- a/views/viewPartials/uploadThumbnail.pug +++ b/views/viewPartials/uploadThumbnail.pug @@ -1,12 +1,22 @@ +style. + progress { + width: 100%; + border: 0px solid red; + background: LightGray; + height: 10px; + } + progress::-moz-progress-bar { background: red; } + progress::-webkit-progress-value { background: red; } div.holder(style="border:") a.title-anchor(href=`/user/${upload.uploader.channelUrl || channelUrl}/${upload.uniqueTag}` style="color:#7d7373;" ) div.image-container(style="") - if upload.thumbnails && upload.thumbnails.custom - img.upload-thumbnail.preview-image(src=`${uploadServer}/${channelUrl || upload.uploader.channelUrl}/${upload.thumbnails.custom}` style="") - - else if upload.fileType == 'video' && upload.thumbnails && upload.thumbnails.generated - img.upload-thumbnail.preview-image(src=`${uploadServer}/${channelUrl || upload.uploader.channelUrl}/${upload.thumbnails.generated}` style="") + if upload.fileType == 'video' + if !upload.lastWatchedTime + img.upload-thumbnail.preview-image(src=`${uploadServer}/${channelUrl || upload.uploader.channelUrl}/${upload.thumbnails.generated}` style="margin-bottom: -1.5%; height: 220px; max-height: 220px") + else + img.upload-thumbnail.preview-image(src=`${uploadServer}/${channelUrl || upload.uploader.channelUrl}/${upload.thumbnails.generated}` style="margin-bottom: -1.5%") + progress(value=upload.lastWatchedTime max=upload.durationInSeconds) else if upload.fileType == 'video' && upload.thumbnails && upload.thumbnails.medium img.upload-thumbnail.preview-image(src=`${uploadServer}/${channelUrl || upload.uploader.channelUrl}/${upload.thumbnails.medium}` style="") @@ -23,3 +33,4 @@ div.holder(style="border:") else if upload.fileType == 'unknown' img.upload-thumbnail.preview-image(src='/images/no_img.png') +