🥅 Catches errors if caused by undefined options

This commit is contained in:
Alicia Sykes 2022-07-23 14:42:26 +01:00
parent ad9df7a67c
commit 37954eaeb0
2 changed files with 12 additions and 3 deletions

View File

@ -1838,7 +1838,7 @@ Display info from the Gluetun VPN container public IP API. This can show the IP
**Field** | **Type** | **Required** | **Description**
--- | --- | --- | ---
**`visibleFields`** | `string` | Required | A comma separated list of the fields you want visible in the widget. You can have any number of the following : `public_ip`, `region`, `country`, `city`, `location`, `organisation`, `postal_code`, `timezone`
**`visibleFields`** | `string` | Required | A comma separated list of the fields you want visible in the widget. You can have any number of the following : `public_ip`, `region`, `country`, `city`, `location`, `organisation`, `postal_code`, `timezone`. Defaults to just `public_ip`
**`host`** | `string` | Required | The url to the gluetun HTTP control server. E.g. `http://gluetun:8000`

View File

@ -52,14 +52,23 @@ export default {
timezone: null,
};
},
computed: {
visibleFields() {
return this.options.visibleFields || 'public_ip';
},
hostname() {
if (!this.options.hostname) this.error('`hostname` is required');
return this.options.hostname;
},
},
methods: {
/* Make GET request to Gluetun publicip API endpoint */
fetchData() {
this.makeRequest(`${this.options.hostname}/v1/publicip/ip`).then(this.processData);
this.makeRequest(`${this.hostname}/v1/publicip/ip`).then(this.processData);
},
/* Assign data variables to the returned data */
processData(ipInfo) {
const fields = this.options.visibleFields.split(',');
const fields = this.visibleFields.split(',');
this.public_ip = fields.includes('public_ip') ? ipInfo.public_ip : null;
this.country = fields.includes('country') ? ipInfo.country : null;
this.region = fields.includes('region') ? ipInfo.region : null;