From 08de6b8f1743f8bc2e3621d26d46eb424b8bd019 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Fri, 17 Dec 2021 20:16:11 +0000 Subject: [PATCH] :sparkles: Adds widget for showing public IP --- docs/widgets.md | 21 +++++- src/components/Widgets/PublicIp.vue | 93 +++++++++++++++++++++++++++ src/components/Widgets/WidgetBase.vue | 9 +++ src/utils/MiscHelpers.js | 15 +++++ src/utils/defaults.js | 1 + 5 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/components/Widgets/PublicIp.vue diff --git a/docs/widgets.md b/docs/widgets.md index 04259561..ded52484 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -18,6 +18,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a - [Stock Price History](#stock-price-history) - [Joke of the Day](#joke) - [Flight Data](#flight-data) + - [Public IP Address](#public-ip) - [Self-Hosted Services Widgets](#dynamic-widgets) - [System Info](#system-info) - [CPU History](#cpu-history-netdata) @@ -430,6 +431,24 @@ Displays airport departure and arrival flights, using data from [AeroDataBox](ht --- +### Public IP + +Displays your public IP address, along with ISP name and approx location. Data is fetched from [IP-API.com](https://ip-api.com/). + +

+ +##### Options + +_No config options._ + +##### Example + +```yaml +- type: public-ip +``` + +--- + ## Self-Hosted Services Widgets @@ -441,7 +460,7 @@ Displays info about the server which Dashy is hosted on. Includes user + host, o ##### Options -No config options. +_No config options._ ##### Example diff --git a/src/components/Widgets/PublicIp.vue b/src/components/Widgets/PublicIp.vue new file mode 100644 index 00000000..93c3450f --- /dev/null +++ b/src/components/Widgets/PublicIp.vue @@ -0,0 +1,93 @@ + + + + + diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vue index ec1e839b..f49bd345 100644 --- a/src/components/Widgets/WidgetBase.vue +++ b/src/components/Widgets/WidgetBase.vue @@ -109,6 +109,13 @@ @error="handleError" :ref="widgetRef" /> + { return code; }; +/* Given a 2-digit country code, return path to flag image from Flagpedia */ +export const getCountryFlag = (countryCode, dimens) => { + const protocol = 'https'; + const cdn = 'flagcdn.com'; + const dimensions = dimens || '64x48'; + const country = countryCode.toLowerCase(); + const ext = 'png'; + return `${protocol}://${cdn}/${dimensions}/${country}.${ext}`; +}; + +/* Given a Latitude & Longitude object, and optional zoom level, return link to OSM */ +export const getMapUrl = (location, zoom) => { + return `https://www.openstreetmap.org/#map=${zoom || 10}/${location.lat}/${location.lon}`; +}; + /* Given a large number, will add commas to make more readable */ export const putCommasInBigNum = (bigNum) => { const strNum = Number.isNaN(bigNum) ? bigNum : String(bigNum); diff --git a/src/utils/defaults.js b/src/utils/defaults.js index d5bcdd06..e19738c8 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -219,6 +219,7 @@ module.exports = { rssToJson: 'https://api.rss2json.com/v1/api.json', codeStats: 'https://codestats.net/', holidays: 'https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForDateRange', + publicIp: 'http://ip-api.com/json', }, /* URLs for web search engines */ searchEngineUrls: {