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

Igor polish #380

Open
wants to merge 5 commits 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
32 changes: 16 additions & 16 deletions config/protonmailTransport.js
Original file line number Diff line number Diff line change
@@ -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
// };
46 changes: 38 additions & 8 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 @@ -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'){
Expand All @@ -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');
}
}
Expand Down Expand Up @@ -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){
Expand Down
66 changes: 55 additions & 11 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,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'){
Expand All @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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';
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
55 changes: 43 additions & 12 deletions views/media.pug
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends layout

block content

block content
if !upload.description
style.
@media (min-width: 900px) {
Expand Down Expand Up @@ -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='')
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -859,7 +889,7 @@ block extra_js

if user
script.

$(document).ready(function(){

var alreadyHaveEmailNotifsOn = '#{alreadySubscribedForEmails}' == 'true'
Expand Down Expand Up @@ -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();
})


Expand Down
Loading