|
@@ -1,5 +1,4 @@
|
|
|
import async from "async";
|
|
|
-import config from "config";
|
|
|
import mongoose from "mongoose";
|
|
|
import CoreClass from "../core";
|
|
|
|
|
@@ -307,15 +306,8 @@ class _SongsModule extends CoreClass {
|
|
|
return next(null, song);
|
|
|
});
|
|
|
} else {
|
|
|
- const status =
|
|
|
- (!payload.userId && config.get("hideAnonymousSongs")) ||
|
|
|
- (payload.automaticallyRequested && config.get("hideAutomaticallyRequestedSongs"))
|
|
|
- ? "hidden"
|
|
|
- : "unverified";
|
|
|
-
|
|
|
const song = new SongsModule.SongModel({
|
|
|
...youtubeSong,
|
|
|
- status,
|
|
|
requestedBy: payload.userId,
|
|
|
requestedAt: Date.now()
|
|
|
});
|
|
@@ -398,7 +390,7 @@ class _SongsModule extends CoreClass {
|
|
|
},
|
|
|
|
|
|
(song, next) => {
|
|
|
- const { _id, youtubeId, title, artists, thumbnail, duration, status } = song;
|
|
|
+ const { _id, youtubeId, title, artists, thumbnail, duration, verified } = song;
|
|
|
const trimmedSong = {
|
|
|
_id,
|
|
|
youtubeId,
|
|
@@ -406,7 +398,7 @@ class _SongsModule extends CoreClass {
|
|
|
artists,
|
|
|
thumbnail,
|
|
|
duration,
|
|
|
- status
|
|
|
+ verified
|
|
|
};
|
|
|
this.log("INFO", `Going to update playlists now for song ${_id}`);
|
|
|
DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this)
|
|
@@ -454,7 +446,7 @@ class _SongsModule extends CoreClass {
|
|
|
},
|
|
|
|
|
|
(song, next) => {
|
|
|
- const { _id, youtubeId, title, artists, thumbnail, duration, status } = song;
|
|
|
+ const { _id, youtubeId, title, artists, thumbnail, duration, verified } = song;
|
|
|
this.log("INFO", `Going to update stations now for song ${_id}`);
|
|
|
DBModule.runJob("GET_MODEL", { modelName: "station" }, this)
|
|
|
.then(stationModel => {
|
|
@@ -467,7 +459,7 @@ class _SongsModule extends CoreClass {
|
|
|
"queue.$.artists": artists,
|
|
|
"queue.$.thumbnail": thumbnail,
|
|
|
"queue.$.duration": duration,
|
|
|
- "queue.$.status": status
|
|
|
+ "queue.$.verified": verified
|
|
|
}
|
|
|
},
|
|
|
err => {
|
|
@@ -669,7 +661,6 @@ class _SongsModule extends CoreClass {
|
|
|
*
|
|
|
* @param {object} payload - object that contains the payload
|
|
|
* @param {string} payload.query - the query
|
|
|
- * @param {string} payload.includeHidden - include hidden songs
|
|
|
* @param {string} payload.includeUnverified - include unverified songs
|
|
|
* @param {string} payload.includeVerified - include verified songs
|
|
|
* @param {string} payload.trimmed - include trimmed songs
|
|
@@ -681,11 +672,10 @@ class _SongsModule extends CoreClass {
|
|
|
async.waterfall(
|
|
|
[
|
|
|
next => {
|
|
|
- const statuses = [];
|
|
|
- if (payload.includeHidden) statuses.push("hidden");
|
|
|
- if (payload.includeUnverified) statuses.push("unverified");
|
|
|
- if (payload.includeVerified) statuses.push("verified");
|
|
|
- if (statuses.length === 0) return next("No statuses have been included.");
|
|
|
+ const isVerified = [];
|
|
|
+ if (payload.includeUnverified) isVerified.push(false);
|
|
|
+ if (payload.includeVerified) isVerified.push(true);
|
|
|
+ if (isVerified.length === 0) return next("No verified status has been included.");
|
|
|
|
|
|
let { query } = payload;
|
|
|
|
|
@@ -697,11 +687,11 @@ class _SongsModule extends CoreClass {
|
|
|
const filterArray = [
|
|
|
{
|
|
|
title: new RegExp(`${query}`, "i"),
|
|
|
- status: { $in: statuses }
|
|
|
+ verified: { $in: isVerified }
|
|
|
},
|
|
|
{
|
|
|
artists: new RegExp(`${query}`, "i"),
|
|
|
- status: { $in: statuses }
|
|
|
+ verified: { $in: isVerified }
|
|
|
}
|
|
|
];
|
|
|
|
|
@@ -740,7 +730,7 @@ class _SongsModule extends CoreClass {
|
|
|
else if (payload.trimmed) {
|
|
|
next(null, {
|
|
|
songs: data.songs.map(song => {
|
|
|
- const { _id, youtubeId, title, artists, thumbnail, duration, status } = song;
|
|
|
+ const { _id, youtubeId, title, artists, thumbnail, duration, verified } = song;
|
|
|
return {
|
|
|
_id,
|
|
|
youtubeId,
|
|
@@ -748,7 +738,7 @@ class _SongsModule extends CoreClass {
|
|
|
artists,
|
|
|
thumbnail,
|
|
|
duration,
|
|
|
- status
|
|
|
+ verified
|
|
|
};
|
|
|
}),
|
|
|
...data
|
|
@@ -869,7 +859,7 @@ class _SongsModule extends CoreClass {
|
|
|
async.waterfall(
|
|
|
[
|
|
|
next => {
|
|
|
- SongsModule.SongModel.find({ status: "verified" }, { genres: 1, _id: false }, next);
|
|
|
+ SongsModule.SongModel.find({ verified: true }, { genres: 1, _id: false }, next);
|
|
|
},
|
|
|
|
|
|
(songs, next) => {
|
|
@@ -908,7 +898,7 @@ class _SongsModule extends CoreClass {
|
|
|
next => {
|
|
|
SongsModule.SongModel.find(
|
|
|
{
|
|
|
- status: "verified",
|
|
|
+ verified: true,
|
|
|
genres: { $regex: new RegExp(`^${payload.genre.toLowerCase()}$`, "i") }
|
|
|
},
|
|
|
next
|
|
@@ -999,9 +989,6 @@ class _SongsModule extends CoreClass {
|
|
|
if (song) return next("This song is already in the database.", song);
|
|
|
|
|
|
|
|
|
- const requestedBy = user.preferences.anonymousSongRequests ? null : userId;
|
|
|
- const status = !requestedBy && config.get("hideAnonymousSongs") ? "hidden" : "unverified";
|
|
|
-
|
|
|
return YouTubeModule.runJob("GET_SONG", { youtubeId }, this)
|
|
|
.then(response => {
|
|
|
const { song } = response;
|
|
@@ -1011,7 +998,7 @@ class _SongsModule extends CoreClass {
|
|
|
song.explicit = false;
|
|
|
song.requestedBy = user.preferences.anonymousSongRequests ? null : userId;
|
|
|
song.requestedAt = requestedAt;
|
|
|
- song.status = status;
|
|
|
+ song.verified = false;
|
|
|
next(null, song);
|
|
|
})
|
|
|
.catch(next);
|
|
@@ -1044,7 +1031,7 @@ class _SongsModule extends CoreClass {
|
|
|
async (err, song) => {
|
|
|
if (err && err !== "This song is already in the database.") return reject(err);
|
|
|
|
|
|
- const { _id, youtubeId, title, artists, thumbnail, duration, status } = song;
|
|
|
+ const { _id, youtubeId, title, artists, thumbnail, duration, verified } = song;
|
|
|
const trimmedSong = {
|
|
|
_id,
|
|
|
youtubeId,
|
|
@@ -1052,7 +1039,7 @@ class _SongsModule extends CoreClass {
|
|
|
artists,
|
|
|
thumbnail,
|
|
|
duration,
|
|
|
- status
|
|
|
+ verified
|
|
|
};
|
|
|
|
|
|
if (err && err === "This song is already in the database.")
|
|
@@ -1066,92 +1053,6 @@ class _SongsModule extends CoreClass {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Hides a song
|
|
|
- *
|
|
|
- * @param {object} payload - The payload
|
|
|
- * @param {string} payload.songId - The song id of the song
|
|
|
- * @returns {Promise} - returns promise (reject, resolve)
|
|
|
- */
|
|
|
- HIDE_SONG(payload) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- const { songId } = payload;
|
|
|
-
|
|
|
- async.waterfall(
|
|
|
- [
|
|
|
- next => {
|
|
|
- SongsModule.SongModel.findOne({ _id: songId }, next);
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- if (!song) return next("This song does not exist.");
|
|
|
- if (song.status === "hidden") return next("This song is already hidden.");
|
|
|
-
|
|
|
- return next(null, song.status);
|
|
|
- },
|
|
|
-
|
|
|
- (oldStatus, next) => {
|
|
|
- SongsModule.SongModel.updateOne({ _id: songId }, { status: "hidden" }, res =>
|
|
|
- next(null, res, oldStatus)
|
|
|
- );
|
|
|
- },
|
|
|
-
|
|
|
- (res, oldStatus, next) => {
|
|
|
- SongsModule.runJob("UPDATE_SONG", { songId, oldStatus });
|
|
|
- next();
|
|
|
- }
|
|
|
- ],
|
|
|
- async err => {
|
|
|
- if (err) reject(err);
|
|
|
- resolve();
|
|
|
- }
|
|
|
- );
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * Unhides a song
|
|
|
- *
|
|
|
- * @param {object} payload - The payload
|
|
|
- * @param {string} payload.songId - The song id of the song
|
|
|
- * @returns {Promise} - returns promise (reject, resolve)
|
|
|
- */
|
|
|
- UNHIDE_SONG(payload) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- const { songId } = payload;
|
|
|
-
|
|
|
- async.waterfall(
|
|
|
- [
|
|
|
- next => {
|
|
|
- SongsModule.SongModel.findOne({ _id: songId }, next);
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- if (!song) return next("This song does not exist.");
|
|
|
- if (song.status !== "hidden") return next("This song is not hidden.");
|
|
|
-
|
|
|
- return next();
|
|
|
- },
|
|
|
-
|
|
|
- next => {
|
|
|
- SongsModule.SongModel.updateOne({ _id: songId }, { status: "unverified" }, next);
|
|
|
- },
|
|
|
-
|
|
|
- (res, next) => {
|
|
|
- SongsModule.runJob("UPDATE_SONG", { songId, oldStatus: "hidden" });
|
|
|
- next();
|
|
|
- }
|
|
|
- ],
|
|
|
- async err => {
|
|
|
- if (err) reject(err);
|
|
|
- resolve();
|
|
|
- }
|
|
|
- );
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -1198,7 +1099,7 @@ class _SongsModule extends CoreClass {
|
|
|
},
|
|
|
|
|
|
(song, next) => {
|
|
|
- const { _id, title, artists, thumbnail, duration, status } = song;
|
|
|
+ const { _id, title, artists, thumbnail, duration, verified } = song;
|
|
|
const trimmedSong = {
|
|
|
_id,
|
|
|
youtubeId,
|
|
@@ -1206,7 +1107,7 @@ class _SongsModule extends CoreClass {
|
|
|
artists,
|
|
|
thumbnail,
|
|
|
duration,
|
|
|
- status
|
|
|
+ verified
|
|
|
};
|
|
|
playlistModel.updateMany(
|
|
|
{ "songs.youtubeId": song.youtubeId },
|