diff --git a/LyricsPy/servicios/instance/songs.db b/LyricsPy/servicios/instance/songs.db index 0f774b5..11ab1d8 100644 Binary files a/LyricsPy/servicios/instance/songs.db and b/LyricsPy/servicios/instance/songs.db differ diff --git a/LyricsPy/servicios/lyrics/__init__.py b/LyricsPy/servicios/lyrics/__init__.py index 1ea8216..4016171 100644 --- a/LyricsPy/servicios/lyrics/__init__.py +++ b/LyricsPy/servicios/lyrics/__init__.py @@ -11,6 +11,8 @@ def create_app(): app.config['SECRET_KEY'] = 'secret-key-goes-here' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///songs.db' + app.config['UPLOAD_FOLDER'] = 'lyrics/static/uploads' + app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB máximo from .models import db diff --git a/LyricsPy/servicios/lyrics/models.py b/LyricsPy/servicios/lyrics/models.py index 0d91888..1f5f411 100644 --- a/LyricsPy/servicios/lyrics/models.py +++ b/LyricsPy/servicios/lyrics/models.py @@ -7,6 +7,7 @@ class Album(db.Model): name = db.Column(db.String(100), nullable=False) artist = db.Column(db.String(100), nullable=False) year = db.Column(db.Integer, nullable=False) + cover_image = db.Column(db.String(100), nullable=True) songs = db.relationship('Song', backref='album', lazy=True) def __repr__(self): @@ -18,7 +19,7 @@ class Song(db.Model): author = db.Column(db.String(100), nullable=False) album_id = db.Column(db.Integer, db.ForeignKey('album.id'), nullable=False) lyrics = db.Column(db.Text, nullable=False) - pista = db.Column(db.Integer, nullable=False) # Nuevo campo + pista = db.Column(db.Integer, nullable=False) def __repr__(self): diff --git a/LyricsPy/servicios/lyrics/paginas.py b/LyricsPy/servicios/lyrics/paginas.py index 56fc964..fe4b53f 100644 --- a/LyricsPy/servicios/lyrics/paginas.py +++ b/LyricsPy/servicios/lyrics/paginas.py @@ -1,4 +1,7 @@ -from flask import Blueprint, render_template, request, redirect, url_for +from flask import Blueprint, render_template, request, redirect, url_for, current_app +from werkzeug.utils import secure_filename +import os + from .models import db, Song, Album bp = Blueprint("paginas", __name__) @@ -36,11 +39,29 @@ def add_song(): @bp.route('/add_album', methods=['GET', 'POST']) def add_album(): if request.method == 'POST': + name = request.form['name'] artist = request.form['artist'] year = request.form['year'] - new_album = Album(name=name, artist=artist, year=year) + # Verificar que el campo 'cover_image' está en request.files + if 'coverimage' not in request.files: + return "No file part in the request", 400 + + cover_image = request.files['coverimage'] + + # Verificar que se ha seleccionado un archivo + + if cover_image.filename == '': + return "No selected file", 400 + + if cover_image: + image_filename = secure_filename(cover_image.filename) + cover_image.save(os.path.join(current_app.config['UPLOAD_FOLDER'], image_filename)) + else: + image_filename = None + + new_album = Album(name=name, artist=artist, year=year, cover_image=image_filename) db.session.add(new_album) db.session.commit() diff --git a/LyricsPy/servicios/lyrics/static/uploads/theriver.jpg b/LyricsPy/servicios/lyrics/static/uploads/theriver.jpg new file mode 100644 index 0000000..3caa7cd Binary files /dev/null and b/LyricsPy/servicios/lyrics/static/uploads/theriver.jpg differ diff --git a/LyricsPy/servicios/lyrics/templates/add_album.html b/LyricsPy/servicios/lyrics/templates/add_album.html index 4b036ae..dbef7a9 100644 --- a/LyricsPy/servicios/lyrics/templates/add_album.html +++ b/LyricsPy/servicios/lyrics/templates/add_album.html @@ -2,7 +2,7 @@ {% block content %}
Artista: {{ album.artist }}
Año: {{ album.year }}
- +{% if album.cover_image %} +No hay imágen disponible
+{% endif %}