Compare commits

...

2 Commits

Author SHA1 Message Date
7c77d0942c añadido soporte para ver los covers 2025-04-04 11:44:00 -03:00
6c81e7a4c5 preliminal soporte carga covers 2025-04-04 11:27:57 -03:00
2 changed files with 22 additions and 0 deletions

View File

@@ -55,10 +55,21 @@ class SongController extends Controller
$validated = $request->validate([
'title' => 'required|string',
'artist' => 'required|string',
'cover' => 'nullable|image|max:2048',
]);
if ($request->hasFile('cover')){
if ($song->cover){
$coverfile = "covers/". $song->cover;
Storage::delete($coverfile);
}
$request->cover->store('covers');
$song->cover = "covers/" . $request->cover->getClientOriginalName();
}
$song->title = $validated['title'];
$song->artist = $validated['artist'];
$song->save();
return response()->json([
@@ -86,6 +97,16 @@ class SongController extends Controller
}
return response()->noContent(200);
}
public function viewcover($id){
$song = Song::find($id);
$this->authorize('view', $song);
if ($song && Storage::exists($song->cover)){
return response()->file(Storage::path($song->cover));
}
abort(404, 'Cover no encontrado');
}
/**
* @param int $id
*/

View File

@@ -31,5 +31,6 @@ Route::get('/canciones/stream/{id}', [SongController::class, 'stream']);
Route::post('/canciones', [SongController::class, 'store']);
Route::put('/canciones/{id}', [SongController::class, 'update']);
Route::delete('/canciones/{id}', [SongController::class, 'destroy'])->middleware(['auth', 'verified']);
Route::get('/canciones/cover/{id}', [SongController::class], 'viewcover')
require __DIR__.'/auth.php';