mirror of
https://github.com/koel/koel
synced 2024-12-22 18:43:21 +00:00
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Exceptions\SongPathNotFoundException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\API\ObjectStorage\S3\PutSongRequest;
|
|
use App\Http\Requests\API\ObjectStorage\S3\RemoveSongRequest;
|
|
use App\Services\SongStorage\S3LambdaStorage;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class LambdaSongController extends Controller
|
|
{
|
|
public function __construct(private S3LambdaStorage $storage)
|
|
{
|
|
}
|
|
|
|
public function put(PutSongRequest $request)
|
|
{
|
|
$artist = Arr::get($request->tags, 'artist', '');
|
|
|
|
$song = $this->storage->createSongEntry(
|
|
$request->bucket,
|
|
$request->key,
|
|
$artist,
|
|
Arr::get($request->tags, 'album'),
|
|
trim(Arr::get($request->tags, 'albumartist')),
|
|
Arr::get($request->tags, 'cover'),
|
|
trim(Arr::get($request->tags, 'title', '')),
|
|
(int) Arr::get($request->tags, 'duration', 0),
|
|
(int) Arr::get($request->tags, 'track'),
|
|
(string) Arr::get($request->tags, 'lyrics', '')
|
|
);
|
|
|
|
return response()->json($song);
|
|
}
|
|
|
|
public function remove(RemoveSongRequest $request)
|
|
{
|
|
try {
|
|
$this->storage->deleteSongEntry($request->bucket, $request->key);
|
|
} catch (SongPathNotFoundException) {
|
|
abort(Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
return response()->noContent();
|
|
}
|
|
}
|