Skip to content

Commit

Permalink
feat: Add support for API tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Nov 20, 2023
1 parent 96d565b commit 95de7e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
<input type="text" id="nightscout_url" name="nightscoutUrl" required />
</span>
</div>

<div type="textarea" class="sdpi-item">
<label for="token" class="sdpi-item-label">Token</label>
<span class="sdpi-item-value">
<input type="text" id="token" name="token" required />
</span>
</div>
</form>
</div>

Expand Down
6 changes: 5 additions & 1 deletion src/com.gabe565.nightscout.sdPlugin/js/Nightscout.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class Nightscout {
try {
const url = new URL(this.settings.nightscoutUrl);
url.pathname += "api/v2/properties";
const response = await fetch(url);
const headers = {};
if (this.settings.token) {
headers["Api-Secret"] = this.settings.token;
}
const response = await fetch(url, { headers });
const data = await response.json();
$SD.setImage(this.context, this.template.render(data));
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions src/com.gabe565.nightscout.sdPlugin/js/const.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const DefaultSettings = {
nightscoutUrl: "",
token: "",
updateInterval: 60000,
};

0 comments on commit 95de7e0

Please sign in to comment.