Skip to content

Commit

Permalink
feat: Update Nightscout API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsmaerten committed Apr 26, 2024
1 parent 644ce55 commit f0f161d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
7 changes: 5 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
tabWidth: 2
semi: true
{
"tabWidth": 2,
"semi": true,
"endOfLine": "crlf"
}
7 changes: 4 additions & 3 deletions src/electron-app/components/nightscout-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export default class NightscoutAPI {
// If url has a username, we're using api-secret auth
if (this.url.username) {
const decoded = decodeURIComponent(this.url.username);
const authSecret = require("crypto").createHash("sha1").update(decoded).digest("hex");
this.apiSecret = authSecret
const hash = require("crypto").createHash("sha1");
const authSecret = hash.update(decoded).digest("hex");
this.apiSecret = authSecret;
this.url.username = "";
}
this.url.pathname = API_PATH;
Expand All @@ -29,7 +30,7 @@ export default class NightscoutAPI {
rejectUnauthorized: false,
}),
// If we have an api secret, use it as a header
headers: this.apiSecret ? { 'api-secret': this.apiSecret } : {},
headers: this.apiSecret ? { "api-secret": this.apiSecret } : {},
});
} catch (error) {
console.error("Error fetching current glucose", error);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum IPC {
}

export const STORAGE_KEY = "app-settings";
export const API_PATH = "/api/v1/entries/current.json";
export const API_PATH = "/api/v1/entries.json";
//export const ICON_SIZE = 128;
//export const ICON_TEXT_MARGIN = 10;
export const MGDL_TO_MMOLL = 18;
Expand Down
8 changes: 6 additions & 2 deletions src/web-app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const App = () => {
});
};

const isGluroo = settings?.nsUrl?.includes("ns.gluroo.com");

// Renders the Splash component at first,
// then redirects to Nightscout after countdown hits 0.
const renderCountdown = () => (
Expand All @@ -70,6 +72,7 @@ const App = () => {
if (!props.completed) {
return (
<Splash
isGluroo={isGluroo}
s={props.seconds}
ms={props.milliseconds}
total={props.total}
Expand All @@ -78,13 +81,14 @@ const App = () => {
} else {
// Remove username (api secret) from URL before redirecting
let href = settings.nsUrl;
if (href.includes("@")) {
if (isGluroo) href = "https://app.gluroo.com";
else if (href.includes("@")) {
const url = new URL(href);
url.username = "";
href = url.toString();
}
window.location.href = href;
return <p>Getting Nightscout ...</p>;
return <p>Getting {isGluroo ? "Gluroo" : "Nightscout"} ...</p>;
}
}}
></Countdown>
Expand Down
4 changes: 3 additions & 1 deletion src/web-app/components/Splash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ export default (props: any) => {
});

const [latestVersion, setLatestVersion] = React.useState(version);
const targetApp = props.isGluroo ? "Gluroo" : "Nightscout";
const timeLeft = getTimeLeft(props);

return (
<div>
<h2>Nightscout will be here in {getTimeLeft(props)}</h2>
<h2>{`${targetApp} will be here in ${timeLeft}`}</h2>
<hr />
<p>Need to change your settings? Click the button below:</p>
<button onClick={resetSettings}>Open settings</button>
Expand Down

0 comments on commit f0f161d

Please sign in to comment.