Pony.fm/app/controllers/TracksController.php

75 lines
2 KiB
PHP
Raw Normal View History

2013-07-25 23:33:04 +02:00
<?php
2013-08-19 05:39:29 +02:00
use Entities\ResourceLogItem;
2013-07-27 02:15:07 +02:00
use Entities\Track;
use Illuminate\Support\Facades\App;
2013-07-25 23:33:04 +02:00
class TracksController extends Controller {
public function getIndex() {
return View::make('tracks.index');
}
public function getTrack($id, $slug) {
$track = Track::find($id);
if (!$track || !$track->canView(Auth::user()))
App::abort(404);
if ($track->slug != $slug)
return Redirect::action('TracksController@getTrack', [$id, $track->slug]);
return View::make('tracks.show');
}
public function getShortlink($id) {
$track = Track::find($id);
if (!$track || !$track->canView(Auth::user()))
App::abort(404);
return Redirect::action('TracksController@getTrack', [$id, $track->slug]);
}
2013-08-01 10:57:08 +02:00
public function getStream($id) {
$track = Track::find($id);
if (!$track || !$track->canView(Auth::user()))
App::abort(404);
$format = Track::$Formats['MP3'];
2013-08-19 05:39:29 +02:00
ResourceLogItem::logItem('track', $id, ResourceLogItem::PLAY, $format['index']);
2013-08-01 10:57:08 +02:00
$response = Response::make('', 200);
$response->header('X-Sendfile', $track->getFileFor('MP3'));
2013-08-19 05:39:29 +02:00
$response->header('Content-Disposition', 'filename="' . $track->getFilenameFor('MP3') . '"');
$response->header('Content-Type', $format['mime_type']);
return $response;
}
public function getDownload($id, $extension) {
$track = Track::find($id);
if (!$track || !$track->canView(Auth::user()))
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('track', $id, ResourceLogItem::DOWNLOAD, $format['index']);
$response = Response::make('', 200);
$response->header('X-Sendfile', $track->getFileFor($formatName));
$response->header('Content-Disposition', 'attachment; filename="' . $track->getDownloadFilenameFor($formatName) . '"');
2013-08-01 10:57:08 +02:00
$response->header('Content-Type', $format['mime_type']);
return $response;
}
2013-07-25 23:33:04 +02:00
}