2016-06-13 09:04:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API\ObjectStorage\S3;
|
|
|
|
|
2021-12-06 16:12:47 +00:00
|
|
|
use App\Exceptions\SongPathNotFoundException;
|
2016-06-13 09:04:42 +00:00
|
|
|
use App\Http\Requests\API\ObjectStorage\S3\PutSongRequest;
|
|
|
|
use App\Http\Requests\API\ObjectStorage\S3\RemoveSongRequest;
|
2021-12-06 16:12:47 +00:00
|
|
|
use App\Services\S3Service;
|
2020-09-13 22:04:07 +00:00
|
|
|
use Illuminate\Http\Response;
|
2016-06-13 09:04:42 +00:00
|
|
|
|
|
|
|
class SongController extends Controller
|
|
|
|
{
|
2021-12-06 16:12:47 +00:00
|
|
|
private S3Service $s3Service;
|
2018-08-19 09:05:33 +00:00
|
|
|
|
2021-12-06 16:12:47 +00:00
|
|
|
public function __construct(S3Service $s3Service)
|
|
|
|
{
|
|
|
|
$this->s3Service = $s3Service;
|
2018-08-19 09:05:33 +00:00
|
|
|
}
|
|
|
|
|
2016-06-13 09:04:42 +00:00
|
|
|
public function put(PutSongRequest $request)
|
|
|
|
{
|
2021-12-06 16:12:47 +00:00
|
|
|
$song = $this->s3Service->createSongEntry(
|
|
|
|
$request->bucket,
|
|
|
|
$request->key,
|
|
|
|
array_get($request->tags, 'artist'),
|
|
|
|
array_get($request->tags, 'album'),
|
|
|
|
(bool) trim(array_get($request->tags, 'albumartist')),
|
|
|
|
array_get($request->tags, 'cover'),
|
|
|
|
trim(array_get($request->tags, 'title', '')),
|
|
|
|
(int) array_get($request->tags, 'duration', 0),
|
|
|
|
(int) array_get($request->tags, 'track'),
|
|
|
|
(string) array_get($request->tags, 'lyrics', '')
|
|
|
|
);
|
2016-06-13 09:04:42 +00:00
|
|
|
|
|
|
|
return response()->json($song);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove(RemoveSongRequest $request)
|
|
|
|
{
|
2021-12-06 16:12:47 +00:00
|
|
|
try {
|
|
|
|
$this->s3Service->deleteSongEntry($request->bucket, $request->key);
|
|
|
|
} catch (SongPathNotFoundException $exception) {
|
|
|
|
abort(Response::HTTP_NOT_FOUND);
|
|
|
|
}
|
2016-06-13 09:04:42 +00:00
|
|
|
|
2021-12-06 16:12:47 +00:00
|
|
|
return response()->noContent();
|
2016-06-13 09:04:42 +00:00
|
|
|
}
|
|
|
|
}
|