-
Notifications
You must be signed in to change notification settings - Fork 3
WIP feat: each track.url update matching providerTrack #45
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
# config | ||
.env | ||
|
||
# secrets | ||
.runtimeconfig.json | ||
|
||
# compiled output | ||
/dist | ||
/tmp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.11.5 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
const functions = require('firebase-functions') | ||
const app = require('./src/app') | ||
const onTrackUrlChange = require('./src/on-track-url-change') | ||
|
||
// Public API for Radio4000 | ||
exports.api = functions.https.onRequest(app) | ||
|
||
// Listen to every track change | ||
exports.onTrackUrlChange = | ||
functions.database.ref('/tracks/{trackId}/url') | ||
.onWrite(onTrackUrlChange) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const functions = require('firebase-functions') | ||
const admin = require('firebase-admin'); | ||
const getYoutubeId = require('./utils/youtube-url-to-id.js') | ||
|
||
/* | ||
To test the execution of this function | ||
you can run `yarn firebase:shell` | ||
and use the following mockup call | ||
|
||
onTrackUrlChange({before: 'youtu.be/xIaco5AQrUQ', after: 'https://www.youtube.com/watch?v=OkR7UNnQU6c' }) | ||
*/ | ||
|
||
const onTracksChange = (snapshot, context) => { | ||
// console.log('snapshot: ', snapshot) | ||
// console.log('context: ', context) | ||
|
||
let db = admin.database(); | ||
|
||
let newUrl = snapshot.after.val() | ||
let providerId = getYoutubeId(newUrl) | ||
let providerName = 'youtube' | ||
|
||
// abort if no ID in provider URL | ||
if(!providerId) { | ||
return false | ||
} | ||
|
||
const ref = db.ref(`/providerTracks/${providerName}:${providerId}/tracks/${context.params.trackId}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about splitting ala https://media.now.sh/youtube/YyI52_FEYgY There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now the DB looks like this
So if you want to query it with ember your just do If you separate the provider with a slash how would you query the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. Not sure how to query that either. Maybe different models. Each extend If we have Another idea is to move the provider to to a property? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that there is a misunderstanding on the point of this new model. I will try to make a summary to explain the idea better. |
||
|
||
return ref.set(true); | ||
} | ||
|
||
module.exports = onTracksChange | ||
|
||
/* | ||
Model `providerTrack`: | ||
- tracks: list of tracks that reference this providerTrack | ||
- discogsReleaseId: id of this track's release on discogs | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const youtubeRegex = require('youtube-regex') | ||
|
||
const youtubeUrlToId = function(url) { | ||
const results = youtubeRegex().exec(url); | ||
if (!results) { | ||
return false; | ||
} | ||
return results[1]; | ||
} | ||
|
||
module.exports = youtubeUrlToId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does
onWrite
mean create+update? Does it also include delete?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.