feat: Add redirection to Haiku page and save in DB

Refs: OPS-22
This commit is contained in:
Alivecow 2025-02-28 22:00:52 +01:00
parent 7e5d61663a
commit 6c698d1528
2 changed files with 7 additions and 4 deletions

View file

@ -56,4 +56,5 @@ def generate_haiku():
json_data = request.get_json() json_data = request.get_json()
prompt = json_data["prompt"] prompt = json_data["prompt"]
haiku = request_haiku(prompt) haiku = request_haiku(prompt)
return haiku.get_json() id = store.save_haiku(haiku)
return str(id)

View file

@ -57,10 +57,12 @@ document.getElementById("submit-btn").addEventListener("click", function() {
}, },
body: JSON.stringify({'prompt': userInput}) body: JSON.stringify({'prompt': userInput})
}) })
.then(response => response.json()) .then(response => response.text())
.then(data => { .then(data => {
console.log(data); console.log(data);
responseText.innerHTML = data[0] + "<br>" + data[1] + "<br>" + data[2]; //responseText.innerHTML = data[0] + "<br>" + data[1] + "<br>" + data[2];
let id = parseInt(data, 10);
window.location.replace("/haiku/"+id);
}) })
.catch(error => { .catch(error => {
document.getElementById('result').innerHTML = '<strong>Error:</strong> ' + error.message; document.getElementById('result').innerHTML = '<strong>Error:</strong> ' + error.message;