Skip to content

Commit

Permalink
Fixed some bugs for 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
greghesp committed Dec 5, 2019
1 parent 7f26b78 commit 9e163b2
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 21 deletions.
48 changes: 40 additions & 8 deletions client/src/views/dash/About/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import React from "react";
import {Typography} from "antd";
import React, {useEffect, useState} from "react";
import {message, Typography, Alert} from "antd";
import {post} from '~/helpers/api';

import * as Styles from './styles';

const {Text, Paragraph, Title} = Typography;

function About(){
const [isUpdate, setIsUpdate] = useState(false);

useEffect(() => {
checkUpdate();
},[]);

async function checkUpdate() {
try {
const resp = await post({}, 'checkUpdate');
setIsUpdate(resp.data)
} catch (e) {
message.error(e.message);
}
}

return (
<Styles.Container>
<Styles.Text>
<AlertBox update={isUpdate}/>
<Title level={3}>About Assistant Relay</Title>
<Paragraph>
<Text>
Expand Down Expand Up @@ -47,12 +65,12 @@ function About(){
<Title level={3}>Want to buy me a coffee?</Title>
<Text>Any donations are greatly appreciated, but certainly not required!</Text>
<Styles.Form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="YK2LXAHNTSVLC" />
<input width="200" type="image" src="https://raw.githubusercontent.com/stefan-niedermann/paypal-donate-button/master/paypal-donate-button.png" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" />
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1" />
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="YK2LXAHNTSVLC" />
<input width="200" type="image" src="https://raw.githubusercontent.com/stefan-niedermann/paypal-donate-button/master/paypal-donate-button.png" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" />
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1" />
</form>

</Styles.Form>

Expand All @@ -63,4 +81,18 @@ function About(){
)
}

function AlertBox({update}) {
if(!update.update) return null;
return (
<Styles.Alert>
<Alert
message={`Version ${update.details.title} is available`}
description={<span>To download the latest update, please visit <a>{update.details.link}</a></span>}
type="info"
showIcon
/>
</Styles.Alert>
)
}

export default About;
4 changes: 4 additions & 0 deletions client/src/views/dash/About/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ export const Form = styled.div`
justify-content: center;
`;

export const Alert = styled.div`
margin: 10px 0;
`;

6 changes: 6 additions & 0 deletions readMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ 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.1
**Note: Please run `npm i` after updating**
- Fixed a bug that stopped commands from working (sorry, not sure where this one came from)
- Fixed the update checker
- Added a feature to check for updates every day

## 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
Expand Down
8 changes: 7 additions & 1 deletion relay/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const createError = require('http-errors');
const cron = require("node-cron");
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const cors = require('cors');

const {initializeServer} = require('./helpers/server');
const {initializeServer, isUpdateAvailable} = require('./helpers/server');

const serverRouter = require('./routes/server');
const indexRouter = require('./routes/index');
Expand All @@ -21,6 +22,11 @@ app.use(express.static(path.join(__dirname, './views')));

global.assistants = {};

cron.schedule("0 1 * * *", function() {
if(updateAvail) console.log(`An update is available. Please visit https://github.com/greghesp/assistant-relay/releases`);
});


(async function () {
try {
await initializeServer();
Expand Down
3 changes: 3 additions & 0 deletions relay/bin/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "v3.1.1"
}
14 changes: 8 additions & 6 deletions relay/helpers/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const parser = new Parser();
const adapter = new FileSync('./bin/config.json');
const {setCredentials} = require('../helpers/auth');
const {sendTextInput} = require('../helpers/assistant.js');
const version = require('../bin/version.json');

const FileWriter = require('wav').FileWriter;
const moment = require('moment');
Expand Down Expand Up @@ -42,7 +43,6 @@ exports.initializeServer = function (text) {
users: [],
responses: [],
devices: [],
lastCheck: moment().format()
}).write();
const size = db.get('users').size().value();
const users = db.get('users').value();
Expand Down Expand Up @@ -122,13 +122,15 @@ exports.isStartupMuted = function() {
};


exports.isUpdateAvailable = function() {
exports.isUpdateAvailable = function() {
return new Promise(async(res, rej) => {
const db = await low(adapter);
const lastCheck = db.get('lastCheck').value();
const feed = await parser.parseURL('https://github.com/greghesp/assistant-relay/releases.atom');
const latestTime = feed.items[0].pubDate;
return res(moment(lastCheck).isBefore(latestTime));
const latestVersion = feed.items[0].title;
if(latestVersion !== version.version) {
return res(true)
} else {
return res(false)
}
})
};

Expand Down
23 changes: 21 additions & 2 deletions relay/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion relay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assistant-relay",
"version": "3.1.0",
"version": "3.1.1",
"description": "Middleman server to allow custom integration with Google Home/Assistant",
"keywords": [
"google",
Expand Down Expand Up @@ -37,6 +37,7 @@
"moment": "^2.24.0",
"morgan": "~1.9.1",
"multicast-dns": "^7.2.0",
"node-cron": "^2.0.3",
"node-dns-sd": "^0.4.0",
"pm2": "^4.1.2",
"rss-parser": "^3.7.3",
Expand Down
4 changes: 2 additions & 2 deletions relay/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ router.post('/assistant', async(req, res) => {
const timestamp = Date.now();
const fileStream = outputFileStream(convoData, timestamp);
const isQH = await isQuietHour();
const {user, converse = false, preset} = req.body;
let {command, broadcast = false} = req.body;
const {user, converse = false, preset} = req.body.data;
let {command, broadcast = false} = req.body.data;

// console.log(user, converse, preset, command, broadcast)

Expand Down
3 changes: 2 additions & 1 deletion relay/routes/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const router = express.Router();
router.post('/checkUpdate', async(req, res) => {
try {
const update = await isUpdateAvailable();
console.log(update)
const data = {};
if(update) {
const details = await updateDetails();
Expand All @@ -25,6 +26,7 @@ router.post('/checkUpdate', async(req, res) => {
} else {
data.update = false
}
console.log(data)
res.status(200).json(data);
} catch (e) {
res.status(500).send(e.message)
Expand Down Expand Up @@ -88,7 +90,6 @@ router.post('/updateConfig', async(req, res) => {
const db = await low(adapter);
const promises = [];
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
1 change: 1 addition & 0 deletions release.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const dir = './release';
const ncp = require('ncp').ncp;
ncp.limit = 16;

console.log("Did you remember to change the version number in /bin/version.json and /relay/package.json?!");

if (!fs.existsSync(dir)) fs.mkdirSync(dir);
ncp('./relay/bin/', './release/bin');
Expand Down

0 comments on commit 9e163b2

Please sign in to comment.