mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-03-03 16:51:28 +01:00
Add download-cached service
This commit is contained in:
parent
4c5a03329a
commit
d4526852cf
1 changed files with 20 additions and 0 deletions
20
resources/assets/scripts/app/services/download-cached.coffee
Normal file
20
resources/assets/scripts/app/services/download-cached.coffee
Normal file
|
@ -0,0 +1,20 @@
|
|||
angular.module('ponyfm').factory('download-cached', [
|
||||
'$rootScope', '$http', '$log'
|
||||
($rootScope, $http, $log) ->
|
||||
download = (type, id, format) ->
|
||||
url = '/api/web/' + type + '/download-cached/' + id + '/' + format
|
||||
|
||||
encodingComplete = (response) ->
|
||||
if response.data.url == null
|
||||
'pending'
|
||||
else
|
||||
response.data.url
|
||||
|
||||
encodingFailed = (error) ->
|
||||
$log.error 'Error downloading encoded file - Status: ' + error.status + '- Message: ' + error.data
|
||||
'error'
|
||||
|
||||
$http.get(url).then(encodingComplete).catch encodingFailed
|
||||
|
||||
{download: download}
|
||||
])
|
Loading…
Add table
Reference in a new issue