diff --git a/__pycache__/app.cpython-311.pyc b/__pycache__/app.cpython-311.pyc index 81ae97a..cca1b00 100644 Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ diff --git a/app.py b/app.py index c421cfe..cc34bcc 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ import os -from flask import Flask, render_template, request, redirect, url_for, session, flash +from flask import Flask, render_template, request, redirect, url_for, session, flash, jsonify from flask_sqlalchemy import SQLAlchemy from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required, current_user from flask_bcrypt import Bcrypt @@ -532,6 +532,33 @@ def clean_unused_files(): return redirect(url_for('admin')) +@app.route('/api/playlists', methods=['GET']) +def get_playlist(): + quickconnect_code = request.args.get('quickconnect_code') + if not quickconnect_code: + return jsonify({'error': 'Quick connect code is required'}), 400 + + players = Player.query.all() + player = None + for p in players: + if p.verify_quickconnect_code(quickconnect_code): + player = p + break + + if not player: + return jsonify({'error': 'Invalid quick connect code'}), 404 + + if player.groups: + # If the player is part of a group, get the group's content + group = player.groups[0] # Assuming a player can only be in one group + content = Content.query.filter_by(group_id=group.id).all() + else: + # If the player is not part of a group, get the player's content + content = Content.query.filter_by(player_id=player.id).all() + + playlist = [{'file_name': item.file_name, 'duration': item.duration} for item in content] + return jsonify({'playlist': playlist}) + @app.context_processor def inject_theme(): if current_user.is_authenticated: diff --git a/docker-compose.yml b/docker-compose.yml index 2753521..154632b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,17 +5,17 @@ services: image: digi-server:latest ports: - - "7100:5000" + - "80:5000" environment: - FLASK_APP=app.py - FLASK_RUN_HOST=0.0.0.0 - ADMIN_USER=admin - - ADMIN_PASSWORD=Matei + - ADMIN_PASSWORD=Initial01! - SECRET_KEY=Ma_Duc_Dupa_Merele_Lui_Ana volumes: - .:/app - - /home/ske087/digi-server/db:/app/instance - - /home/ske087/digi-server/static:/app/static/uploads + - /home/pi/Desktop/digi-server/db:/app/instance + - /home/pi/Desktop/digi-server/static:/app/static/uploads # when setting allready exist and data are setted and is performed an update use second line of command - command: sh -c "python clear_db.py && python init_db.py && gunicorn -w 4 -b 0.0.0.0:5000 app:app" - #command: sh -c "python init_db.py && gunicorn -w 4 -b 0.0.0.0:5000 app:app" \ No newline at end of file + #command: sh -c "python clear_db.py && python init_db.py && gunicorn -w 4 -b 0.0.0.0:5000 app:app" + command: sh -c "python init_db.py && gunicorn -w 4 -b 0.0.0.0:5000 app:app" \ No newline at end of file diff --git a/models.py b/models.py index 8565812..05ea8d0 100644 --- a/models.py +++ b/models.py @@ -1,4 +1,7 @@ from app import db +from flask_bcrypt import Bcrypt + +bcrypt = Bcrypt() class Content(db.Model): id = db.Column(db.Integer, primary_key=True) @@ -7,4 +10,14 @@ class Content(db.Model): player_id = db.Column(db.Integer, db.ForeignKey('player.id'), nullable=True) group_id = db.Column(db.Integer, db.ForeignKey('group.id'), nullable=True) +class Player(db.Model): + id = db.Column(db.Integer, primary_key=True) + username = db.Column(db.String(80), unique=True, nullable=False) + hostname = db.Column(db.String(120), unique=True, nullable=False) + password = db.Column(db.String(120), nullable=False) + quickconnect_password = db.Column(db.String(120), nullable=False) + + def verify_quickconnect_code(self, code): + return bcrypt.check_password_hash(self.quickconnect_password, code) + # other models... \ No newline at end of file diff --git a/static/resurse/login_picture.png b/static/resurse/login_picture.png index b8bfa51..37d0fbc 100644 Binary files a/static/resurse/login_picture.png and b/static/resurse/login_picture.png differ diff --git a/static/resurse/logo.png b/static/resurse/logo.png index aeb8795..9c43769 100644 Binary files a/static/resurse/logo.png and b/static/resurse/logo.png differ diff --git a/test_api.py b/test_api.py new file mode 100644 index 0000000..41c5a5b --- /dev/null +++ b/test_api.py @@ -0,0 +1,19 @@ +import requests + +# Replace with the actual server IP address or domain name and quick connect code +server_ip = 'Http://192.168.0.115' +quickconnect_code = 'Initial01!' + +# Construct the URL with the quick connect code as a query parameter +url = f'{server_ip}/api/playlists?quickconnect_code={quickconnect_code}' + +# Make the GET request to the API +response = requests.get(url) + +# Check if the request was successful +if response.status_code == 200: + # Parse the JSON response + playlist = response.json().get('playlist', []) + print('Playlist:', playlist) +else: + print('Failed to retrieve playlist:', response.json()) \ No newline at end of file