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

@ -55,5 +55,6 @@ def generate_haiku():
if request.method == 'POST':
json_data = request.get_json()
prompt = json_data["prompt"]
haiku = request_haiku(prompt)
return haiku.get_json()
haiku = request_haiku(prompt)
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})
})
.then(response => response.json())
.then(response => response.text())
.then(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 => {
document.getElementById('result').innerHTML = '<strong>Error:</strong> ' + error.message;