public function getCachedTrack($id, $format) { // Validation try { $track = Track::findOrFail($id); } catch (ModelNotFoundException $e) { return $this->notFound('Track not found!'); } if (!$track->canView(Auth::user())) { return $this->notFound('Track not found!'); } if ($track->is_downloadable == false) { return $this->notFound('Track not found!'); } if (!in_array($format, Track::$CacheableFormats)) { return $this->notFound('Format not found!'); } try { $trackFile = $track->trackFiles()->where('format', $format)->firstOrFail(); } catch (ModelNotFoundException $e) { return $this->notFound('Track file not found!'); } // Return URL or begin encoding if ($trackFile->expires_at != null && File::exists($trackFile->getFile())) { $url = $track->getUrlFor($format); } elseif ($trackFile->status === TrackFile::STATUS_PROCESSING) { $url = null; } else { $this->dispatch(new EncodeTrackFile($trackFile, true)); $url = null; } return Response::json(['url' => $url], 200); }
public function getUploadStatus($trackId) { $track = Track::findOrFail($trackId); $this->authorize('edit', $track); if ($track->status === Track::STATUS_PROCESSING) { return Response::json(['message' => 'Processing...'], 202); } elseif ($track->status === Track::STATUS_COMPLETE) { return Response::json(['message' => $track->published_at ? 'Processing complete! The track is live at the track_url. The artist can edit the track by visiting its edit_url.' : 'Processing complete! The artist must publish the track by visiting its edit_url.', 'edit_url' => action('ContentController@getTracks', ['id' => $trackId]), 'track_url' => $track->url], 201); } else { // something went wrong return Response::json(['error' => 'Processing failed! Please contact feld0@poniverse.net to figure out what went wrong.'], 500); } }
/** * Execute the console command. * * @return mixed */ public function handle() { if ($this->argument('trackId')) { $track = Track::findOrFail($this->argument('trackId')); $tracks = [$track]; } else { $tracks = Track::whereNotNull('published_at')->withTrashed()->orderBy('id', 'asc')->get(); } $numberOfTracks = sizeof($tracks); $this->info("Updating tags for {$numberOfTracks} tracks..."); $bar = $this->output->createProgressBar($numberOfTracks); foreach ($tracks as $track) { /** @var $track Track */ $track->updateTags(); $bar->advance(); } $bar->finish(); $this->line(''); }