Skip to content

Commit

Permalink
feat: check track youtube media availability on update
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Vieilledent committed Jul 13, 2018
1 parent f0e46f1 commit 64fe29b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/models/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import firebase from 'firebase';
import {task} from 'ember-concurrency';
import {validator, buildValidations} from 'ember-cp-validations';
import youtubeUrlToId from 'radio4000/utils/youtube-url-to-id';
import {fetchTrackAvailability} from 'radio4000/utils/youtube-api';
import format from 'npm:date-fns/format';

const {Model, attr, belongsTo} = DS;
Expand Down Expand Up @@ -91,10 +92,22 @@ export default Model.extend(Validations, {
},

// In case url changed, we need to set the ytid.
// and also check if the track is available on the provider
update: task(function * () {
if (!get(this, 'hasDirtyAttributes')) {
return
}

const ytid = this.get('ytid')

let mediaNotAvailable = yield !fetchTrackAvailability(ytid)

if(mediaNotAvailable) {
this.set('mediaNotAvailable', true)
} else {
this.set('mediaNotAvailable', false)
}

yield this.updateYoutubeId();
yield this.save()
}).drop(),
Expand Down

0 comments on commit 64fe29b

Please sign in to comment.