1
Fork 0
mirror of https://github.com/redstrate/Auracite.git synced 2025-05-01 16:37:45 +00:00

Fix the web version for the new API

This commit is contained in:
Joshua Goins 2025-04-30 23:19:34 -04:00
parent 8fe4a36a88
commit c4b27b8a7b
2 changed files with 30 additions and 9 deletions

View file

@ -392,3 +392,12 @@ pub async extern "C" fn archive_character_base64(
.map(|x| BASE64_STANDARD.encode(x))?;
return Ok(format!("data:application/octet-stream;charset=utf-16le;base64,{buf}").into());
}
#[cfg(target_family = "wasm")]
#[wasm_bindgen]
pub async extern "C" fn search_for_character(name: &str) -> Option<u64> {
#[cfg(feature = "debug")]
console_error_panic_hook::set_once();
search_character(name).await
}

View file

@ -5,19 +5,31 @@
<meta charset="utf-8"/>
<title>Auracite</title>
<script type="module">
import init, {archive_character_base64} from "./pkg/auracite.js";
import init, {archive_character_base64, search_for_character} from "./pkg/auracite.js";
function archive() {
init().then(() => {
archive_character_base64(document.getElementById("name").value, document.getElementById("scales").checked).then((uri) => {
// Download character archive
var link = document.createElement('a');
link.download = document.getElementById("name").value + ".zip";
link.href = uri;
link.click();
document.getElementById("statusMessage").innerText = "Archive complete!";
console.debug("Auracite initialized successfully!");
let name = document.getElementById("name").value;
search_for_character(name).then((id) => {
console.debug("Lodestone id for " + name + ": " + id);
archive_character_base64(id, document.getElementById("scales").checked).then((uri) => {
console.debug("Archive complete!");
// Download character archive
var link = document.createElement('a');
link.download = name + ".zip";
link.href = uri;
link.click();
document.getElementById("statusMessage").innerText = "Archive complete!";
}).catch((err) => {
document.getElementById("statusMessage").innerText = err;
});
}).catch((err) => {
document.getElementById("statusMessage").innerText = err;
document.getElementById("statusMessage").innerText = "No character found!";
});
});
}