Skip to content

Commit

Permalink
Create the play URLs for playlists files within the front-end on NC28
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paulijar committed Jan 7, 2024
1 parent 93b0d2e commit 265c0c4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
8 changes: 5 additions & 3 deletions js/embedded/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));

Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion lib/Controller/PlaylistApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]),
Expand Down
1 change: 0 additions & 1 deletion lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 265c0c4

Please # to comment.