Skip to content

Commit 7b669f2

Browse files
committed
Merge branch 'master' of github.com:mayeaux/nodetube
* 'master' of github.com:mayeaux/nodetube: bugfix eslint fix and remove logs channel page working seems to be working fixing channel page update upload functionality
2 parents 363d955 + c441d20 commit 7b669f2

File tree

3 files changed

+67
-18
lines changed

3 files changed

+67
-18
lines changed

controllers/backend/uploading.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,16 @@ exports.getUploadProgress = async(req, res) => {
108108
};
109109

110110
function areUploadsOff(uploadsOn, isNotTrustedUser, res){
111+
112+
// allows users to
111113
if(uploadsOn == 'false' && isNotTrustedUser){
112114
console.log('HERE');
113115
res.status(500);
114-
return res.send({ message: 'UPLOADS_OFF'});
116+
res.send({ message: 'UPLOADS_OFF'});
117+
return false;
115118
}
119+
120+
return true;
116121
}
117122

118123
function testIfUserRestricted(user, logObject, res){
@@ -122,8 +127,11 @@ function testIfUserRestricted(user, logObject, res){
122127
uploadLogger.info('User upload status restricted', logObject);
123128

124129
res.status(403);
125-
return res.send('Sorry your account is restricted');
130+
res.send('Sorry your account is restricted');
131+
return true;
126132
}
133+
134+
return false;
127135
}
128136

