From e5c9ff3e71b9eea35e05123bb01f99b1762e666b Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Sat, 1 Oct 2016 18:20:49 +0100 Subject: [PATCH] Added dialog for track load errors --- app/Http/Controllers/TracksController.php | 7 +++- .../partials/track-load-fail-dialog.html | 17 ++++++++++ .../assets/scripts/app/services/player.coffee | 33 +++++++++++-------- 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 public/templates/partials/track-load-fail-dialog.html diff --git a/app/Http/Controllers/TracksController.php b/app/Http/Controllers/TracksController.php index 05f60a5f..ff42d6cf 100644 --- a/app/Http/Controllers/TracksController.php +++ b/app/Http/Controllers/TracksController.php @@ -114,11 +114,16 @@ class TracksController extends Controller } $trackFile = TrackFile::findOrFailByExtension($track->id, $extension); - ResourceLogItem::logItem('track', $id, ResourceLogItem::PLAY, $trackFile->getFormat()['index']); $response = Response::make('', 200); $filename = $trackFile->getFile(); + if (!file_exists($filename)) { + App::abort(418); + } + + ResourceLogItem::logItem('track', $id, ResourceLogItem::PLAY, $trackFile->getFormat()['index']); + if (Config::get('app.sendfile')) { $response->header('X-Sendfile', $filename); } else { diff --git a/public/templates/partials/track-load-fail-dialog.html b/public/templates/partials/track-load-fail-dialog.html new file mode 100644 index 00000000..35b81f13 --- /dev/null +++ b/public/templates/partials/track-load-fail-dialog.html @@ -0,0 +1,17 @@ + diff --git a/resources/assets/scripts/app/services/player.coffee b/resources/assets/scripts/app/services/player.coffee index bcdc93b1..5e11b5dc 100644 --- a/resources/assets/scripts/app/services/player.coffee +++ b/resources/assets/scripts/app/services/player.coffee @@ -15,8 +15,8 @@ # along with this program. If not, see . module.exports = angular.module('ponyfm').factory('player', [ - '$rootScope', '$http' - ($rootScope, $http) -> + '$rootScope', '$http', '$modal' + ($rootScope, $http, $modal) -> readyDef = new $.Deferred() play = (track) -> @@ -43,6 +43,13 @@ module.exports = angular.module('ponyfm').factory('player', [ track.progressSeconds = self.currentSound.position / 1000 track.progress = (self.currentSound.position / (track.duration * 1000)) * 100 + onload: (res) -> $rootScope.safeApply -> + if !res + # Track failed to load + dialog = $modal + templateUrl: '/templates/partials/track-load-fail-dialog.html', + show: true + onfinish: () -> $rootScope.safeApply -> if self.repeatState == 2 # Track repeat @@ -169,18 +176,18 @@ module.exports = angular.module('ponyfm').factory('player', [ self.ready = true self.setVolume($.cookie('pfm-volume') || 100) - codeArray = [] - codeKey = '38,38,40,40,37,39,37,39,66,65' - $(document).keydown (e) -> - codeArray.push e.keyCode - if codeArray.toString().indexOf(codeKey) >= 0 - $http.get('https://pony.fm/api/web/tracks/23453').success (trackResponse) => - toPlay = trackResponse.track - play(toPlay) - codeArray = [] - return - readyDef.resolve() + codeArray = [] + codeKey = '38,38,40,40,37,39,37,39,66,65' + $(document).keydown (e) -> + codeArray.push e.keyCode + if codeArray.toString().indexOf(codeKey) >= 0 + $http.get('https://pony.fm/api/web/tracks/23453').success (trackResponse) => + toPlay = trackResponse.track + self.playTracks [toPlay], 0 + codeArray = [] + return + self ])