Skip to content

Commit

Permalink
Merge pull request #395 from timwangmusic/fix-gen-img-location
Browse files Browse the repository at this point in the history
  • Loading branch information
timwangmusic authored Dec 31, 2024
2 parents 058528d + 959a007 commit b888a55
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions assets/js/search_results.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,29 @@ async function getImageForLocation() {
console.log("calling image generation function...");
const location = getLocation();
const url = `/v1/gen_image`;
let parts = location.split(", ");
const parts = location.split(",").map((str) => str.trim());
if (parts.length < 2 || parts.length > 3) {
console.log("wrong location input format", location);
$("#loadingSpinner").hide();
return;
}

let city = parts[0];
let country = parts[parts.length - 1];
let adminAreaLevelOne = "cities";
if (parts.length == 3) {
adminAreaLevelOne = parts[1];
}

await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
city: parts[0],
adminAreaLevelOne: parts[1],
country: parts[2],
city: city,
adminAreaLevelOne: adminAreaLevelOne,
country: country,
}),
})
.then((response) => response.json())
Expand Down

0 comments on commit b888a55

Please sign in to comment.