129137
function aboutToProcess(res, channelUrl, uniqueTag){
@@ -164,8 +172,11 @@ async function checkIfAlreadyUploaded(user, title, logObject, res){
164172
if(alreadyUploaded){
165173
uploadLogger.info('Upload title already uploaded', logObject);
166174
res.status(500);
167-
return res.send({message: 'ALREADY-UPLOADED'});
175+
res.send({message: 'ALREADY-UPLOADED'});
176+
return true;
168177
}
178+
179+
return false;
169180
}
170181

171182
/** RESPOND EARLY IF ITS AN UNKNOWN FILE TYPE **/
@@ -217,13 +228,15 @@ exports.postFileUpload = async(req, res) => {
217228

218229
const isNotTrustedUser = !req.user.privs.autoVisibleUpload;
219230

220-
// TODO: have to fix these, should end function execution early (see unknown file type below)
221-
areUploadsOff(uploadsOn, isNotTrustedUser, logObject, res);
231+
const uploadsAreOff = areUploadsOff(uploadsOn, isNotTrustedUser, logObject, res);
232+
if(uploadsAreOff){ return; }
222233

223234
// ends the response early if user is restricted
224-
testIfUserRestricted(user, logObject, res);
235+
const userIsRestricted = testIfUserRestricted(user, logObject, res);
236+
if(userIsRestricted){ return; }
225237

226-
checkIfAlreadyUploaded(user, title, logObject, res);
238+
const uploadAlreadyUploaded = checkIfAlreadyUploaded(user, title, logObject, res);
239+
if(uploadAlreadyUploaded){ return; }
227240

228241
// let upload = setUpload()
229242

@@ -274,7 +287,7 @@ exports.postFileUpload = async(req, res) => {
274287
// TODO: not a great design but I don't know a better approach
275288
// user this after upload object is made because it saves it to db
276289
const isUnknown = await testIsFileTypeUnknown(upload, fileType, fileExtension, logObject, res);
277-
if(isUnknown)return;
290+
if(isUnknown){ return; }
278291

279292
// where is this used?
280293
let uploadPath = `./upload/${identifier}`;

controllers/frontend/account.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const Subscription = require('../../models/index').Subscription;
1515

1616
const { uploadServer, uploadUrl } = require('../../lib/helpers/settings');
1717

18+
const { filterUploadsByMediaType } = require('../../lib/mediaBrowsing/helpers');
19+
20+
const { URLSearchParams } = require('url');
21+
1822
const brandName = process.env.INSTANCE_BRAND_NAME;
1923

2024
const thumbnailServer = process.env.THUMBNAIL_SERVER || '';
@@ -123,7 +127,7 @@ exports.subscriptions = async(req, res) => {
123127
}
124128
};
125129

126-
// TODO: find a new home, wrong controller
130+
// TODO: desperately needs a cleanup
127131
/**
128132
* GET /channel
129133
* Profile page.
@@ -136,6 +140,12 @@ exports.getChannel = async(req, res) => {
136140

137141
const channelUrl = req.params.channel;
138142

143+
let media = req.query.mediaType;
144+
if(!media){
145+
media = 'all';
146+
}
147+
const mediaType = media;
148+
139149
const limit = 51;
140150
const skipAmount = (page * limit) - limit;
141151

@@ -208,6 +218,8 @@ exports.getChannel = async(req, res) => {
208218
/** DB CALL TO GET UPLOADS **/
209219
let uploads = await Upload.find(searchQuery).populate('').sort({ createdAt : -1 });
210220

221+
uploads = filterUploadsByMediaType(uploads, mediaType);
222+
211223
// console.log(`IS ADMIN OR MOD: ${viewerIsAdminOrMod}`);
212224
// console.log(`IS OWNER: ${viewerIsOwner}`);
213225

@@ -253,6 +265,8 @@ exports.getChannel = async(req, res) => {
253265
orderBy = req.query.orderBy;
254266
}
255267

268+
// console.log(`orderBy : ${orderBy}`)
269+
256270
if(orderBy !== 'popular' && orderBy !== 'newToOld' && orderBy !== 'oldToNew' && orderBy !== 'alphabetical'){
257271
console.log('doesnt connect');
258272
orderBy = 'newToOld';
@@ -316,23 +330,23 @@ exports.getChannel = async(req, res) => {
316330

317331
if(orderBy == 'newToOld'){
318332

319-
console.log('new to old');
333+
// console.log('new to old');
320334
uploads = uploads.sort(function(a, b){
321335
return b.createdAt - a.createdAt;
322336
});
323337
}
324338

325339
if(orderBy == 'oldToNew'){
326340

327-
console.log('old to new');
341+
// console.log('old to new');
328342
uploads = uploads.sort(function(a, b){
329343
return a.createdAt - b.createdAt;
330344
});
331345
}
332346

333347
if(orderBy == 'alphabetical'){
334348

335-
console.log('alphabetical');
349+
// console.log('alphabetical');
336350

337351
uploads = uploads.sort(function(a, b){
338352
return a.title.localeCompare(b.title);
@@ -396,7 +410,10 @@ exports.getChannel = async(req, res) => {
396410
userUploadAmount,
397411
channelUrl: user.channelUrl,
398412
categories,
399-
joinedTimeAgo
413+
joinedTimeAgo,
414+
media,
415+
page,
416+
orderBy
400417
});
401418

402419
} catch(err){

views/account/channel.pug

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,42 @@ block content
124124
hr
125125

126126
div.center-block.text-center
127+
127128
div.dropdown(style="display:inline;margin-right:15px;")
128-
button.btn.btn-primary.dropdown-toggle(type='button', data-toggle='dropdown' style="border-radius:5px")
129+
button.fw.btn.btn-primary.dropdown-toggle(type='button', data-toggle='dropdown' style="border-radius:5px")
129130
| Order By: #{orderByEnglishString} &nbsp
130131
span.caret
131132

132133
ul.dropdown-menu.dropdown
133134
li
134-
a(href=`/user/${channel.channelUrl}?orderBy=popular`) Popular
135+
a(href=`/user/${channel.channelUrl}?orderBy=popular&mediaType=${media}&page=${page}`) Popular
135136
li
136-
a(href=`/user/${channel.channelUrl}?orderBy=newToOld`) New To Old
137+
a(href=`/user/${channel.channelUrl}?orderBy=newToOld&mediaType=${media}&page=${page}`) New To Old
137138
li
138-
a(href=`/user/${channel.channelUrl}?orderBy=oldToNew`) Old To New
139+
a(href=`/user/${channel.channelUrl}?orderBy=oldToNew&mediaType=${media}&page=${page}`) Old To New
139140
li
140-
a(href=`/user/${channel.channelUrl}?orderBy=alphabetical`) Alphabetical
141+
a(href=`/user/${channel.channelUrl}?orderBy=alphabetical&mediaType=${media}&page=${page}`) Alphabetical
142+
143+
div.search-upload-buttons-container.dropdown(style="display:inline;padding-right:15px;")
144+
button#dropdownMenu1.fw.btn.btn-primary.dropdown-toggle(type='button', data-toggle='dropdown' style="border-radius:5px;")
145+
| File Type: #{media.charAt(0).toUpperCase() + media.slice(1)} &nbsp
146+
span.caret
147+
148+
ul.dropdown-menu(role='menu', aria-labelledby='dropdownMenu1')
149+
li(role='presentation')
150+
a(href=`/user/${channelUrl}/?mediaType=all&orderBy=${orderBy}&page=${page}`) All
151+
li(role='presentation')
152+
a(href=`/user/${channelUrl}/?mediaType=video&orderBy=${orderBy}&page=${page}`) Videos
153+
li(role='presentation')
154+
a(href=`/user/${channelUrl}/?mediaType=audio&orderBy=${orderBy}&page=${page}`) Audio
155+
li(role='presentation')
156+
a(href=`/user/${channelUrl}/?mediaType=image&orderBy=${orderBy}&page=${page}`) Images
141157

142158
include ../viewPartials/sensitivityFilterDropdown
143159

160+
161+
162+
144163
include ../viewPartials/channelOverviewPagination
145164

146165
br

0 commit comments

Comments
 (0)