From cc189a3abdeb6a0edb6ee7f8c26c11879fa1c67b Mon Sep 17 00:00:00 2001 From: Isaac Grynsztein Date: Wed, 15 Jul 2020 23:37:00 -0400 Subject: [PATCH] Unified videos videos are now properly retrieved from the server --- backend/app.js | 43 ++++++++++++++++--- .../recent-videos/recent-videos.component.ts | 11 ++++- .../unified-file-card.component.html | 4 +- src/app/posts.services.ts | 4 ++ 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/backend/app.js b/backend/app.js index eb33fd9..9ddf85f 100644 --- a/backend/app.js +++ b/backend/app.js @@ -2047,21 +2047,50 @@ app.post('/api/getFile', optionalJwt, function (req, res) { }); app.post('/api/getAllFiles', optionalJwt, function (req, res) { - files = null; - playlists = null; + // these are returned + let files = []; + let playlists = []; + let subscription_files = []; + + let videos = null; + let audios = null; + let audio_playlists = null; + let video_playlists = null; + let subscriptions = subscriptions_api.getAllSubscriptions(req.isAuthenticated() ? req.user.uid : null); + + // get basic info depending on multi-user mode being enabled if (req.isAuthenticated()) { - const videos = auth_api.getUserVideos(req.user.uid, 'video'); - const audios = auth_api.getUserVideos(req.user.uid, 'audio'); - const audio_playlists = null; - const video_playlists = null; + videos = auth_api.getUserVideos(req.user.uid, 'video'); + audios = auth_api.getUserVideos(req.user.uid, 'audio'); + audio_playlists = auth_api.getUserPlaylists(req.user.uid, 'audio'); + video_playlists = auth_api.getUserPlaylists(req.user.uid, 'video'); } else { + videos = db.get('files.audio').value(); + audios = db.get('files.video').value(); + audio_playlists = db.get('playlists.audio').value(); + video_playlists = db.get('playlists.video').value(); + } + files = videos.concat(audios); + playlists = video_playlists.concat(audio_playlists); + + // loop through subscriptions and add videos + for (let i = 0; i < subscriptions.length; i++) { + sub = subscriptions[i]; + console.log(sub); + if (!sub.videos) continue; + // add sub id for UI + for (let j = 0; j < sub.videos.length; j++) { + sub.videos[j].sub_id = sub.id; + } + + files = files.concat(sub.videos); } res.send({ files: files, playlists: playlists - }) + }); }); // video sharing diff --git a/src/app/components/recent-videos/recent-videos.component.ts b/src/app/components/recent-videos/recent-videos.component.ts index 77d46fd..7ac5a73 100644 --- a/src/app/components/recent-videos/recent-videos.component.ts +++ b/src/app/components/recent-videos/recent-videos.component.ts @@ -15,10 +15,19 @@ export class RecentVideosComponent implements OnInit { constructor(private postsService: PostsService) { } ngOnInit(): void { + this.postsService.service_initialized.subscribe(init => { + if (init) { + this.getAllFiles(); + } + }); } getAllFiles() { - + this.normal_files_received = false; + this.postsService.getAllFiles().subscribe(res => { + this.files = res['files']; + this.files.sort(this.sortFiles); + }); } sortFiles(a, b) { 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 58cd542..5816a3c 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 @@ -14,8 +14,8 @@
-
- Thumbnail +
+ Thumbnail
{{file_title}} diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index b334c1e..62ce5d2 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -207,6 +207,10 @@ export class PostsService implements CanActivate { return this.http.post(this.path + 'getFile', {uid: uid, type: type, uuid: uuid}, this.httpOptions); } + getAllFiles() { + return this.http.post(this.path + 'getAllFiles', {}, this.httpOptions); + } + downloadFileFromServer(fileName, type, outputName = null, fullPathProvided = null, subscriptionName = null, subPlaylist = null, uid = null, uuid = null) { return this.http.post(this.path + 'downloadFile', {fileNames: fileName,