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.
|
||||
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/).
|
||||
The database is not included in this repository.
|
||||
|
||||
|
|
2
api.php
2
api.php
|
@ -5,7 +5,7 @@ if (!isset($_GET["action"]))
|
|||
exit("null");
|
||||
$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) {
|
||||
case "list-signatures":
|
||||
$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>.
|
||||
</span>
|
||||
</noscript>
|
||||
<p>
|
||||
<blockquote>
|
||||
<p><em>
|
||||
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"
|
||||
button.
|
||||
</p>
|
||||
</em></p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
@ -39,7 +41,7 @@
|
|||
<!-- Input -->
|
||||
<section class="container">
|
||||
<h2>Settings</h2>
|
||||
<form>
|
||||
<form id="signatureForm">
|
||||
<button id="signatureToggle" class="button button-outline" type="button">Select all signatures</button>
|
||||
<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>.
|
||||
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>
|
||||
</footer>
|
||||
</main>
|
||||
|
@ -158,12 +160,16 @@
|
|||
* Downloads an array of signatures from the API.
|
||||
*
|
||||
* @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")
|
||||
.then(response => {
|
||||
if (!response.ok)
|
||||
if (!response.ok) {
|
||||
if (handle) handle(response);
|
||||
console.error(response);
|
||||
throw new Error("Failed to fetch list of signatures.");
|
||||
}
|
||||
|
||||
return response.json();
|
||||
})
|
||||
|
@ -218,14 +224,18 @@
|
|||
* Downloads a random record from the API.
|
||||
*
|
||||
* @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();
|
||||
|
||||
fetch(`api.php?action=get-random&signatures=${selectedSignatures.join(",")}`)
|
||||
.then(response => {
|
||||
if (!response.ok)
|
||||
if (!response.ok) {
|
||||
if (handle) handle(response);
|
||||
console.error(response);
|
||||
throw new Error("Failed to fetch random record.");
|
||||
}
|
||||
|
||||
return response.text();
|
||||
})
|
||||
|
@ -248,10 +258,16 @@
|
|||
doAfterLoad(() => {
|
||||
$("#submit").onclick = () => downloadRandomRecord(record => showRecord(record));
|
||||
|
||||
downloadSignatures(signatures => {
|
||||
createSignatureButtons(signatures);
|
||||
loadSelectedSignaturesFromCookie();
|
||||
});
|
||||
downloadSignatures(
|
||||
signatures => {
|
||||
createSignatureButtons(signatures);
|
||||
loadSelectedSignaturesFromCookie();
|
||||
},
|
||||
errorResponse => {
|
||||
const form = $("#signatureForm");
|
||||
form.style.color = "red";
|
||||
form.innerHTML = "Error: Failed to download signatures."
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue