koel/app/Http/Controllers/API/ObjectStorage/S3/SongController.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2016-06-13 09:04:42 +00:00
<?php
namespace App\Http\Controllers\API\ObjectStorage\S3;
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;
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
{
private S3Service $s3Service;
2018-08-19 09:05:33 +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)
{
$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)
{
try {
$this->s3Service->deleteSongEntry($request->bucket, $request->key);
} catch (SongPathNotFoundException $exception) {
abort(Response::HTTP_NOT_FOUND);
}
2016-06-13 09:04:42 +00:00
return response()->noContent();
2016-06-13 09:04:42 +00:00
}
}