mirror of
https://github.com/koel/koel
synced 2024-11-24 13:13:05 +00:00
Finish Favorites download
This commit is contained in:
parent
44e184454c
commit
6d0322f80d
4 changed files with 46 additions and 1 deletions
23
app/Http/Controllers/API/Download/FavoritesController.php
Normal file
23
app/Http/Controllers/API/Download/FavoritesController.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\Download;
|
||||
|
||||
use App\Http\Requests\API\Download\Request;
|
||||
use App\Models\Song;
|
||||
use Download;
|
||||
|
||||
class FavoritesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Download all songs in a playlist.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Playlist $playlist
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public function download(Request $request)
|
||||
{
|
||||
return response()->download(Download::from(Song::getFavorites($request->user())));
|
||||
}
|
||||
}
|
|
@ -58,6 +58,7 @@ Route::group(['prefix' => 'api', 'namespace' => 'API'], function () {
|
|||
Route::get('album/{album}', 'AlbumController@download');
|
||||
Route::get('artist/{artist}', 'ArtistController@download');
|
||||
Route::get('playlist/{playlist}', 'PlaylistController@download');
|
||||
Route::get('favorites', 'FavoritesController@download');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -215,6 +215,27 @@ class Song extends Model
|
|||
return $query->where('path', 'LIKE', "$path%");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all songs favorited by a user.
|
||||
*
|
||||
* @param User $user
|
||||
* @param bool $toArray
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection|Array
|
||||
*/
|
||||
public static function getFavorites(User $user, $toArray = false)
|
||||
{
|
||||
$songs = Interaction::where([
|
||||
'user_id' => $user->id,
|
||||
'liked' => true,
|
||||
])
|
||||
->with('song')
|
||||
->get()
|
||||
->pluck('song');
|
||||
|
||||
return $toArray ? $songs->toArray() : $songs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes the tags extracted from getID3 are HTML entity encoded.
|
||||
* This makes sure they are always sane.
|
||||
|
|
|
@ -7,7 +7,7 @@ use App\Models\Album;
|
|||
use App\Models\Artist;
|
||||
use App\Models\Playlist;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use ZipArchive;
|
||||
|
||||
|
|
Loading…
Reference in a new issue