diff --git a/README.md b/README.md index e5a490e34..1045bb4fb 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,7 @@ Beside those mentioned resources following additional resources are implemented: * `/api/cover/{hash}` * `/api/file/{fileId}` * `/api/file/{fileId}/info` -* `/api/file/{fileId}/webdav` +* `/api/file/{fileId}/path` * `/api/file/{fileId}/download` * `/api/scan` * `/api/scanstate` @@ -259,7 +259,7 @@ Response: ### `/api/collection` -Returns all artists with nested albums and each album with nested tracks. The tracks carry file IDs which can be used to obtain WebDAV link for playing with /api/file/{fileId}/webdav. +Returns all artists with nested albums and each album with nested tracks. Each track carries a file ID which can be used to obtain the file path with `/api/file/{fileId}/path`. The front-end converts the path into playable WebDAV link like this: `OC.linkToRemoteBase('webdav') + path`. GET /api/collection diff --git a/appinfo/routes.php b/appinfo/routes.php index 8189142a1..44dd140aa 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -29,7 +29,8 @@ ['name' => 'api#prepareCollection', 'url' => '/api/prepare_collection', 'verb' => 'POST'], ['name' => 'api#collection', 'url' => '/api/collection', 'verb' => 'GET'], ['name' => 'api#trackByFileId', 'url' => '/api/file/{fileId}', 'verb' => 'GET'], - ['name' => 'api#fileWebDavUrl', 'url' => '/api/file/{fileId}/webdav', 'verb' => 'GET'], + ['name' => 'api#fileWebDavUrl', 'url' => '/api/file/{fileId}/webdav', 'verb' => 'GET'], // DEPRECATED + ['name' => 'api#filePath', 'url' => '/api/file/{fileId}/path', 'verb' => 'GET'], ['name' => 'api#download', 'url' => '/api/file/{fileId}/download', 'verb' => 'GET'], ['name' => 'api#fileInfo', 'url' => '/api/file/{fileId}/info', 'verb' => 'GET'], ['name' => 'api#getScanState', 'url' => '/api/scanstate', 'verb' => 'GET'], diff --git a/controller/apicontroller.php b/controller/apicontroller.php index f20f59f1d..8d428eb52 100644 --- a/controller/apicontroller.php +++ b/controller/apicontroller.php @@ -310,6 +310,24 @@ public function trackByFileId($fileId) { * @NoAdminRequired * @NoCSRFRequired */ + public function filePath($fileId) { + $nodes = $this->userFolder->getById($fileId); + if (\count($nodes) == 0) { + return new ErrorResponse(Http::STATUS_NOT_FOUND); + } else { + $node = $nodes[0]; + $path = $this->userFolder->getRelativePath($node->getPath()); + // URL encode each part of the file path + $path = \join('/', \array_map('rawurlencode', \explode('/', $path))); + return new JSONResponse(['path' => $path]); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + * DEPRECATED + */ public function fileWebDavUrl($fileId) { $nodes = $this->userFolder->getById($fileId); if (\count($nodes) == 0) { diff --git a/js/app/controllers/playercontroller.js b/js/app/controllers/playercontroller.js index c3f4a9892..e390bfdd7 100644 --- a/js/app/controllers/playercontroller.js +++ b/js/app/controllers/playercontroller.js @@ -106,11 +106,12 @@ function ($scope, $rootScope, playlistService, libraryService, // get webDAV URL to the track and start playing it var mimeAndId = $scope.getPlayableFileId(track); - Restangular.one('file', mimeAndId.id).one('webdav').get().then(function(result) { + Restangular.one('file', mimeAndId.id).one('path').get().then(function(result) { // It is possible that the active track has already changed again by the time we get // the URI. Do not start playback in that case. if (track == $scope.currentTrack) { - var url = result.url + '?requesttoken=' + encodeURIComponent(OC.requestToken); + var url = OC.linkToRemoteBase('webdav') + result.path + + '?requesttoken=' + encodeURIComponent(OC.requestToken); $scope.player.fromURL(url, mimeAndId.mime); $scope.seekCursorType = $scope.player.seekingSupported() ? 'pointer' : 'default'; diff --git a/js/public/app.js b/js/public/app.js index 1563c780f..41d236713 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -681,11 +681,12 @@ function ($scope, $rootScope, playlistService, libraryService, // get webDAV URL to the track and start playing it var mimeAndId = $scope.getPlayableFileId(track); - Restangular.one('file', mimeAndId.id).one('webdav').get().then(function(result) { + Restangular.one('file', mimeAndId.id).one('path').get().then(function(result) { // It is possible that the active track has already changed again by the time we get // the URI. Do not start playback in that case. if (track == $scope.currentTrack) { - var url = result.url + '?requesttoken=' + encodeURIComponent(OC.requestToken); + var url = OC.linkToRemoteBase('webdav') + result.path + + '?requesttoken=' + encodeURIComponent(OC.requestToken); $scope.player.fromURL(url, mimeAndId.mime); $scope.seekCursorType = $scope.player.seekingSupported() ? 'pointer' : 'default';