koel/app/Http/Controllers/API/LambdaSongController.php

50 lines
1.4 KiB
PHP
Raw Normal View History

2016-06-13 09:04:42 +00:00
<?php
2024-02-05 22:47:13 +00:00
namespace App\Http\Controllers\API;
2016-06-13 09:04:42 +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;
use App\Services\SongStorages\S3LambdaStorage;
2020-09-13 22:04:07 +00:00
use Illuminate\Http\Response;
2024-01-18 11:13:05 +00:00
use Illuminate\Support\Arr;
2016-06-13 09:04:42 +00:00
2024-02-05 22:47:13 +00:00
class LambdaSongController extends Controller
2016-06-13 09:04:42 +00:00
{
2024-04-18 14:36:28 +00:00
public function __construct(private readonly S3LambdaStorage $storage)
{
2018-08-19 09:05:33 +00:00
}
2016-06-13 09:04:42 +00:00
public function put(PutSongRequest $request)
{
2024-01-18 11:13:05 +00:00
$artist = Arr::get($request->tags, 'artist', '');
2022-08-02 09:33:24 +00:00
2024-02-05 22:47:13 +00:00
$song = $this->storage->createSongEntry(
$request->bucket,
$request->key,
$artist,
2024-01-18 11:13:05 +00:00
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', '')
);
2016-06-13 09:04:42 +00:00
return response()->json($song);
}
public function remove(RemoveSongRequest $request)
{
try {
2024-02-05 22:47:13 +00:00
$this->storage->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
}
}