mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
chore: cleanups
This commit is contained in:
parent
fd25a58deb
commit
36b808c067
16 changed files with 25 additions and 125 deletions
|
@ -1006,7 +1006,7 @@ paths:
|
|||
- last.fm
|
||||
responses: {}
|
||||
operationId: get-lastfm-connect
|
||||
description: 'Connect the current user to Last.fm. This is NOT an XmlHttpRequest. The application should instead redirect the current user to this route, which will send them to Last.fm for authentication. After authentication is successful, the user will be redirected back to `/lastfm/callback?token=<Last.fm token>`.'
|
||||
description: '[Connect](https://www.last.fm/api/authentication) the current user to Last.fm. This is actually NOT an API request. The application should instead redirect the current user to this route, which will send them to Last.fm for authentication. After authentication is successful, the user will be redirected back to `/lastfm/callback?token=<Last.fm token>`.'
|
||||
security:
|
||||
- api-token: []
|
||||
'/play/{songId}/{transcode}/{bitrate}':
|
||||
|
|
|
@ -8,9 +8,6 @@ use App\Models\Album;
|
|||
use App\Services\MediaMetadataService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* @group 5. Media information
|
||||
*/
|
||||
class AlbumCoverController extends Controller
|
||||
{
|
||||
private $mediaMetadataService;
|
||||
|
@ -20,17 +17,6 @@ class AlbumCoverController extends Controller
|
|||
$this->mediaMetadataService = $mediaMetadataService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload an album's cover
|
||||
*
|
||||
* Upload an image as an album's cover.
|
||||
*
|
||||
* @bodyParam cover string required The cover image's content, in <a href="https://en.wikipedia.org/wiki/Data_URI_scheme">Data URI format</a>.
|
||||
* Example: data:image/jpeg;base64,Rm9v
|
||||
* @responseFile responses/albumCover.update.json
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(AlbumCoverUpdateRequest $request, Album $album)
|
||||
{
|
||||
$this->mediaMetadataService->writeAlbumCover(
|
||||
|
|
|
@ -6,9 +6,6 @@ use App\Models\Album;
|
|||
use App\Services\MediaMetadataService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* @group 5. Media information
|
||||
*/
|
||||
class AlbumThumbnailController extends Controller
|
||||
{
|
||||
private $mediaMetadataService;
|
||||
|
@ -18,14 +15,6 @@ class AlbumThumbnailController extends Controller
|
|||
$this->mediaMetadataService = $mediaMetadataService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an album's thumbnail
|
||||
*
|
||||
* Get an album's thumbnail (a 48px-wide blurry version of the album's cover).
|
||||
* Returns the full URL to the thumbnail or NULL if the album has no cover.
|
||||
*
|
||||
* @response ["thumbnailUrl", "https://localhost/img/covers/a146d01afb742b01f28ab8b556f9a75d_thumbnail.jpg"]
|
||||
*/
|
||||
public function get(Album $album): JsonResponse
|
||||
{
|
||||
return response()->json(['thumbnailUrl' => $this->mediaMetadataService->getAlbumThumbnailUrl($album)]);
|
||||
|
|
|
@ -8,9 +8,6 @@ use App\Models\Artist;
|
|||
use App\Services\MediaMetadataService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* @group 5. Media information
|
||||
*/
|
||||
class ArtistImageController extends Controller
|
||||
{
|
||||
private $mediaMetadataService;
|
||||
|
@ -20,17 +17,6 @@ class ArtistImageController extends Controller
|
|||
$this->mediaMetadataService = $mediaMetadataService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload an artist's image
|
||||
*
|
||||
* Upload an image as an artist's image.
|
||||
*
|
||||
* @bodyParam image string required The image's content, in <a href="https://en.wikipedia.org/wiki/Data_URI_scheme">Data URI format</a>.
|
||||
* Example: data:image/jpeg;base64,Rm9v
|
||||
* @responseFile responses/artistImage.update.json
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(ArtistImageUpdateRequest $request, Artist $artist)
|
||||
{
|
||||
$this->mediaMetadataService->writeArtistImage(
|
||||
|
|
|
@ -9,14 +9,14 @@ class BatchLikeController extends Controller
|
|||
{
|
||||
public function store(BatchInteractionRequest $request)
|
||||
{
|
||||
$interactions = $this->interactionService->batchLike((array) $request->songs, $request->user());
|
||||
$interactions = $this->interactionService->batchLike((array) $request->songs, $this->currentUser);
|
||||
|
||||
return response()->json($interactions);
|
||||
}
|
||||
|
||||
public function destroy(BatchInteractionRequest $request)
|
||||
{
|
||||
$this->interactionService->batchUnlike((array) $request->songs, $request->user());
|
||||
$this->interactionService->batchUnlike((array) $request->songs, $this->currentUser);
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
|
|
@ -3,14 +3,20 @@
|
|||
namespace App\Http\Controllers\API\Interaction;
|
||||
|
||||
use App\Http\Controllers\Controller as BaseController;
|
||||
use App\Models\User;
|
||||
use App\Services\InteractionService;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
protected $interactionService;
|
||||
|
||||
public function __construct(InteractionService $interactionService)
|
||||
/** @var User */
|
||||
protected $currentUser;
|
||||
|
||||
public function __construct(InteractionService $interactionService, ?Authenticatable $currentUser)
|
||||
{
|
||||
$this->interactionService = $interactionService;
|
||||
$this->currentUser = $currentUser;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ class LikeController extends Controller
|
|||
{
|
||||
public function store(SongLikeRequest $request)
|
||||
{
|
||||
return response()->json($this->interactionService->toggleLike($request->song, $request->user()));
|
||||
return response()->json($this->interactionService->toggleLike($request->song, $this->currentUser));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ class PlayCountController extends Controller
|
|||
{
|
||||
public function store(StorePlayCountRequest $request)
|
||||
{
|
||||
$interaction = $this->interactionService->increasePlayCount($request->song, $request->user());
|
||||
$interaction = $this->interactionService->increasePlayCount($request->song, $this->currentUser);
|
||||
event(new SongStartedPlaying($interaction->song, $interaction->user));
|
||||
|
||||
return response()->json($interaction);
|
||||
|
|
|
@ -4,20 +4,23 @@ namespace App\Http\Controllers\API\Interaction;
|
|||
|
||||
use App\Repositories\InteractionRepository;
|
||||
use App\Services\InteractionService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
class RecentlyPlayedController extends Controller
|
||||
{
|
||||
private $interactionRepository;
|
||||
|
||||
public function __construct(InteractionService $interactionService, InteractionRepository $interactionRepository)
|
||||
{
|
||||
parent::__construct($interactionService);
|
||||
public function __construct(
|
||||
InteractionService $interactionService,
|
||||
InteractionRepository $interactionRepository,
|
||||
?Authenticatable $currentUser
|
||||
) {
|
||||
parent::__construct($interactionService, $currentUser);
|
||||
$this->interactionRepository = $interactionRepository;
|
||||
}
|
||||
|
||||
public function index(Request $request, ?int $count = null)
|
||||
public function index(?int $count = null)
|
||||
{
|
||||
return response()->json($this->interactionRepository->getRecentlyPlayed($request->user(), $count));
|
||||
return response()->json($this->interactionRepository->getRecentlyPlayed($this->currentUser, $count));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,7 @@ use App\Models\Playlist;
|
|||
use App\Models\User;
|
||||
use App\Repositories\PlaylistRepository;
|
||||
use App\Services\SmartPlaylistService;
|
||||
use Exception;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PlaylistController extends Controller
|
||||
|
@ -87,16 +84,6 @@ class PlaylistController extends Controller
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a playlist
|
||||
*
|
||||
* @response []
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws AuthorizationException
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function destroy(Playlist $playlist)
|
||||
{
|
||||
$this->authorize('owner', $playlist);
|
||||
|
|
|
@ -8,6 +8,7 @@ use App\Exceptions\SongUploadFailedException;
|
|||
use App\Http\Requests\API\UploadRequest;
|
||||
use App\Services\UploadService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class UploadController extends Controller
|
||||
{
|
||||
|
@ -23,9 +24,9 @@ class UploadController extends Controller
|
|||
try {
|
||||
$song = $this->uploadService->handleUploadedFile($request->file);
|
||||
} catch (MediaPathNotSetException $e) {
|
||||
abort(403, $e->getMessage());
|
||||
abort(Response::HTTP_FORBIDDEN, $e->getMessage());
|
||||
} catch (SongUploadFailedException $e) {
|
||||
abort(400, $e->getMessage());
|
||||
abort(Response::HTTP_BAD_REQUEST, $e->getMessage());
|
||||
}
|
||||
|
||||
event(new MediaCacheObsolete());
|
||||
|
|
|
@ -4,16 +4,8 @@ namespace App\Http\Controllers\Download;
|
|||
|
||||
use App\Models\Album;
|
||||
|
||||
/**
|
||||
* @group 6. Download
|
||||
*/
|
||||
class AlbumController extends Controller
|
||||
{
|
||||
/**
|
||||
* Download a whole album
|
||||
*
|
||||
* @response []
|
||||
*/
|
||||
public function show(Album $album)
|
||||
{
|
||||
return response()->download($this->downloadService->from($album));
|
||||
|
|
|
@ -4,19 +4,8 @@ namespace App\Http\Controllers\Download;
|
|||
|
||||
use App\Models\Artist;
|
||||
|
||||
/**
|
||||
* @group 6. Download
|
||||
*/
|
||||
class ArtistController extends Controller
|
||||
{
|
||||
/**
|
||||
* Download all songs by an artist
|
||||
*
|
||||
* Don't see why one would need this, really.
|
||||
* Let's pray to God the user doesn't trigger this on Elvis.
|
||||
*
|
||||
* @response []
|
||||
*/
|
||||
public function show(Artist $artist)
|
||||
{
|
||||
return response()->download($this->downloadService->from($artist));
|
||||
|
|
|
@ -6,9 +6,6 @@ use App\Http\Requests\Download\Request;
|
|||
use App\Repositories\InteractionRepository;
|
||||
use App\Services\DownloadService;
|
||||
|
||||
/**
|
||||
* @group 6. Download
|
||||
*/
|
||||
class FavoritesController extends Controller
|
||||
{
|
||||
private $interactionRepository;
|
||||
|
@ -19,11 +16,6 @@ class FavoritesController extends Controller
|
|||
$this->interactionRepository = $interactionRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download all songs favorite'd by the current user
|
||||
*
|
||||
* @response []
|
||||
*/
|
||||
public function show(Request $request)
|
||||
{
|
||||
$songs = $this->interactionRepository->getUserFavorites($request->user());
|
||||
|
|
|
@ -3,20 +3,9 @@
|
|||
namespace App\Http\Controllers\Download;
|
||||
|
||||
use App\Models\Playlist;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
|
||||
/**
|
||||
* @group 6. Download
|
||||
*/
|
||||
class PlaylistController extends Controller
|
||||
{
|
||||
/**
|
||||
* Download a whole playlist
|
||||
*
|
||||
* @response []
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function show(Playlist $playlist)
|
||||
{
|
||||
$this->authorize('owner', $playlist);
|
||||
|
|
|
@ -7,12 +7,8 @@ use App\Models\User;
|
|||
use App\Services\LastfmService;
|
||||
use App\Services\TokenManager;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
/**
|
||||
* @group 9. Last.fm integration
|
||||
*/
|
||||
class LastfmController extends Controller
|
||||
{
|
||||
private $lastfmService;
|
||||
|
@ -28,19 +24,6 @@ class LastfmController extends Controller
|
|||
$this->currentUser = $currentUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to Last.fm
|
||||
*
|
||||
* [Connect](https://www.last.fm/api/authentication) the current user to Last.fm.
|
||||
* This is actually NOT an API request. The application should instead redirect the current user to this route,
|
||||
* which will send them to Last.fm for authentication. After authentication is successful, the user will be
|
||||
* redirected back to `lastfm/callback?token=<Last.fm token>`.
|
||||
*
|
||||
* @queryParam api_token required Authentication token of the current user.
|
||||
* @response []
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function connect()
|
||||
{
|
||||
abort_unless(
|
||||
|
@ -52,7 +35,7 @@ class LastfmController extends Controller
|
|||
$callbackUrl = urlencode(sprintf(
|
||||
'%s?api_token=%s',
|
||||
route('lastfm.callback'),
|
||||
// for enhanced security, create a temporary token that can be deleted later
|
||||
// create a temporary token that can be deleted later
|
||||
$this->tokenManager->createToken($this->currentUser)->plainTextToken
|
||||
));
|
||||
|
||||
|
@ -61,9 +44,6 @@ class LastfmController extends Controller
|
|||
return redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serve the callback request from Last.fm.
|
||||
*/
|
||||
public function callback(LastfmCallbackRequest $request)
|
||||
{
|
||||
$sessionKey = $this->lastfmService->getSessionKey($request->token);
|
||||
|
|
Loading…
Reference in a new issue