This repository was archived by the owner on Mar 2, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +512
-236
lines changed Expand file tree Collapse file tree 8 files changed +512
-236
lines changed Original file line number Diff line number Diff line change 33# config
44.env
55
6+ # secrets
7+ .runtimeconfig.json
8+
69# compiled output
710/dist
811/tmp
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -195,3 +195,13 @@ Firebase allowed this project to come to life without having the need to spend t
195195
196196Do you want your project to appear here? Send a pull request or get in touch.
197197
198+ ## Developement
199+
200+ ` firebase functions:config:get > .runtimeconfig.json ` will download
201+ locally the secret keys saved in the project environment. You will
202+ need them to run the API.
203+
204+ ` yarn start ` will run the API.
205+
206+ ` yarn firebase:shell ` will run the Firebase shell, with which can
207+ locally be testes the non-https functions. See the [ documentation] ( https://firebase.google.com/docs/functions/local-emulator ) .
Original file line number Diff line number Diff line change 11const functions = require ( 'firebase-functions' )
22const app = require ( './src/app' )
3+ const onTrackUrlChange = require ( './src/on-track-url-change' )
34
5+ // Public API for Radio4000
46exports . api = functions . https . onRequest ( app )
7+
8+ // Listen to every track change
9+ exports . onTrackUrlChange =
10+ functions . database . ref ( '/tracks/{trackId}/url' )
11+ . onWrite ( onTrackUrlChange )
Original file line number Diff line number Diff line change 77 "scripts" : {
88 "start" : " firebase serve --only hosting,functions --port 4001" ,
99 "test" : " ava" ,
10+ "firebase:shell" : " firebase functions:shell" ,
1011 "deploy-api" : " firebase use staging; firebase deploy --only functions" ,
1112 "deploy-api-production" : " firebase use production; firebase deploy --only functions" ,
1213 "deploy-rules" : " firebase use staging; firebase deploy --only database" ,
1617 "body-parser" : " ^1.17.2" ,
1718 "cors" : " ^2.8.4" ,
1819 "express" : " ^4.15.3" ,
19- "firebase-admin" : " ^5.10.0 " ,
20- "firebase-functions" : " ^0.8.2 " ,
20+ "firebase-admin" : " ^5.12.1 " ,
21+ "firebase-functions" : " ^1.1.0 " ,
2122 "got" : " ^6.7.1" ,
2223 "radio4000-sdk" : " ^0.0.5" ,
23- "stripe" : " ^4.24.0"
24+ "stripe" : " ^4.24.0" ,
25+ "youtube-regex" : " ^1.0.5"
2426 },
2527 "devDependencies" : {
2628 "ava" : " ^0.21.0" ,
27- "firebase-tools" : " ^3.17.7"
29+ "firebase-tools" : " ^3.17.7" ,
30+ "@google-cloud/functions-emulator" : " ^1.0.0-beta.4"
2831 }
2932}
Original file line number Diff line number Diff line change 1+ const functions = require ( 'firebase-functions' )
2+ const admin = require ( 'firebase-admin' ) ;
3+ const getYoutubeId = require ( './utils/youtube-url-to-id.js' )
4+
5+ /*
6+ To test the execution of this function
7+ you can run `yarn firebase:shell`
8+ and use the following mockup call
9+
10+ onTrackUrlChange({before: 'youtu.be/xIaco5AQrUQ', after: 'https://www.youtube.com/watch?v=OkR7UNnQU6c' })
11+ */
12+
13+ const onTracksChange = ( snapshot , context ) => {
14+ // console.log('snapshot: ', snapshot)
15+ // console.log('context: ', context)
16+
17+ let db = admin . database ( ) ;
18+
19+ let newUrl = snapshot . after . val ( )
20+ let providerId = getYoutubeId ( newUrl )
21+ let providerName = 'youtube'
22+
23+ // abort if no ID in provider URL
24+ if ( ! providerId ) {
25+ return false
26+ }
27+
28+ const ref = db . ref ( `/providerTracks/${ providerName } :${ providerId } /tracks/${ context . params . trackId } ` ) ;
29+
30+ return ref . set ( true ) ;
31+ }
32+
33+ module . exports = onTracksChange
34+
35+ /*
36+ Model `providerTrack`:
37+ - tracks: list of tracks that reference this providerTrack
38+ - discogsReleaseId: id of this track's release on discogs
39+ */
Original file line number Diff line number Diff line change 1+ const youtubeRegex = require ( 'youtube-regex' )
2+
3+ const youtubeUrlToId = function ( url ) {
4+ const results = youtubeRegex ( ) . exec ( url ) ;
5+ if ( ! results ) {
6+ return false ;
7+ }
8+ return results [ 1 ] ;
9+ }
10+
11+ module . exports = youtubeUrlToId
You can’t perform that action at this time.
0 commit comments