mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-03-17 17:00:01 +01:00
T125: Refactored track downloads with TrackFile::findOrFailByExtension().
This commit is contained in:
parent
9ade037820
commit
3a9a659257
2 changed files with 24 additions and 24 deletions
|
@ -72,18 +72,7 @@
|
||||||
if (!$track || !$track->canView(Auth::user()))
|
if (!$track || !$track->canView(Auth::user()))
|
||||||
App::abort(404);
|
App::abort(404);
|
||||||
|
|
||||||
$trackFile = null;
|
$trackFile = TrackFile::findOrFailByExtension($track->id, $extension);
|
||||||
|
|
||||||
foreach ($track->trackFiles as $file) {
|
|
||||||
if ($file->extension === $extension) {
|
|
||||||
$trackFile = $file;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($trackFile == null)
|
|
||||||
App::abort(404);
|
|
||||||
|
|
||||||
ResourceLogItem::logItem('track', $id, ResourceLogItem::PLAY, $trackFile->getFormat()['index']);
|
ResourceLogItem::logItem('track', $id, ResourceLogItem::PLAY, $trackFile->getFormat()['index']);
|
||||||
|
|
||||||
$response = Response::make('', 200);
|
$response = Response::make('', 200);
|
||||||
|
@ -113,18 +102,7 @@
|
||||||
if (!$track || !$track->canView(Auth::user()))
|
if (!$track || !$track->canView(Auth::user()))
|
||||||
App::abort(404);
|
App::abort(404);
|
||||||
|
|
||||||
$trackFile = null;
|
$trackFile = TrackFile::findOrFailByExtension($track->id, $extension);
|
||||||
|
|
||||||
foreach ($track->trackFiles as $file) {
|
|
||||||
if ($file->extension === $extension) {
|
|
||||||
$trackFile = $file;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($trackFile == null)
|
|
||||||
App::abort(404);
|
|
||||||
|
|
||||||
ResourceLogItem::logItem('track', $id, ResourceLogItem::DOWNLOAD, $trackFile->getFormat()['index']);
|
ResourceLogItem::logItem('track', $id, ResourceLogItem::DOWNLOAD, $trackFile->getFormat()['index']);
|
||||||
|
|
||||||
$response = Response::make('', 200);
|
$response = Response::make('', 200);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<?php namespace Entities;
|
<?php namespace Entities;
|
||||||
|
|
||||||
|
use Entities\Track;
|
||||||
use Helpers;
|
use Helpers;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\Facades\URL;
|
use Illuminate\Support\Facades\URL;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
@ -10,6 +12,26 @@ class TrackFile extends \Eloquent {
|
||||||
return $this->belongsTo('Entities\Track');
|
return $this->belongsTo('Entities\Track');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function findOrFailByExtension($trackId, $extension) {
|
||||||
|
// find the extension's format
|
||||||
|
$requestedFormatName = null;
|
||||||
|
foreach (Track::$Formats as $name => $format) {
|
||||||
|
if ($extension === $format[ 'extension' ]) {
|
||||||
|
$requestedFormatName = $name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($requestedFormatName === null) {
|
||||||
|
App::abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return static::
|
||||||
|
with('track')
|
||||||
|
->where('track_id', $trackId)
|
||||||
|
->where('format', $requestedFormatName)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
public function getFormatAttribute($value) {
|
public function getFormatAttribute($value) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue