mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-03-29 22:37:46 +01:00
T125: Properly 404 on a nonexistent TrackFile.
This commit is contained in:
parent
3a9a659257
commit
adbb894873
1 changed files with 16 additions and 1 deletions
|
@ -12,6 +12,15 @@ class TrackFile extends \Eloquent {
|
||||||
return $this->belongsTo('Entities\Track');
|
return $this->belongsTo('Entities\Track');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Look up and return a TrackFile by track ID and an extension.
|
||||||
|
*
|
||||||
|
* If the track does not have a TrackFile in the given extension's format, a 404 exception is thrown.
|
||||||
|
*
|
||||||
|
* @param int $trackId
|
||||||
|
* @param string $extension
|
||||||
|
* @return TrackFile
|
||||||
|
*/
|
||||||
public static function findOrFailByExtension($trackId, $extension) {
|
public static function findOrFailByExtension($trackId, $extension) {
|
||||||
// find the extension's format
|
// find the extension's format
|
||||||
$requestedFormatName = null;
|
$requestedFormatName = null;
|
||||||
|
@ -25,11 +34,17 @@ class TrackFile extends \Eloquent {
|
||||||
App::abort(404);
|
App::abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::
|
$trackFile = static::
|
||||||
with('track')
|
with('track')
|
||||||
->where('track_id', $trackId)
|
->where('track_id', $trackId)
|
||||||
->where('format', $requestedFormatName)
|
->where('format', $requestedFormatName)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
if ($trackFile === null) {
|
||||||
|
App::abort(404);
|
||||||
|
} else {
|
||||||
|
return $trackFile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormatAttribute($value) {
|
public function getFormatAttribute($value) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue