From c63a64ebefacdf6f0514ae0d4756964cf896fdc7 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Wed, 23 Dec 2020 01:29:22 -0500 Subject: [PATCH] Categories will now auto-generate playlists --- backend/app.js | 35 +++++++++++++-- backend/authentication/auth.js | 44 ++++++++++++++++--- .../custom-playlists.component.ts | 2 +- .../recent-videos/recent-videos.component.ts | 2 +- .../unified-file-card.component.html | 9 +++- .../unified-file-card.component.scss | 5 +++ .../video-info-dialog.component.html | 2 +- src/app/player/player.component.ts | 4 ++ 8 files changed, 88 insertions(+), 15 deletions(-) diff --git a/backend/app.js b/backend/app.js index 98a054e..d284b3b 100644 --- a/backend/app.js +++ b/backend/app.js @@ -79,7 +79,7 @@ const logger = winston.createLogger({ }); config_api.initialize(logger); -auth_api.initialize(users_db, logger); +auth_api.initialize(db, users_db, logger); db_api.initialize(db, users_db, logger); subscriptions_api.initialize(db, users_db, logger, db_api); categories_api.initialize(db, users_db, logger, db_api); @@ -1215,7 +1215,7 @@ async function downloadFileByURL_exec(url, type, options, sessionID = null) { const customPath = options.noRelativePath ? path.dirname(full_file_path).split(path.sep).pop() : null; // registers file in DB - file_uid = db_api.registerFileDB(file_path, type, multiUserMode, null, customPath); + file_uid = db_api.registerFileDB(file_path, type, multiUserMode, null, customPath, category); if (file_name) file_names.push(file_name); } @@ -2014,10 +2014,37 @@ app.post('/api/getAllFiles', optionalJwt, async function (req, res) { // get basic info depending on multi-user mode being enabled if (req.isAuthenticated()) { files = auth_api.getUserVideos(req.user.uid); - playlists = auth_api.getUserPlaylists(req.user.uid); + playlists = auth_api.getUserPlaylists(req.user.uid, files); } else { files = db.get('files').value(); - playlists = db.get('playlists').value(); + playlists = JSON.parse(JSON.stringify(db.get('playlists').value())); + const categories = db.get('categories').value(); + if (categories) { + categories.forEach(category => { + const audio_files = files && files.filter(file => file.category && file.category.uid === category.uid && file.isAudio); + const video_files = files && files.filter(file => file.category && file.category.uid === category.uid && !file.isAudio); + if (audio_files && audio_files.length > 0) { + playlists.push({ + name: category['name'], + thumbnailURL: audio_files[0].thumbnailURL, + thumbnailPath: audio_files[0].thumbnailPath, + fileNames: audio_files.map(file => file.id), + type: 'audio', + auto: true + }); + } + if (video_files && video_files.length > 0) { + playlists.push({ + name: category['name'], + thumbnailURL: video_files[0].thumbnailURL, + thumbnailPath: video_files[0].thumbnailPath, + fileNames: video_files.map(file => file.id), + type: 'video', + auto: true + }); + } + }); + } } // loop through subscriptions and add videos diff --git a/backend/authentication/auth.js b/backend/authentication/auth.js index ce8f100..e5f04ec 100644 --- a/backend/authentication/auth.js +++ b/backend/authentication/auth.js @@ -15,15 +15,16 @@ var JwtStrategy = require('passport-jwt').Strategy, // other required vars let logger = null; -var users_db = null; +let db = null; +let users_db = null; let SERVER_SECRET = null; let JWT_EXPIRATION = null; let opts = null; let saltRounds = null; -exports.initialize = function(input_users_db, input_logger) { +exports.initialize = function(input_db, input_users_db, input_logger) { setLogger(input_logger) - setDB(input_users_db); + setDB(input_db, input_users_db); /************************* * Authentication module @@ -61,7 +62,8 @@ function setLogger(input_logger) { logger = input_logger; } -function setDB(input_users_db) { +function setDB(input_db, input_users_db) { + db = input_db; users_db = input_users_db; } @@ -310,9 +312,39 @@ exports.removePlaylist = function(user_uid, playlistID) { return true; } -exports.getUserPlaylists = function(user_uid) { +exports.getUserPlaylists = function(user_uid, user_files = null) { const user = users_db.get('users').find({uid: user_uid}).value(); - return user['playlists']; + const playlists = JSON.parse(JSON.stringify(user['playlists'])); + const categories = db.get('categories').value(); + if (categories && user_files) { + categories.forEach(category => { + const audio_files = user_files && user_files.filter(file => file.category && file.category.uid === category.uid && file.isAudio); + const video_files = user_files && user_files.filter(file => file.category && file.category.uid === category.uid && !file.isAudio); + if (audio_files && audio_files.length > 0) { + playlists.push({ + name: category['name'], + thumbnailURL: audio_files[0].thumbnailURL, + thumbnailPath: audio_files[0].thumbnailPath, + fileNames: audio_files.map(file => file.id), + type: 'audio', + uid: user_uid, + auto: true + }); + } + if (video_files && video_files.length > 0) { + playlists.push({ + name: category['name'], + thumbnailURL: video_files[0].thumbnailURL, + thumbnailPath: video_files[0].thumbnailPath, + fileNames: video_files.map(file => file.id), + type: 'video', + uid: user_uid, + auto: true + }); + } + }); + } + return playlists; } exports.getUserPlaylist = function(user_uid, playlistID, requireSharing = false) { diff --git a/src/app/components/custom-playlists/custom-playlists.component.ts b/src/app/components/custom-playlists/custom-playlists.component.ts index d2d65d6..73e3036 100644 --- a/src/app/components/custom-playlists/custom-playlists.component.ts +++ b/src/app/components/custom-playlists/custom-playlists.component.ts @@ -62,7 +62,7 @@ export class CustomPlaylistsComponent implements OnInit { } else { localStorage.setItem('player_navigator', this.router.url); const fileNames = playlist.fileNames; - this.router.navigate(['/player', {fileNames: fileNames.join('|nvr|'), type: type, id: playlistID, uid: playlistID}]); + this.router.navigate(['/player', {fileNames: fileNames.join('|nvr|'), type: type, id: playlistID, uid: playlistID, auto: playlist.auto}]); } } else { // playlist not found diff --git a/src/app/components/recent-videos/recent-videos.component.ts b/src/app/components/recent-videos/recent-videos.component.ts index 7ca6c9b..83bd72f 100644 --- a/src/app/components/recent-videos/recent-videos.component.ts +++ b/src/app/components/recent-videos/recent-videos.component.ts @@ -98,7 +98,7 @@ export class RecentVideosComponent implements OnInit { private filterFiles(value: string) { const filterValue = value.toLowerCase(); - this.filtered_files = this.files.filter(option => option.id.toLowerCase().includes(filterValue) || option.category?.toLowerCase().includes(filterValue)); + this.filtered_files = this.files.filter(option => option.id.toLowerCase().includes(filterValue) || option.category?.name?.toLowerCase().includes(filterValue)); this.pageChangeEvent({pageSize: this.pageSize, pageIndex: this.paginator.pageIndex}); } diff --git a/src/app/components/unified-file-card/unified-file-card.component.html b/src/app/components/unified-file-card/unified-file-card.component.html index a080324..066d78e 100644 --- a/src/app/components/unified-file-card/unified-file-card.component.html +++ b/src/app/components/unified-file-card/unified-file-card.component.html @@ -1,5 +1,10 @@
-
{{(file_obj.type === 'audio' || file_obj.isAudio) ? 'audiotrack' : 'movie'}}  {{file_obj.registered | date:'shortDate' : undefined : locale.ngID}}
+
+ {{(file_obj.type === 'audio' || file_obj.isAudio) ? 'audiotrack' : 'movie'}} +    + Auto-generated + {{file_obj.registered | date:'shortDate' : undefined : locale.ngID}} +
- + diff --git a/src/app/components/unified-file-card/unified-file-card.component.scss b/src/app/components/unified-file-card/unified-file-card.component.scss index 067ef4a..8d8ea1a 100644 --- a/src/app/components/unified-file-card/unified-file-card.component.scss +++ b/src/app/components/unified-file-card/unified-file-card.component.scss @@ -111,6 +111,11 @@ top: 1px; left: 5px; z-index: 99999; + width: calc(100% - 8px); + white-space: nowrap; + overflow: hidden; + display: block; + text-overflow: ellipsis; } .audio-video-icon { diff --git a/src/app/dialogs/video-info-dialog/video-info-dialog.component.html b/src/app/dialogs/video-info-dialog/video-info-dialog.component.html index 203cfd5..e62d1c9 100644 --- a/src/app/dialogs/video-info-dialog/video-info-dialog.component.html +++ b/src/app/dialogs/video-info-dialog/video-info-dialog.component.html @@ -27,7 +27,7 @@
Category: 
-
{{file.category}}N/A
+
{{file.category.name}}N/A
diff --git a/src/app/player/player.component.ts b/src/app/player/player.component.ts index c2aa1c2..123e2b4 100644 --- a/src/app/player/player.component.ts +++ b/src/app/player/player.component.ts @@ -207,6 +207,10 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy { } getPlaylistFiles() { + if (this.route.snapshot.paramMap.get('auto') === 'true') { + this.show_player = true; + return; + } this.postsService.getPlaylist(this.id, null, this.uuid).subscribe(res => { if (res['playlist']) { this.db_playlist = res['playlist'];