Ver código fonte

refactor: change the youtube/soundcloud get_data songId custom aggregation pipeline to support mediaSource

Kristian Vos 1 ano atrás
pai
commit
c7ad45dbdc
2 arquivos alterados com 24 adições e 8 exclusões
  1. 12 4
      backend/logic/actions/soundcloud.js
  2. 12 4
      backend/logic/actions/youtube.js

+ 12 - 4
backend/logic/actions/soundcloud.js

@@ -166,12 +166,20 @@ export default {
 								blacklistedProperties: [],
 								specialProperties: {
 									songId: [
-										// Fetch songs from songs collection with a matching mediaSource
+										// Fetch songs from songs collection with a matching mediaSource, which we first need to assemble
 										{
 											$lookup: {
-												from: "songs", // TODO fix this to support mediasource, so start with youtube:, so add a new pipeline steps
-												localField: "trackId",
-												foreignField: "trackId",
+												from: "songs",
+												let: {
+													mediaSource: { $concat: ["soundcloud:", { $toString: "$trackId" }] }
+												},
+												pipeline: [
+													{
+														$match: {
+															$expr: { $eq: ["$mediaSource", "$$mediaSource"] }
+														}
+													}
+												],
 												as: "song"
 											}
 										},

+ 12 - 4
backend/logic/actions/youtube.js

@@ -265,12 +265,20 @@ export default {
 								blacklistedProperties: [],
 								specialProperties: {
 									songId: [
-										// Fetch songs from songs collection with a matching mediaSource
+										// Fetch songs from songs collection with a matching mediaSource, which we first need to assemble
 										{
 											$lookup: {
-												from: "songs", // TODO fix this to support mediasource, so start with youtube:, so add a new pipeline steps
-												localField: "youtubeId",
-												foreignField: "youtubeId",
+												from: "songs",
+												let: {
+													mediaSource: { $concat: ["youtube:", "$youtubeId"] }
+												},
+												pipeline: [
+													{
+														$match: {
+															$expr: { $eq: ["$mediaSource", "$$mediaSource"] }
+														}
+													}
+												],
 												as: "song"
 											}
 										},