Example #1
0
 public function getShow($id)
 {
     $playlist = Playlist::with(['tracks.user', 'tracks.genre', 'tracks.cover', 'tracks.album', 'tracks' => function ($query) {
         $query->userDetails();
     }, 'comments', 'comments.user'])->userDetails()->find($id);
     if (!$playlist || !$playlist->canView(Auth::user())) {
         App::abort('404');
     }
     if (Input::get('log')) {
         ResourceLogItem::logItem('playlist', $id, ResourceLogItem::VIEW);
         $playlist->view_count++;
     }
     return Response::json(Playlist::mapPublicPlaylistShow($playlist), 200);
 }
Example #2
0
 public function getShow($id)
 {
     $track = Track::userDetails()->withComments()->find($id);
     if (!$track || !$track->canView(Auth::user())) {
         return $this->notFound('Track not found!');
     }
     if (Input::get('log')) {
         ResourceLogItem::logItem('track', $id, ResourceLogItem::VIEW);
         $track->view_count++;
     }
     $returned_track = Track::mapPublicTrackShow($track);
     if ($returned_track['is_downloadable'] != 1) {
         unset($returned_track['formats']);
     }
     return Response::json(['track' => $returned_track], 200);
 }
Example #3
0
 public function getShow($id)
 {
     $album = Album::with(['tracks' => function ($query) {
         $query->userDetails();
     }, 'tracks.cover', 'tracks.genre', 'tracks.user', 'user', 'comments', 'comments.user'])->userDetails()->find($id);
     if (!$album) {
         App::abort(404);
     }
     if (Input::get('log')) {
         ResourceLogItem::logItem('album', $id, ResourceLogItem::VIEW);
         $album->view_count++;
     }
     $returned_album = Album::mapPublicAlbumShow($album);
     if ($returned_album['is_downloadable'] == 0) {
         unset($returned_album['formats']);
     }
     return Response::json(['album' => $returned_album], 200);
 }
Example #4
0
 public function getDownload($id, $extension)
 {
     $playlist = Playlist::with('tracks', 'user', 'tracks.album')->find($id);
     if (!$playlist || !$playlist->is_public && !Auth::check() || !$playlist->is_public && $playlist->user_id !== Auth::user()->id) {
         App::abort(404);
     }
     $format = null;
     $formatName = null;
     foreach (Track::$Formats as $name => $item) {
         if ($item['extension'] == $extension) {
             $format = $item;
             $formatName = $name;
             break;
         }
     }
     if ($format == null) {
         App::abort(404);
     }
     ResourceLogItem::logItem('playlist', $id, ResourceLogItem::DOWNLOAD, $format['index']);
     $downloader = new PlaylistDownloader($playlist, $formatName);
     $downloader->download();
 }
Example #5
0
 public function getDownload($id, $extension)
 {
     $track = Track::find($id);
     if (!$track || !$track->canView(Auth::user())) {
         App::abort(404);
     }
     $trackFile = TrackFile::findOrFailByExtension($track->id, $extension);
     ResourceLogItem::logItem('track', $id, ResourceLogItem::DOWNLOAD, $trackFile->getFormat()['index']);
     $response = Response::make('', 200);
     $filename = $trackFile->getFile();
     if (Config::get('app.sendfile')) {
         $response->header('X-Sendfile', $filename);
         $response->header('Content-Disposition', 'attachment; filename="' . $trackFile->getDownloadFilename() . '"');
     } else {
         $response->header('X-Accel-Redirect', $filename);
         $response->header('Content-Disposition', 'attachment; filename="' . $trackFile->getDownloadFilename() . '"');
     }
     $time = gmdate(filemtime($filename));
     if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $time == $_SERVER['HTTP_IF_MODIFIED_SINCE']) {
         header('HTTP/1.0 304 Not Modified');
         exit;
     }
     $response->header('Last-Modified', $time);
     $response->header('Content-Type', $trackFile->getFormat()['mime_type']);
     return $response;
 }