Skip to content

Commit

Permalink
Fixed bug when saving config and removed need for user to enter serve…
Browse files Browse the repository at this point in the history
…r details
  • Loading branch information
greghesp committed Dec 3, 2019
1 parent 411a681 commit 7f26b78
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"workbox-webpack-plugin": "4.3.1"
},
"scripts": {
"start": "node scripts/start.js",
"start": "set \"REACT_APP_DEV_SERVER=http://127.0.0.1:3000\" && node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js"
},
Expand Down
30 changes: 15 additions & 15 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ function App({history}) {
setUserCount(response.data.size);
setLoading(false)
} catch (e) {
if(e.message === "Network Error" ||
e.message === "Failed to execute 'open' on 'XMLHttpRequest': Invalid URL" ||
e.response.status === 404) {
return setOverride(true)
}
// if(e.message === "Network Error" ||
// e.message === "Failed to execute 'open' on 'XMLHttpRequest': Invalid URL" ||
// e.response.status === 404) {
// return setOverride(true)
// }
message.error(e.message);
}
}

function OverrideReload() {
getUserCount();
setOverride($ => !$);
}

if(override) return (
<Setup>
<Override setReload={() => OverrideReload()} />
</Setup>
);
// function OverrideReload() {
// getUserCount();
// setOverride($ => !$);
// }
//
// if(override) return (
// <Setup>
// <Override setReload={() => OverrideReload()} />
// </Setup>
// );

if(loading) return <Loading/>;

Expand Down
30 changes: 12 additions & 18 deletions client/src/helpers/api.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import axios from 'axios';

export const post = async function(data, url) {
const p = await localStorage.getItem('port');
const i = await localStorage.getItem('ip');
if(process.env.REACT_APP_DEV_SERVER) {
return axios.post(`${process.env.REACT_APP_DEV_SERVER}/server/${url}`, {
data
});
}

const port = p ? p : '3000';
const ip = i ? i : '127.0.0.1';

const w = window.location;

return axios({
method: "post",
url: `http://${ip}:${port}/server/${url}`,
return axios.post(`/server/${url}`, {
data
});
};

export const sandbox = async function(data) {
const p = await localStorage.getItem('port');
const i = await localStorage.getItem('ip');

const port = p ? p : '3000';
const ip = i ? i : '127.0.0.1';
if(process.env.REACT_APP_DEV_SERVER) {
return axios.post(`${process.env.REACT_APP_DEV_SERVER}/assistant`, {
data
});
}

return axios({
method: "post",
url: `http://${ip}:${port}/assistant`,
return axios.post('/assistant', {
data
});
};
4 changes: 4 additions & 0 deletions readMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Send Assistant Relay any query you would send the Google Assistant SDK, and get

It also supports the Google Home Broadcast command so you can send audio notifications to your Google Home devices, without interrupting music.

## New in V3.1.0
- Fixed a bug that prevented the configuration being saved
- Removed the need for the user to enter the server IP and port

## New in V3.0.6
- Fixed a [bug](https://github.com/greghesp/assistant-relay/issues/135) that set invalid date when clearing quiet hours times

Expand Down
2 changes: 1 addition & 1 deletion relay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assistant-relay",
"version": "3.0.6",
"version": "3.1.0",
"description": "Middleman server to allow custom integration with Google Home/Assistant",
"keywords": [
"google",
Expand Down
3 changes: 2 additions & 1 deletion relay/routes/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ router.post('/updateConfig', async(req, res) => {
try {
const db = await low(adapter);
const promises = [];
Object.entries(req.body).forEach(([key, val]) => {
Object.entries(req.body.data).forEach(([key, val]) => {
console.log(key, val);
promises.push(db.set(key, val).write());
});
await Promise.all(promises);
Expand Down

0 comments on commit 7f26b78

Please sign in to comment.