Parcourir la source

refactor(Station): Updated migration and minor tweaks

Owen Diffey il y a 3 ans
Parent
commit
dfa7ba538b

+ 1 - 1
backend/logic/db/index.js

@@ -13,7 +13,7 @@ const REQUIRED_DOCUMENT_VERSIONS = {
 	queueSong: 1,
 	report: 5,
 	song: 7,
-	station: 7,
+	station: 8,
 	user: 3
 };
 

+ 3 - 3
backend/logic/db/schemas/station.js

@@ -43,15 +43,15 @@ export default {
 	requests: {
 		enabled: { type: Boolean, default: true },
 		access: { type: String, enum: ["owner", "user"], default: "owner" },
-		limit: { type: Number, min: 1, max: 50, default: 3 }
+		limit: { type: Number, min: 1, max: 50, default: 5 }
 	},
 	autofill: {
 		enabled: { type: Boolean, default: true },
 		playlists: [{ type: mongoose.Schema.Types.ObjectId, ref: "playlists" }],
-		limit: { type: Number, min: 1, max: 50, default: 3 },
+		limit: { type: Number, min: 1, max: 50, default: 30 },
 		mode: { type: String, enum: ["random", "sequential"], default: "random" }
 	},
 	theme: { type: String, enum: ["blue", "purple", "teal", "orange", "red"], default: "blue" },
 	blacklist: [{ type: mongoose.Schema.Types.ObjectId, ref: "playlists" }],
-	documentVersion: { type: Number, default: 7, required: true }
+	documentVersion: { type: Number, default: 8, required: true }
 };

+ 21 - 48
backend/logic/migration/migrations/migration20.js

@@ -17,52 +17,10 @@ export default async function migrate(MigrationModule) {
 			[
 				next => {
 					this.log("INFO", `Migration 20. Finding stations with document version 7.`);
-					stationModel.find({ documentVersion: 7, excludedPlaylists: { $exists: true } }, (err, stations) => {
-						if (err) next(err);
-						else {
-							async.eachLimit(
-								stations.map(station => station._doc),
-								1,
-								(station, next) => {
-									stationModel.updateOne(
-										{ _id: station._id },
-										{
-											$unset: { excludedPlaylists: "" },
-											$set: {
-												blacklist: station.excludedPlaylists.map(playlist =>
-													mongoose.Types.ObjectId(playlist)
-												) /* ,
-												documentVersion: 8 */
-											}
-										},
-										next
-									);
-								},
-								err => {
-									this.log("INFO", `Migration 20. Stations found: ${stations.length}.`);
-									next(err);
-								}
-							);
-						}
-					});
-					stationModel.updateMany(
-						{ documentVersion: 7 },
+					stationModel.find(
 						{
-							$set: {
-								requests: {
-									enabled: true,
-									access: "owner",
-									limit: 3
-								}
-							}
+							documentVersion: 7
 						},
-						(err, res) => {
-							this.log("INFO", `Migration 20. Stations found: ${res.modifiedCount}.`);
-							next(err);
-						}
-					);
-					stationModel.find(
-						{ documentVersion: 7, includedPlaylists: { $exists: true }, playMode: { $exists: true } },
 						(err, stations) => {
 							if (err) next(err);
 							else {
@@ -73,16 +31,31 @@ export default async function migrate(MigrationModule) {
 										stationModel.updateOne(
 											{ _id: station._id },
 											{
-												$unset: { includedPlaylists: "", playMode: "" },
+												$unset: {
+													includedPlaylists: "",
+													excludedPlaylists: "",
+													playMode: "",
+													partyMode: "",
+													locked: ""
+												},
 												$set: {
 													autofill: {
-														enabled: true,
+														enabled: !station.partyMode,
 														playlists: station.includedPlaylists.map(playlist =>
 															mongoose.Types.ObjectId(playlist)
 														),
-														limit: 3,
+														limit: 30,
 														mode: station.playMode
-													}
+													},
+													requests: {
+														enabled: station.partyMode,
+														access: station.locked ? "owner" : "user",
+														limit: 5
+													},
+													blacklist: station.excludedPlaylists.map(playlist =>
+														mongoose.Types.ObjectId(playlist)
+													),
+													documentVersion: 8
 												}
 											},
 											next

+ 6 - 4
frontend/src/components/PlaylistTabBase.vue

@@ -22,7 +22,9 @@
 					Current
 				</button>
 				<button
-					v-if="station.type === 'community'"
+					v-if="
+						type === 'autorequest' || station.type === 'community'
+					"
 					class="button is-default"
 					ref="my-playlists-tab"
 					:class="{ selected: tab === 'my-playlists' }"
@@ -210,7 +212,7 @@
 					</playlist-item>
 					<br />
 				</div>
-				<label class="label"> Search for a public playlist </label>
+				<label class="label">Search for a playlist</label>
 				<div class="control is-grouped input-with-button">
 					<p class="control is-expanded">
 						<input
@@ -455,7 +457,7 @@
 				</p>
 			</div>
 			<div
-				v-if="station.type === 'community'"
+				v-if="type === 'autorequest' || station.type === 'community'"
 				class="tab"
 				v-show="tab === 'my-playlists'"
 			>
@@ -932,7 +934,7 @@ export default {
 
 			const { query } = this.search;
 			const action =
-				this.station.type === "official"
+				this.station.type === "official" && this.type !== "autorequest"
 					? "playlists.searchOfficial"
 					: "playlists.searchCommunity";
 

+ 0 - 1
frontend/src/components/modals/ManageStation/Settings.vue

@@ -281,7 +281,6 @@ export default {
 		width: 100%;
 		margin: 10px 0;
 		padding: 10px;
-		background-color: var(--light-grey);
 		border-radius: @border-radius;
 		box-shadow: @box-shadow;