diff --git a/package-lock.json b/package-lock.json index 6f445d8..2b329ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "bootstrap": "^5.3.0-alpha3", "chokidar": "^3.5.3", + "electron-fetch": "^1.9.1", "electron-squirrel-startup": "^1.0.0", "glob": "^10.2.2", "lodash-es": "^4.17.21", @@ -2291,6 +2292,17 @@ "node": ">= 12.20.55" } }, + "node_modules/electron-fetch": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/electron-fetch/-/electron-fetch-1.9.1.tgz", + "integrity": "sha512-M9qw6oUILGVrcENMSRRefE1MbHPIz0h79EKIeJWK9v563aT9Qkh8aEHPO1H5vi970wPirNY+jO9OpFoLiMsMGA==", + "dependencies": { + "encoding": "^0.1.13" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/electron-installer-common": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/electron-installer-common/-/electron-installer-common-0.10.3.tgz", @@ -2811,8 +2823,6 @@ "version": "0.1.13", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", - "dev": true, - "optional": true, "dependencies": { "iconv-lite": "^0.6.2" } @@ -2821,8 +2831,6 @@ "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "dev": true, - "optional": true, "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" }, @@ -5826,8 +5834,7 @@ "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/sass": { "version": "1.62.1", diff --git a/package.json b/package.json index 1f93862..8c109db 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "dependencies": { "bootstrap": "^5.3.0-alpha3", "chokidar": "^3.5.3", + "electron-fetch": "^1.9.1", "electron-squirrel-startup": "^1.0.0", "glob": "^10.2.2", "lodash-es": "^4.17.21", diff --git a/src/interfaces/EDSMInterface.js b/src/interfaces/EDSMInterface.js deleted file mode 100644 index 182c2b0..0000000 --- a/src/interfaces/EDSMInterface.js +++ /dev/null @@ -1,18 +0,0 @@ -class EDSM { - constructor() { - this.data = {} - this.dataError = false - } - - request(url) { - return fetch(url) - .then(response => { - if (!response.ok) { - throw new Error('HTTP error' + response.status) - } - return response.json() - }) - .then(json => this.data = json) - .catch(() => this.dataError = true) - } -} \ No newline at end of file diff --git a/src/models/EDSM.ts b/src/models/EDSM.ts new file mode 100644 index 0000000..6047261 --- /dev/null +++ b/src/models/EDSM.ts @@ -0,0 +1,24 @@ +import fetch from 'electron-fetch' +import { Log } from './Log' + +class EDSM { + constructor() {} + + static async request(url: string, options: {[index: string]: string}): Promise { + let data: object|undefined = undefined + + try { + const response = await fetch(url + '?' + new URLSearchParams(options)) + + if (!response.ok) { + throw new Error(`Network error - ${response}`) + } + + data = await response.json() + } catch (err) { + Log.write(`ERROR - EDSM.request(): ${err}`) + } + + return data + } +} \ No newline at end of file