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;
|
2022-07-29 06:47:10 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
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
|
|
|
|
{
|
2022-07-29 06:47:10 +00:00
|
|
|
public function __construct(private S3Service $s3Service)
|
2021-12-06 16:12:47 +00:00
|
|
|
{
|
2018-08-19 09:05:33 +00:00
|
|
|
}
|
|
|
|
|
2016-06-13 09:04:42 +00:00
|
|
|
public function put(PutSongRequest $request)
|
|
|
|
{
|
2022-04-13 13:59:37 +00:00
|
|
|
$artist = array_get($request->tags, 'artist', '');
|
2022-08-02 09:33:24 +00:00
|
|
|
|
2021-12-06 16:12:47 +00:00
|
|
|
$song = $this->s3Service->createSongEntry(
|
|
|
|
$request->bucket,
|
|
|
|
$request->key,
|
2022-04-13 13:59:37 +00:00
|
|
|
$artist,
|
2021-12-06 16:12:47 +00:00
|
|
|
array_get($request->tags, 'album'),
|
2022-07-07 10:45:47 +00:00
|
|
|
trim(array_get($request->tags, 'albumartist')),
|
2021-12-06 16:12:47 +00:00
|
|
|
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);
|
2022-07-07 10:45:47 +00:00
|
|
|
} catch (SongPathNotFoundException) {
|
2021-12-06 16:12:47 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|