|
@@ -1,5 +1,4 @@
|
|
|
import async from "async";
|
|
|
-import config from "config";
|
|
|
import mongoose from "mongoose";
|
|
|
import CoreClass from "../core";
|
|
|
|
|
@@ -512,15 +511,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()
|
|
|
});
|
|
@@ -603,7 +595,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,
|
|
@@ -611,7 +603,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)
|
|
@@ -659,7 +651,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 => {
|
|
@@ -672,7 +664,7 @@ class _SongsModule extends CoreClass {
|
|
|
"queue.$.artists": artists,
|
|
|
"queue.$.thumbnail": thumbnail,
|
|
|
"queue.$.duration": duration,
|
|
|
- "queue.$.status": status
|
|
|
+ "queue.$.verified": verified
|
|
|
}
|
|
|
},
|
|
|
err => {
|
|
@@ -874,7 +866,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
|
|
@@ -886,11 +877,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;
|
|
|
|
|
@@ -902,11 +892,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 }
|
|
|
}
|
|
|
];
|
|
|
|
|
@@ -945,7 +935,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,
|
|
@@ -953,7 +943,7 @@ class _SongsModule extends CoreClass {
|
|
|
artists,
|
|
|
thumbnail,
|
|
|
duration,
|
|
|
- status
|
|
|
+ verified
|
|
|
};
|
|
|
}),
|
|
|
...data
|
|
@@ -1074,7 +1064,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) => {
|
|
@@ -1113,7 +1103,7 @@ class _SongsModule extends CoreClass {
|
|
|
next => {
|
|
|
SongsModule.SongModel.find(
|
|
|
{
|
|
|
- status: "verified",
|
|
|
+ verified: true,
|
|
|
genres: { $regex: new RegExp(`^${payload.genre.toLowerCase()}$`, "i") }
|
|
|
},
|
|
|
next
|
|
@@ -1204,9 +1194,6 @@ class _SongsModule extends CoreClass {
|
|
|
if (song) return next("This song is already in the database.", song);
|
|
|
// TODO Add err object as first param of callback
|
|
|
|
|
|
- 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;
|
|
@@ -1216,7 +1203,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);
|
|
@@ -1249,7 +1236,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,
|
|
@@ -1257,7 +1244,7 @@ class _SongsModule extends CoreClass {
|
|
|
artists,
|
|
|
thumbnail,
|
|
|
duration,
|
|
|
- status
|
|
|
+ verified
|
|
|
};
|
|
|
|
|
|
if (err && err === "This song is already in the database.")
|
|
@@ -1271,92 +1258,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);
|
|
|
- },
|
|
|
-
|
|
|
- // Get YouTube data from id
|
|
|
- (song, next) => {
|
|
|
- if (!song) return next("This song does not exist.");
|
|
|
- if (song.status === "hidden") return next("This song is already hidden.");
|
|
|
- // TODO Add err object as first param of callback
|
|
|
- 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);
|
|
|
- },
|
|
|
-
|
|
|
- // Get YouTube data from id
|
|
|
- (song, next) => {
|
|
|
- if (!song) return next("This song does not exist.");
|
|
|
- if (song.status !== "hidden") return next("This song is not hidden.");
|
|
|
- // TODO Add err object as first param of callback
|
|
|
- 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();
|
|
|
- }
|
|
|
- );
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
// runjob songs REQUEST_ORPHANED_PLAYLIST_SONGS {}
|
|
|
|
|
|
/**
|
|
@@ -1403,7 +1304,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,
|
|
@@ -1411,7 +1312,7 @@ class _SongsModule extends CoreClass {
|
|
|
artists,
|
|
|
thumbnail,
|
|
|
duration,
|
|
|
- status
|
|
|
+ verified
|
|
|
};
|
|
|
playlistModel.updateMany(
|
|
|
{ "songs.youtubeId": song.youtubeId },
|
|
@@ -1517,7 +1418,7 @@ class _SongsModule extends CoreClass {
|
|
|
*
|
|
|
* @returns {Promise} - returns promise (reject, resolve)
|
|
|
*/
|
|
|
- GET_TAGS() {
|
|
|
+ GET_TAGS() {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
async.waterfall(
|
|
|
[
|