Add error feedback and hide database
This commit is contained in:
parent
3204a76983
commit
56ba3662ee
|
@ -0,0 +1 @@
|
||||||
|
.fo76-dumps-ids.db
|
|
@ -2,7 +2,7 @@
|
||||||
Allows a user to retrieve a random record from the _Fallout 76_ game files.
|
Allows a user to retrieve a random record from the _Fallout 76_ game files.
|
||||||
The user can filter records by data type to avoid receiving uninteresting data types.
|
The user can filter records by data type to avoid receiving uninteresting data types.
|
||||||
|
|
||||||
The back end, `api.php`, communicates with an SQLite database, `fo76-dumps-ids.db`, containing only the `IDS.csv` dump
|
The back end, `api.php`, communicates with an SQLite database, `.fo76-dumps-ids.db`, containing only the `IDS.csv` dump
|
||||||
from [the _Fallout 76_ data dumps repository](https://github.com/FWDekker/fo76-dumps/).
|
from [the _Fallout 76_ data dumps repository](https://github.com/FWDekker/fo76-dumps/).
|
||||||
The database is not included in this repository.
|
The database is not included in this repository.
|
||||||
|
|
||||||
|
|
2
api.php
2
api.php
|
@ -5,7 +5,7 @@ if (!isset($_GET["action"]))
|
||||||
exit("null");
|
exit("null");
|
||||||
$action = $_GET["action"];
|
$action = $_GET["action"];
|
||||||
|
|
||||||
$db = new SQLite3("fo76-dumps-ids.db", SQLITE3_OPEN_READONLY);
|
$db = new SQLite3(".fo76-dumps-ids.db", SQLITE3_OPEN_READONLY);
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case "list-signatures":
|
case "list-signatures":
|
||||||
$results = $db->query("SELECT DISTINCT Signature FROM IDs ORDER BY Signature;");
|
$results = $db->query("SELECT DISTINCT Signature FROM IDs ORDER BY Signature;");
|
||||||
|
|
40
index.html
40
index.html
|
@ -27,11 +27,13 @@
|
||||||
instructions on how to enable JavaScript in your web browser</a>.
|
instructions on how to enable JavaScript in your web browser</a>.
|
||||||
</span>
|
</span>
|
||||||
</noscript>
|
</noscript>
|
||||||
<p>
|
<blockquote>
|
||||||
|
<p><em>
|
||||||
On this page you can retrieve a random record from the <i>Fallout 76</i> game files.
|
On this page you can retrieve a random record from the <i>Fallout 76</i> game files.
|
||||||
Simply select the signatures you want to include below, and then press the "Get random record"
|
Simply select the signatures you want to include below, and then press the "Get random record"
|
||||||
button.
|
button.
|
||||||
</p>
|
</em></p>
|
||||||
|
</blockquote>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
@ -39,7 +41,7 @@
|
||||||
<!-- Input -->
|
<!-- Input -->
|
||||||
<section class="container">
|
<section class="container">
|
||||||
<h2>Settings</h2>
|
<h2>Settings</h2>
|
||||||
<form>
|
<form id="signatureForm">
|
||||||
<button id="signatureToggle" class="button button-outline" type="button">Select all signatures</button>
|
<button id="signatureToggle" class="button button-outline" type="button">Select all signatures</button>
|
||||||
<fieldset id="signatures">Loading... please wait.</fieldset>
|
<fieldset id="signatures">Loading... please wait.</fieldset>
|
||||||
|
|
||||||
|
@ -63,7 +65,7 @@
|
||||||
<a href="https://git.fwdekker.com/FWDekker/random-fo76/src/branch/master/LICENSE">MIT License</a>.
|
<a href="https://git.fwdekker.com/FWDekker/random-fo76/src/branch/master/LICENSE">MIT License</a>.
|
||||||
Source code available on <a href="https://git.fwdekker.com/FWDekker/random-fo76/">git</a>.
|
Source code available on <a href="https://git.fwdekker.com/FWDekker/random-fo76/">git</a>.
|
||||||
|
|
||||||
<div style="float: right;">v1.0.6</div>
|
<div style="float: right;">v1.0.7</div>
|
||||||
</section>
|
</section>
|
||||||
</footer>
|
</footer>
|
||||||
</main>
|
</main>
|
||||||
|
@ -158,12 +160,16 @@
|
||||||
* Downloads an array of signatures from the API.
|
* Downloads an array of signatures from the API.
|
||||||
*
|
*
|
||||||
* @param callback the function to execute with the array of signatures
|
* @param callback the function to execute with the array of signatures
|
||||||
|
* @param handle the function to execute if signatures could not be downloaded
|
||||||
*/
|
*/
|
||||||
const downloadSignatures = callback => {
|
const downloadSignatures = (callback, handle) => {
|
||||||
fetch("api.php?action=list-signatures")
|
fetch("api.php?action=list-signatures")
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.ok)
|
if (!response.ok) {
|
||||||
|
if (handle) handle(response);
|
||||||
|
console.error(response);
|
||||||
throw new Error("Failed to fetch list of signatures.");
|
throw new Error("Failed to fetch list of signatures.");
|
||||||
|
}
|
||||||
|
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
|
@ -218,14 +224,18 @@
|
||||||
* Downloads a random record from the API.
|
* Downloads a random record from the API.
|
||||||
*
|
*
|
||||||
* @param callback the function to execute with the record
|
* @param callback the function to execute with the record
|
||||||
|
* @param handle the function to execute if signatures could not be downloaded
|
||||||
*/
|
*/
|
||||||
const downloadRandomRecord = callback => {
|
const downloadRandomRecord = (callback, handle) => {
|
||||||
const selectedSignatures = getSelectedSignatures();
|
const selectedSignatures = getSelectedSignatures();
|
||||||
|
|
||||||
fetch(`api.php?action=get-random&signatures=${selectedSignatures.join(",")}`)
|
fetch(`api.php?action=get-random&signatures=${selectedSignatures.join(",")}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.ok)
|
if (!response.ok) {
|
||||||
|
if (handle) handle(response);
|
||||||
|
console.error(response);
|
||||||
throw new Error("Failed to fetch random record.");
|
throw new Error("Failed to fetch random record.");
|
||||||
|
}
|
||||||
|
|
||||||
return response.text();
|
return response.text();
|
||||||
})
|
})
|
||||||
|
@ -248,10 +258,16 @@
|
||||||
doAfterLoad(() => {
|
doAfterLoad(() => {
|
||||||
$("#submit").onclick = () => downloadRandomRecord(record => showRecord(record));
|
$("#submit").onclick = () => downloadRandomRecord(record => showRecord(record));
|
||||||
|
|
||||||
downloadSignatures(signatures => {
|
downloadSignatures(
|
||||||
createSignatureButtons(signatures);
|
signatures => {
|
||||||
loadSelectedSignaturesFromCookie();
|
createSignatureButtons(signatures);
|
||||||
});
|
loadSelectedSignaturesFromCookie();
|
||||||
|
},
|
||||||
|
errorResponse => {
|
||||||
|
const form = $("#signatureForm");
|
||||||
|
form.style.color = "red";
|
||||||
|
form.innerHTML = "Error: Failed to download signatures."
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue