paulijar / music

:notes: My personal sandbox for ownCloud Music development. All production-quality code is eventually pushed to https://github.com/owncloud/music
GNU Affero General Public License v3.0
0 stars 0 forks source link

Exception thrown when attempting file download via REST endpoint #4

Closed Biont closed 6 years ago

Biont commented 6 years ago

Hello. I was just toying around with the rest API, but failed to actually fetch a song for playback

Endpoint used (example): https://nextcloud.com/index.php/apps/music/api/file/63816/download

I get this, when I call the URL in my browser:

  'reqId' => '9wSgJmBYQdAxVLNTDyPd',
  'level' => 3,
  'time' => '2017-11-20T17:18:00+00:00',
  'remoteAddr' => 'XXX.XX.XX.XXX',
  'user' => 'biont',
  'app' => 'index',
  'method' => 'GET',
  'url' => '/index.php/apps/music/api/file/63816/download',
  'message' => 'Exception: {"Exception":"Error","Message":"Call to a member function getSize() on array","Code":0,"Trace":"#0 \\/usr\\/share\\/webapps\\/nextcloud\\/apps\\/music\\/controller\\/apicontroller.php(448): OCA\\\\Music\\\\Http\\\\FileResponse->__construct(Array)\\n#1 [internal function]: OCA\\\\Music\\\\Controller\\\\ApiController->download(\'63816\')\\n#2 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/AppFramework\\/Http\\/Dispatcher.php(160): call_user_func_array(Array, Array)\\n#3 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/AppFramework\\/Http\\/Dispatcher.php(90): OC\\\\AppFramework\\\\Http\\\\Dispatcher->executeController(Object(OCA\\\\Music\\\\Controller\\\\ApiController), \'download\')\\n#4 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/AppFramework\\/App.php(114): OC\\\\AppFramework\\\\Http\\\\Dispatcher->dispatch(Object(OCA\\\\Music\\\\Controller\\\\ApiController), \'download\')\\n#5 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/AppFramework\\/Routing\\/RouteActionHandler.php(47): OC\\\\AppFramework\\\\App::main(\'ApiController\', \'download\', Object(OC\\\\AppFramework\\\\DependencyInjection\\\\DIContainer), Array)\\n#6 [internal function]: OC\\\\AppFramework\\\\Routing\\\\RouteActionHandler->__invoke(Array)\\n#7 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/Route\\/Router.php(299): call_user_func(Object(OC\\\\AppFramework\\\\Routing\\\\RouteActionHandler), Array)\\n#8 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/base.php(1004): OC\\\\Route\\\\Router->match(\'\\/apps\\/music\\/api...\')\\n#9 \\/usr\\/share\\/webapps\\/nextcloud\\/index.php(48): OC::handleRequest()\\n#10 {main}","File":"\\/usr\\/share\\/webapps\\/nextcloud\\/apps\\/music\\/http\\/fileresponse.php","Line":42}',
  'userAgent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
  'version' => '12.0.3.3',
)

..and this when I use my dummy Android App:

array (
  'reqId' => 'EJYeitakByyXs0B3Lt8x',
  'level' => 3,
  'time' => '2017-11-20T17:42:04+00:00',
  'remoteAddr' => '178.24.76.122',
  'user' => '--',
  'app' => 'index',
  'method' => 'GET',
  'url' => '//index.php/apps/music/api/file/63816/download',
  'message' => 'Exception: {"Exception":"TypeError","Message":"Argument 12 passed to OCA\\\\Music\\\\Controller\\\\ApiController::__construct() must implement interface OCP\\\\Files\\\\Folder, null given, called in \\/usr\\/share\\/webapps\\/nextcloud\\/apps\\/music\\/app\\/music.php on line 95","Code":0,"Trace":"#0 \\/usr\\/share\\/webapps\\/nextcloud\\/apps\\/music\\/app\\/music.php(95): OCA\\\\Music\\\\Controller\\\\ApiController->__construct(\'music\', Object(OC\\\\AppFramework\\\\Http\\\\Request), Object(OC\\\\URLGenerator), Object(OCA\\\\Music\\\\BusinessLayer\\\\TrackBusinessLayer), Object(OCA\\\\Music\\\\BusinessLayer\\\\ArtistBusinessLayer), Object(OCA\\\\Music\\\\BusinessLayer\\\\AlbumBusinessLayer), Object(OCA\\\\Music\\\\Db\\\\Cache), Object(OCA\\\\Music\\\\Utility\\\\Scanner), Object(OCA\\\\Music\\\\Utility\\\\CoverHelper), false, Object(OC\\\\L10N\\\\L10N), NULL, Object(OCA\\\\Music\\\\AppFramework\\\\Core\\\\Logger))\\n#1 \\/usr\\/share\\/webapps\\/nextcloud\\/3rdparty\\/pimple\\/pimple\\/src\\/Pimple\\/Container.php(113): OCA\\\\Music\\\\App\\\\Music->OCA\\\\Music\\\\App\\\\{closure}(Object(OC\\\\AppFramework\\\\DependencyInjection\\\\DIContainer))\\n#2 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/AppFramework\\/Utility\\/SimpleContainer.php(115): Pimple\\\\Container->offsetGet(\'ApiController\')\\n#3 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/AppFramework\\/DependencyInjection\\/DIContainer.php(429): OC\\\\AppFramework\\\\Utility\\\\SimpleContainer->query(\'ApiController\')\\n#4 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/AppFramework\\/DependencyInjection\\/DIContainer.php(414): OC\\\\AppFramework\\\\DependencyInjection\\\\DIContainer->queryNoFallback(\'ApiController\')\\n#5 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/AppFramework\\/App.php(91): OC\\\\AppFramework\\\\DependencyInjection\\\\DIContainer->query(\'ApiController\')\\n#6 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/AppFramework\\/Routing\\/RouteActionHandler.php(47): OC\\\\AppFramework\\\\App::main(\'ApiController\', \'download\', Object(OC\\\\AppFramework\\\\DependencyInjection\\\\DIContainer), Array)\\n#7 [internal function]: OC\\\\AppFramework\\\\Routing\\\\RouteActionHandler->__invoke(Array)\\n#8 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/private\\/Route\\/Router.php(299): call_user_func(Object(OC\\\\AppFramework\\\\Routing\\\\RouteActionHandler), Array)\\n#9 \\/usr\\/share\\/webapps\\/nextcloud\\/lib\\/base.php(1004): OC\\\\Route\\\\Router->match(\'\\/apps\\/music\\/api...\')\\n#10 \\/usr\\/share\\/webapps\\/nextcloud\\/index.php(48): OC::handleRequest()\\n#11 {main}","File":"\\/usr\\/share\\/webapps\\/nextcloud\\/apps\\/music\\/controller\\/apicontroller.php","Line":65}',
  'userAgent' => 'uamp/1.1 (Linux;Android 7.0) ExoPlayerLib/2.5.0',
  'version' => '12.0.3.3',
)

Do you have an idea what's wrong here? I'm using

The endpoint https://nextcloud.com/index.php/apps/music/api/file/63816 responds just fine, so the file should exist.

(I don't know if this is the right repo given there's so little activity in the issues here. It just felt weird to create the issue on the owncloud repo as a nextcloud user. And it seems the Nextcloud App Store draws its releases from here)

paulijar commented 6 years ago

There seems to be a bug (or actually two) in the endpoint /api/file/{fileid}/download which makes it fail on Chrome. I'll include a fix for this to the next Music app release. The bug does not happen on Firefox, because unlike Chrome, it does not use the "HTTP range request" to download the file, and the bugs were in the parts of code handling the range requests.

The bugs had been introduced more than year ago in commit a1119d297, but they haven't been noticed because the UI of the Music app has not used the endpoint /api/file/{fileid}/download for many years. Instead, it uses the WebDAV API to load the files. The WebDAV URL of a file can be obtained from /api/file/{fileid}/webdav.

The error you see on your dummy Android app is another issue. It basically indicates that there was no logged-in user when the endpoint was called. Technically, the error note states that the "user folder" injected to ApiController was null.

The owncloud/music repo is the official channel to report issues on the Music app. I have been making releases for ownCloud and Nextcloud from the exactly same sources and it would be pointless to maintain the application in more than one repositories. This fork paulijar/music is just my personal sandbox which I may use e.g. to prototype changes which I'm not ready to make public yet.

Biont commented 6 years ago

Hey thank you for your reply.

I actually did suspect missing authentication to be the cause, but after seeing that it did not work in the browser as well, I figured we had a bug here. What a coincidence, having two separate problems in the same spot. I have now implemented authentication and was able to proceed to the next problem (within the android app), so that is settled.

The endpoint indeed works in Firefox, looking forward to the fix for Chrome. Thanks for clearing up my confusion about this repo. I will create new issues over at owncloud/music. See you there :)

paulijar commented 6 years ago

The issue in endpoint /api/file/{fileid}/download with Chrome was fixed with commit be7131edcf which has been released in the Music app v0.5.5.