koel/app/Services/Streamers/S3Streamer.php

33 lines
776 B
PHP
Raw Normal View History

2016-06-13 09:04:42 +00:00
<?php
2017-04-20 11:20:32 +00:00
namespace App\Services\Streamers;
2016-06-13 09:04:42 +00:00
2018-08-29 04:06:17 +00:00
use App\Services\S3Service;
2020-12-22 20:11:22 +00:00
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
2018-08-29 04:06:17 +00:00
2018-08-22 17:59:14 +00:00
class S3Streamer extends Streamer implements ObjectStorageStreamerInterface
2016-06-13 09:04:42 +00:00
{
2021-06-05 10:47:56 +00:00
private S3Service $s3Service;
2018-08-29 04:06:17 +00:00
public function __construct(S3Service $s3Service)
{
parent::__construct();
2020-12-22 20:11:22 +00:00
2018-08-29 04:06:17 +00:00
$this->s3Service = $s3Service;
}
2016-06-13 09:04:42 +00:00
/**
* Stream the current song through S3.
2018-08-29 04:06:17 +00:00
* Actually, we just redirect the request to the S3 object's location.
2020-12-22 20:11:22 +00:00
*
* @return Redirector|RedirectResponse
2021-06-05 10:47:56 +00:00
*
2016-06-13 09:04:42 +00:00
*/
2021-06-05 10:47:56 +00:00
public function stream() // @phpcs:ignore
2016-06-13 09:04:42 +00:00
{
// Get and redirect to the actual presigned-url
2018-08-29 04:06:17 +00:00
return redirect($this->s3Service->getSongPublicUrl($this->song));
2016-06-13 09:04:42 +00:00
}
}