Refactor OAuth provider linking and unlinking logic into a dedicated service; enhance error handling and logging throughout the application; improve sound management and scanning services with better file handling and unique naming; implement centralized error and logging services for consistent API responses and application-wide logging configuration.

This commit is contained in:
JSC
2025-07-05 13:07:06 +02:00
parent 41fc197f4c
commit e2fe451e5a
17 changed files with 758 additions and 352 deletions

View File

@@ -37,7 +37,7 @@ def get_sounds():
"sounds": sounds_data,
"total": len(sounds_data),
"type": sound_type,
}
},
)
except Exception as e:
return jsonify({"error": str(e)}), 500
@@ -60,11 +60,10 @@ def play_sound(sound_id: int):
if success:
return jsonify({"message": "Sound playing", "sound_id": sound_id})
else:
return (
jsonify({"error": "Sound not found or cannot be played"}),
404,
)
return (
jsonify({"error": "Sound not found or cannot be played"}),
404,
)
except Exception as e:
return jsonify({"error": str(e)}), 500
@@ -89,7 +88,7 @@ def stop_all_sounds():
{
"message": f"Force stopped {stopped_count} sounds",
"forced": True,
}
},
)
return jsonify({"message": "All sounds stopped"})
@@ -107,7 +106,7 @@ def force_stop_all_sounds():
{
"message": f"Force stopped {stopped_count} sound instances",
"stopped_count": stopped_count,
}
},
)
except Exception as e:
return jsonify({"error": str(e)}), 500
@@ -129,7 +128,7 @@ def get_status():
"id": process_id,
"pid": process.pid,
"running": process.poll() is None,
}
},
)
return jsonify(
@@ -137,7 +136,7 @@ def get_status():
"playing_count": playing_count,
"is_playing": playing_count > 0,
"processes": processes,
}
},
)
except Exception as e:
return jsonify({"error": str(e)}), 500
@@ -153,7 +152,8 @@ def get_play_history():
offset = (page - 1) * per_page
recent_plays = SoundPlayed.get_recent_plays(
limit=per_page, offset=offset
limit=per_page,
offset=offset,
)
return jsonify(
@@ -161,7 +161,7 @@ def get_play_history():
"plays": [play.to_dict() for play in recent_plays],
"page": page,
"per_page": per_page,
}
},
)
except Exception as e:
return jsonify({"error": str(e)}), 500
@@ -182,7 +182,9 @@ def get_my_play_history():
offset = (page - 1) * per_page
user_plays = SoundPlayed.get_user_plays(
user_id=user_id, limit=per_page, offset=offset
user_id=user_id,
limit=per_page,
offset=offset,
)
return jsonify(
@@ -191,7 +193,7 @@ def get_my_play_history():
"page": page,
"per_page": per_page,
"user_id": user_id,
}
},
)
except Exception as e:
return jsonify({"error": str(e)}), 500
@@ -230,7 +232,7 @@ def get_popular_sounds():
"popular_sounds": popular_sounds,
"limit": limit,
"days": days,
}
},
)
except Exception as e:
return jsonify({"error": str(e)}), 500