feat: 🎨 Create beautifull dialog

This commit is contained in:
Louis Gallet 2024-06-29 23:22:04 +02:00
parent 7d507e7c46
commit ce0a9573d9
Signed by: lgallet
GPG Key ID: 84D3DF1528A84511
4 changed files with 38 additions and 6 deletions

6
.idea/jsLibraryMappings.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="file://$PROJECT_DIR$" libraries="{sweetalert2}" />
</component>
</project>

View File

@ -6,5 +6,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="sweetalert2" level="application" />
</component>
</module>

11
main.py
View File

@ -24,17 +24,16 @@ def main_app():
@app.route('/add/<string:trackid>', methods=['GET'])
def add_to_playlist(trackid):
if not os.getenv("n8n_webhook"):
return 'n8n_webhook not set'
if not trackid:
return 'No trackid provided'
return render_template("add.html", response="No n8n webhook provided", comment="Please provide a n8n webhook in the .env file", type="error")
try:
data = requests.get(os.getenv("n8n_webhook") + "/" + trackid)
if data.json()['message'] == 'Workflow was started':
return 'Track added to playlist'
return render_template("add.html", response="Track added to playlist successfully", comment="Enjoy the night \U0001f57a", type="success")
else:
return 'Invalid response from server: {}'.format(data.text)
return render_template("add.html", response='Invalid response from server', comment=data.text, type="error")
except requests.exceptions.RequestException as e:
return 'Request failed: {}'.format(e)
return render_template("add.html", response='Request failed', comment=e, type="error")
if __name__ == '__main__':

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fête de la musique</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
{{ bootstrap.load_css() }}
</head>
<body>
<div>
<div>
<script>
Swal.fire({
title:"{{ response }}",
text: "{{ comment }}",
icon: "{{ type }}",
confirmButtonText: "Add another track",
}).then(function() {
window.location = "/";
})
</script>
</div>
</div>
</body>
</html>