|
|
@@ -0,0 +1,35 @@
|
|
|
+import { type_manager } from "./functions.js";
|
|
|
+import { database } from "./database.js";
|
|
|
+
|
|
|
+class database_downloader {
|
|
|
+ #url;
|
|
|
+ #database;
|
|
|
+
|
|
|
+ constructor(url) {
|
|
|
+ if (!type_manager.is_string(url)) {
|
|
|
+ throw "Url to the database must be an string.";
|
|
|
+ }
|
|
|
+
|
|
|
+ this.#url = url;
|
|
|
+ }
|
|
|
+
|
|
|
+ async download() {
|
|
|
+ const response = await fetch(this.#url);
|
|
|
+
|
|
|
+ if (!response.ok) {
|
|
|
+ throw "Can not download database. Error: " + response.status;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (response.headers.get("content-type") !== "application/json") {
|
|
|
+ throw "Response content type of the database must be an json.";
|
|
|
+ }
|
|
|
+
|
|
|
+ this.#database = new database(await response.json());
|
|
|
+ }
|
|
|
+
|
|
|
+ get result() {
|
|
|
+ return this.#database;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export { database_downloader };
|