diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9c691df
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.fo76-dumps-ids.db
diff --git a/README.md b/README.md
index c1fcfeb..829f6a9 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/api.php b/api.php
index 9f939a1..12a7350 100644
--- a/api.php
+++ b/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;");
diff --git a/index.html b/index.html
index 9f83b9a..531f124 100644
--- a/index.html
+++ b/index.html
@@ -27,11 +27,13 @@
instructions on how to enable JavaScript in your web browser.
-
+
+
On this page you can retrieve a random record from the Fallout 76 game files.
Simply select the signatures you want to include below, and then press the "Get random record"
button.
-
+
+
@@ -39,7 +41,7 @@
@@ -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."
+ });
});