Attempt a redirect to the wiki if a relevant page exists

This commit is contained in:
Adam Goldsmith 2020-11-16 15:45:40 -05:00
parent feb9d036b8
commit e70c8f5266
2 changed files with 33 additions and 1 deletions

View File

@ -1,4 +1,4 @@
RewriteEngine on RewriteEngine on
RewriteCond %{HTTP_HOST} ^inv\.claremontmakerspace\.org$ RewriteCond %{HTTP_HOST} ^inv\.claremontmakerspace\.org$
RewriteRule ^(CMS[0-9]{5})$ https://inventory.claremontmakerspace.org/hardware/bytag?assetTag=$1 [R,L] RewriteRule ^(CMS[0-9]{5})$ https://inv.claremontmakerspace.org/index.html?$1 [R,L]
RewriteRule . https://inventory.claremontmakerspace.org/ [R,L] RewriteRule . https://inventory.claremontmakerspace.org/ [R,L]

32
index.html Normal file
View File

@ -0,0 +1,32 @@
<body>
<div id="status">Trying to find the right wiki page...</div>
<script>
const status_div = document.getElementById("status");
const asset_tag = window.location.search.slice(1);
fetch(
`https://wiki.claremontmakerspace.org/api.php?action=ask&query=[[Asset Tag::${asset_tag}]]&format=json&api_version=3&origin=*`
)
.then((r) => r.json())
.then((r) => {
if (r && r.query && r.query.results && r.query.results.length > 0) {
Object.entries(r.query.results[0]).forEach(([name, data]) => {
status_div.innerText = `Redirecting to Wiki Page for "${name}"...`;
window.location.assign(data.fullurl);
});
} else {
throw new Error("No results for query!");
}
})
.catch((e) => {
console.error(e);
status_div.innerText = "Failed to find an appropriate wiki page. ";
const link = status_div.appendChild(document.createElement("a"));
link.href =
"https://inventory.claremontmakerspace.org/hardware/bytag?assetTag=" +
asset_tag;
link.textContent = "Click here to go to the Inventory page";
});
</script>
</body>