Add Info-Beamer API endpoints and update node.lua for streaming channels
This commit is contained in:
59
server.py
59
server.py
@@ -552,6 +552,65 @@ def init_db():
|
||||
db.session.commit()
|
||||
print("Created default streaming channel")
|
||||
|
||||
# API Endpoints for Info-Beamer Integration
|
||||
@app.route('/api/player/<device_id>/content')
|
||||
def api_player_content(device_id):
|
||||
"""Get content for a specific player"""
|
||||
player = Player.query.filter_by(device_id=device_id).first()
|
||||
if not player:
|
||||
return jsonify({'error': 'Player not found'}), 404
|
||||
|
||||
if not player.channel_id:
|
||||
return jsonify({'content': []})
|
||||
|
||||
# Get content from the player's assigned channel
|
||||
channel_content = ChannelContent.query.filter_by(channel_id=player.channel_id).order_by(ChannelContent.order).all()
|
||||
|
||||
content_list = []
|
||||
for content in channel_content:
|
||||
media_file = MediaFile.query.get(content.media_file_id)
|
||||
if media_file:
|
||||
content_list.append({
|
||||
'filename': media_file.filename,
|
||||
'type': 'image' if media_file.file_type.startswith('image/') else 'video',
|
||||
'duration': content.duration or 10,
|
||||
'order': content.order
|
||||
})
|
||||
|
||||
return jsonify({'content': content_list})
|
||||
|
||||
@app.route('/api/player/<device_id>/channel')
|
||||
def api_player_channel(device_id):
|
||||
"""Get channel information for a specific player"""
|
||||
player = Player.query.filter_by(device_id=device_id).first()
|
||||
if not player:
|
||||
return jsonify({'error': 'Player not found'}), 404
|
||||
|
||||
if not player.channel_id:
|
||||
return jsonify({'name': 'No Channel Assigned', 'description': 'No channel assigned to this player'})
|
||||
|
||||
channel = StreamingChannel.query.get(player.channel_id)
|
||||
if not channel:
|
||||
return jsonify({'error': 'Channel not found'}), 404
|
||||
|
||||
return jsonify({
|
||||
'name': channel.name,
|
||||
'description': channel.description,
|
||||
'is_active': channel.is_active
|
||||
})
|
||||
|
||||
@app.route('/api/player/<device_id>/heartbeat', methods=['POST'])
|
||||
def api_player_heartbeat(device_id):
|
||||
"""Update player last seen timestamp"""
|
||||
player = Player.query.filter_by(device_id=device_id).first()
|
||||
if not player:
|
||||
return jsonify({'error': 'Player not found'}), 404
|
||||
|
||||
player.last_seen = datetime.utcnow()
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({'status': 'ok'})
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_db()
|
||||
app.run(host='0.0.0.0', port=80, debug=True)
|
||||
Reference in New Issue
Block a user