Browse Source

Merge branch 'polishing' into kris-station-local-skipping

Kristian Vos 3 years ago
parent
commit
10d014e54a

+ 4 - 8
backend/logic/actions/songs.js

@@ -741,15 +741,15 @@ export default {
 	 * Verifies a song
 	 *
 	 * @param session
-	 * @param youtubeId - the youtube id
+	 * @param songId - the song id
 	 * @param cb
 	 */
-	verify: isAdminRequired(async function add(session, youtubeId, cb) {
+	verify: isAdminRequired(async function add(session, songId, cb) {
 		const SongModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
 		async.waterfall(
 			[
 				next => {
-					SongModel.findOne({ youtubeId }, next);
+					SongModel.findOne({ _id: songId }, next);
 				},
 
 				(song, next) => {
@@ -787,11 +787,7 @@ export default {
 					return cb({ status: "error", message: err });
 				}
 
-				this.log(
-					"SUCCESS",
-					"SONGS_VERIFY",
-					`User "${session.userId}" successfully verified song "${youtubeId}".`
-				);
+				this.log("SUCCESS", "SONGS_VERIFY", `User "${session.userId}" successfully verified song "${songId}".`);
 
 				CacheModule.runJob("PUB", {
 					channel: "song.newVerifiedSong",

+ 49 - 2
backend/logic/actions/users.js

@@ -15,6 +15,7 @@ const WSModule = moduleManager.modules.ws;
 const CacheModule = moduleManager.modules.cache;
 const MailModule = moduleManager.modules.mail;
 const PunishmentsModule = moduleManager.modules.punishments;
+const SongsModule = moduleManager.modules.songs;
 const ActivitiesModule = moduleManager.modules.activities;
 const PlaylistsModule = moduleManager.modules.playlists;
 
@@ -222,6 +223,8 @@ export default {
 
 		const dataRequestEmail = await MailModule.runJob("GET_SCHEMA", { schemaName: "dataRequest" }, this);
 
+		const songsToAdjustRatings = [];
+
 		async.waterfall(
 			[
 				// activities related to the user
@@ -262,13 +265,57 @@ export default {
 					playlistModel.deleteMany({ owner: session.userId }, next);
 				},
 
-				// user's playlists
 				(res, next) => {
+					playlistModel.findOne({ createdBy: session.userId, displayName: "Liked Songs" }, next);
+				},
+
+				// get all liked songs (as the global rating values for these songs will need adjusted)
+				(playlist, next) => {
+					if (!playlist) return next();
+
+					playlist.songs.forEach(song =>
+						songsToAdjustRatings.push({ songId: song._id, youtubeId: song.youtubeId })
+					);
+
+					return next();
+				},
+
+				next => {
+					playlistModel.findOne({ createdBy: session.userId, displayName: "Disliked Songs" }, next);
+				},
+
+				// get all disliked songs (as the global rating values for these songs will need adjusted)
+				(playlist, next) => {
+					if (!playlist) return next();
+
+					playlist.songs.forEach(song =>
+						songsToAdjustRatings.push({ songId: song._id, youtubeId: song.youtubeId })
+					);
+
+					return next();
+				},
+
+				// user's playlists
+				next => {
 					playlistModel.deleteMany({ createdBy: session.userId }, next);
 				},
 
-				// user object
 				(res, next) => {
+					async.each(
+						songsToAdjustRatings,
+						(song, next) => {
+							const { songId, youtubeId } = song;
+
+							SongsModule.runJob("RECALCULATE_SONG_RATINGS", { songId, youtubeId })
+								.then(() => next())
+								.catch(next);
+						},
+						err => next(err)
+					);
+				},
+
+				// user object
+				next => {
 					userModel.deleteMany({ _id: session.userId }, next);
 				},
 

+ 11 - 11
frontend/prod.nginx.conf

@@ -21,19 +21,19 @@ http {
         location / {
             try_files $uri /build/$uri /build/index.html =404;
         }
-    }
 
-    location /backend {
-        proxy_set_header X-Real-IP  $remote_addr;
-        proxy_set_header X-Forwarded-For $remote_addr;
-        proxy_set_header Host $host;
+        location /backend {
+            proxy_set_header X-Real-IP  $remote_addr;
+            proxy_set_header X-Forwarded-For $remote_addr;
+            proxy_set_header Host $host;
 
-        proxy_http_version 1.1;
-        proxy_set_header Upgrade $http_upgrade;
-        proxy_set_header Connection "upgrade";
-        proxy_redirect off;
+            proxy_http_version 1.1;
+            proxy_set_header Upgrade $http_upgrade;
+            proxy_set_header Connection "upgrade";
+            proxy_redirect off;
 
-        rewrite ^/backend/?(.*) /$1 break;
-        proxy_pass http://backend:8080; 
+            rewrite ^/backend/?(.*) /$1 break;
+            proxy_pass http://backend:8080; 
+        }
     }
 }

+ 1 - 0
frontend/src/components/SongItem.vue

@@ -43,6 +43,7 @@
 					Requested by
 					<strong>
 						<user-id-to-username
+							:key="song._id"
 							:user-id="song.requestedBy"
 							:link="true"
 						/>

+ 6 - 7
frontend/src/components/modals/EditSong.vue

@@ -482,7 +482,7 @@
 					<button
 						v-if="song.status === 'unverified'"
 						class="button is-success"
-						@click="verify(song)"
+						@click="verify(song._id)"
 						content="Verify Song"
 						v-tippy
 					>
@@ -491,7 +491,7 @@
 					<confirm
 						v-if="song.status === 'verified'"
 						placement="left"
-						@confirm="unverify(song._id, index)"
+						@confirm="unverify(song._id)"
 					>
 						<button
 							class="button is-danger"
@@ -504,7 +504,7 @@
 					<confirm
 						v-if="song.status === 'unverified'"
 						placement="left"
-						@confirm="hide(song._id, index)"
+						@confirm="hide(song._id)"
 					>
 						<button
 							class="button is-danger"
@@ -1475,15 +1475,14 @@ export default {
 				this.activityWatchVideoLastStatus = "not_playing";
 			}
 		},
-		verify(song) {
-			this.socket.dispatch("songs.verify", song.youtubeId, res => {
+		verify(id) {
+			this.socket.dispatch("songs.verify", id, res => {
 				new Toast(res.message);
 			});
 		},
 		unverify(id) {
 			this.socket.dispatch("songs.unverify", id, res => {
-				if (res.status === "success") new Toast(res.message);
-				else new Toast(res.message);
+				new Toast(res.message);
 			});
 		},
 		hide(id) {

+ 3 - 3
frontend/src/pages/Admin/tabs/HiddenSongs.vue

@@ -96,7 +96,7 @@
 							</button>
 							<button
 								class="button is-success"
-								@click="unhide(song)"
+								@click="unhide(song._id)"
 								content="Unhide Song"
 								v-tippy
 							>
@@ -240,8 +240,8 @@ export default {
 			this.editSong(song);
 			this.openModal("editSong");
 		},
-		unhide(song) {
-			this.socket.dispatch("songs.unhide", song._id, res => {
+		unhide(id) {
+			this.socket.dispatch("songs.unhide", id, res => {
 				new Toast(res.message);
 			});
 		},

+ 4 - 7
frontend/src/pages/Admin/tabs/UnverifiedSongs.vue

@@ -96,16 +96,13 @@
 							</button>
 							<button
 								class="button is-success"
-								@click="verify(song)"
+								@click="verify(song._id)"
 								content="Verify Song"
 								v-tippy
 							>
 								<i class="material-icons">check_circle</i>
 							</button>
-							<confirm
-								placement="left"
-								@confirm="hide(song._id, index)"
-							>
+							<confirm placement="left" @confirm="hide(song._id)">
 								<button
 									class="button is-danger"
 									content="Hide Song"
@@ -256,8 +253,8 @@ export default {
 			this.editSong(song);
 			this.openModal("editSong");
 		},
-		verify(song) {
-			this.socket.dispatch("songs.verify", song.youtubeId, res => {
+		verify(id) {
+			this.socket.dispatch("songs.verify", id, res => {
 				new Toast(res.message);
 			});
 		},

+ 4 - 5
frontend/src/pages/Admin/tabs/VerifiedSongs.vue

@@ -89,7 +89,7 @@
 					</tr>
 				</thead>
 				<tbody>
-					<tr v-for="(song, index) in filteredSongs" :key="song._id">
+					<tr v-for="song in filteredSongs" :key="song._id">
 						<td>
 							<img
 								class="song-thumbnail"
@@ -134,7 +134,7 @@
 							</button>
 							<confirm
 								placement="left"
-								@confirm="remove(song._id, index)"
+								@confirm="unverify(song._id)"
 							>
 								<button
 									class="button is-danger"
@@ -357,10 +357,9 @@ export default {
 			this.editSong(song);
 			this.openModal("editSong");
 		},
-		remove(id) {
+		unverify(id) {
 			this.socket.dispatch("songs.unverify", id, res => {
-				if (res.status === "success") new Toast(res.message);
-				else new Toast(res.message);
+				new Toast(res.message);
 			});
 		},
 		updateAllSongs() {

+ 4 - 4
frontend/src/pages/Station/index.vue

@@ -12,10 +12,10 @@
 				preserve-aspect-ratio="none"
 				id="page-loader-content"
 			>
-				<rect x="100" y="108" rx="5" ry="5" width="1048" height="672" />
-				<rect x="100" y="810" rx="5" ry="5" width="1048" height="110" />
-				<rect x="1190" y="110" rx="5" ry="5" width="630" height="149" />
-				<rect x="1190" y="288" rx="5" ry="5" width="630" height="630" />
+				<rect x="55" y="105" rx="5" ry="5" width="670" height="149" />
+				<rect x="55" y="283" rx="5" ry="5" width="670" height="640" />
+				<rect x="745" y="108" rx="5" ry="5" width="1120" height="672" />
+				<rect x="745" y="810" rx="5" ry="5" width="1120" height="110" />
 			</content-loader>
 
 			<content-loader