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;
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;
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)
{
2018-08-19 09:05:33 +00:00
}
2016-06-13 09:04:42 +00:00
public function put(PutSongRequest $request)
{
$artist = array_get($request->tags, 'artist', '');
2022-08-02 09:33:24 +00:00
$song = $this->s3Service->createSongEntry(
$request->bucket,
$request->key,
$artist,
array_get($request->tags, 'album'),
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) {
abort(Response::HTTP_NOT_FOUND);
}
2016-06-13 09:04:42 +00:00
return response()->noContent();
2016-06-13 09:04:42 +00:00
}
}