From 265c0c4edf029b6c14d7fe8c44508088eff00ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauli=20J=C3=A4rvinen?= Date: Sun, 7 Jan 2024 18:27:27 +0200 Subject: [PATCH] Create the play URLs for playlists files within the front-end on NC28 In the previous NC28-compatibility changes, we made the backend include the playback URLs when it parses a playlist file and returns its contents in the REST method `/api/playlists/file/{fileId}`. This had such a drawback that it increased the parsing time ~25% and the response size by ~50% which could make a difference with huge playlist files. Meanwhile, we don't actually need the playback URL for any other song except the one which is just being played. This was now changed so that the playback URL is created on the front-end based on the file ID whenever the playing song changes. The logic to create the playback URL is the same as is used in the Music app proper. --- js/embedded/main.js | 8 +++++--- lib/Controller/PlaylistApiController.php | 1 - lib/Controller/ShareController.php | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/js/embedded/main.js b/js/embedded/main.js index 8e0a641c9..6c4b1f6ab 100644 --- a/js/embedded/main.js +++ b/js/embedded/main.js @@ -54,7 +54,9 @@ function initEmbeddedPlayer() { register(); function urlForFile(file) { - let url = file.url ?? mFileList.getDownloadUrl(file.name, file.path); + let url = mFileList + ? mFileList.getDownloadUrl(file.name, file.path) + : OC.filePath('music', '', 'index.php') + '/api/file/' + file.id + '/download'; // Append request token unless this is a public share. This is actually unnecessary for most files // but needed when the file in question is played using our Aurora.js fallback player. @@ -289,7 +291,7 @@ function initEmbeddedPlayer() { */ exec: (file, view, dir) => { const adaptFile = (f) => { - return {id: f.fileid, name: f.basename, mimetype: f.mime, url: f.source, path: dir}; + return {id: f.fileid, name: f.basename, mimetype: f.mime, path: dir}; }; onActionCallback(adaptFile(file)); @@ -303,7 +305,7 @@ function initEmbeddedPlayer() { // this is how NC28 seems to do this (older NC versions, on the other hand, used the user-selected UI-language // as the locale for sorting although user-selected locale would have made even more sense). // This still leaves such a mismatch that the special characters may be sorted differently by localeCompare than - // what NC28 files does (it uses the 3rd party library natural-orderby for this). + // what NC28 Files does (it uses the 3rd party library natural-orderby for this). dirFiles.sort((a, b) => a.name.localeCompare(b.name, undefined, {numeric: true, sensitivity: 'base'})); mPlaylist = new OCA.Music.Playlist(dirFiles, mAudioMimes, mCurrentFile.id); diff --git a/lib/Controller/PlaylistApiController.php b/lib/Controller/PlaylistApiController.php index c796ad776..7f7d461e7 100644 --- a/lib/Controller/PlaylistApiController.php +++ b/lib/Controller/PlaylistApiController.php @@ -363,7 +363,6 @@ public function parseFile(int $fileId) { 'id' => $file->getId(), 'name' => $file->getName(), 'path' => $this->userFolder->getRelativePath($file->getParent()->getPath()), - 'url' => $this->urlGenerator->linkToRoute('music.api.download', ['fileId' => $file->getId()]), 'mimetype' => $file->getMimeType(), 'caption' => $fileInfo['caption'], 'in_library' => isset($libFileIds[$file->getId()]), diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index df402e3d5..155ae14c9 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -116,7 +116,6 @@ public function parsePlaylist(string $token, int $fileId) { 'id' => $file->getId(), 'name' => $file->getName(), 'path' => $sharedFolder->getRelativePath($file->getParent()->getPath()), - 'url' => 'TODO', 'mimetype' => $file->getMimeType(), 'caption' => $fileInfo['caption'], 'external' => false