Skip to content

Commit

Permalink
Merge branch 'master' into add-choice-number-columns-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Terdious authored Sep 30, 2024
2 parents 9e30e4c + 1f7617c commit 710f469
Show file tree
Hide file tree
Showing 27 changed files with 286 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: |
npm run build
- name: ↗️ Upload build artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: static
path: front/build
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
with:
version: latest
- name: ↙️ Download build artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: static
path: static
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-master-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
env:
RELATIVE_CI_KEY: ${{ secrets.RELATIVE_CI_KEY }}
- name: ↗️ Upload build artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: static
path: front/build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker-pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ jobs:
run: |
npm run build-with-stats
- name: ↗️ Upload webpack stats artifact
uses: relative-ci/agent-upload-artifact-action@v1
uses: relative-ci/agent-upload-artifact-action@v2
with:
webpackStatsFile: ./front/stats.json
- name: ↗️ Upload build artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: static
path: front/build
Expand All @@ -168,7 +168,7 @@ jobs:
with:
version: latest
- name: ↙️ Download build artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: static
path: static
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
run: |
npm run build
- name: ↗️ Upload build artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: static
path: front/build
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
with:
version: v0.9.1
- name: ↙️ Download build artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: static
path: static
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gladys",
"version": "4.45.0",
"version": "4.45.1",
"description": "A privacy-first, open-source home assistant",
"main": "index.js",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions server/api/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ module.exports = function UserController(gladys) {
* @apiGroup User
*/
async function updateMySelf(req, res, next) {
delete req.body.role;
const newUser = await gladys.user.update(req.user.id, req.body);
res.json(newUser);
}
Expand Down
5 changes: 5 additions & 0 deletions server/config/scheduler-jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const jobs = [
rule: '0 0 22 * * *', // every day at 22:00
event: EVENTS.JOB.PURGE_OLD_JOBS,
},
{
name: 'daily-purge-of-old-messages',
rule: '0 0 23 * * *', // every day at 23:00
event: EVENTS.MESSAGE.PURGE_OLD_MESSAGES,
},
{
name: 'check-device-batteries',
rule: '0 0 9 * * 6', // At 09:00 AM, only on Saturday
Expand Down
28 changes: 21 additions & 7 deletions server/lib/calendar/calendar.destroyEvents.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
const { Op } = require('sequelize');
const db = require('../../models');

/**
* @description Delete events from a calendar.
* @param {string} calendarId - Calendar id to empty.
* @param {object} options - Options of the query.
* @example
* gladys.calendar.destroyEvents('0dc03aef-4a23-9c4e-88e3-5437971269e5');
* gladys.calendar.destroyEvents('0dc03aef-4a23-9c4e-88e3-5437971269e5', {url: '/calendar/event.ics'});
*/
async function destroyEvents(calendarId) {
await db.CalendarEvent.destroy({
where: {
calendar_id: calendarId,
},
});
async function destroyEvents(calendarId, options = {}) {
const where = {
calendar_id: calendarId,
};

if (options.url) {
where.url = {
[Op.eq]: options.url,
};
}

if (options.from) {
where.start = {
[Op.gte]: new Date(options.from),
};
}

await db.CalendarEvent.destroy({ where });
}

module.exports = {
Expand Down
14 changes: 14 additions & 0 deletions server/lib/gateway/gateway.getEdfTempo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @description Get edf tempo.
* @returns {Promise} Resolve data from RTE.
* @example
* const data = await getEdfTempo();
*/
async function getEdfTempo() {
const systemInfos = await this.system.getInfos();
return this.gladysGatewayClient.getEdfTempo(systemInfos.gladys_version);
}

module.exports = {
getEdfTempo,
};
2 changes: 2 additions & 0 deletions server/lib/gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const { restoreBackupEvent } = require('./gateway.restoreBackupEvent');
const { saveUsersKeys } = require('./gateway.saveUsersKeys');
const { refreshUserKeys } = require('./gateway.refreshUserKeys');
const { getEcowattSignals } = require('./gateway.getEcowattSignals');
const { getEdfTempo } = require('./gateway.getEdfTempo');
const { openAIAsk } = require('./gateway.openAIAsk');
const { getTTSApiUrl } = require('./gateway.getTTSApiUrl');
const { forwardMessageToOpenAI } = require('./gateway.forwardMessageToOpenAI');
Expand Down Expand Up @@ -117,6 +118,7 @@ Gateway.prototype.restoreBackupEvent = restoreBackupEvent;
Gateway.prototype.saveUsersKeys = saveUsersKeys;
Gateway.prototype.refreshUserKeys = refreshUserKeys;
Gateway.prototype.getEcowattSignals = getEcowattSignals;
Gateway.prototype.getEdfTempo = getEdfTempo;
Gateway.prototype.openAIAsk = openAIAsk;
Gateway.prototype.forwardMessageToOpenAI = forwardMessageToOpenAI;

Expand Down
6 changes: 5 additions & 1 deletion server/lib/message/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ const { EVENTS } = require('../../utils/constants');
const { create } = require('./message.create');
const { get } = require('./message.get');
const { reply } = require('./message.reply');
const { purge } = require('./message.purge');
const { handleEvent } = require('./message.handleEvent');
const { replyByIntent } = require('./message.replyByIntent');
const { sendToUser } = require('./message.sendToUser');
const { eventFunctionWrapper } = require('../../utils/functionsWrapper');

const MessageHandler = function MessageHandler(event, brain, service, state, variable) {
this.event = event;
this.brain = brain;
this.service = service;
this.state = state;
this.variable = variable;
event.on(EVENTS.MESSAGE.NEW, (message) => this.handleEvent(message));
this.event.on(EVENTS.MESSAGE.NEW, (message) => this.handleEvent(message));
this.event.on(EVENTS.MESSAGE.PURGE_OLD_MESSAGES, eventFunctionWrapper(this.purge.bind(this)));
};

MessageHandler.prototype.create = create;
MessageHandler.prototype.get = get;
MessageHandler.prototype.handleEvent = handleEvent;
MessageHandler.prototype.reply = reply;
MessageHandler.prototype.purge = purge;
MessageHandler.prototype.replyByIntent = replyByIntent;
MessageHandler.prototype.sendToUser = sendToUser;

Expand Down
29 changes: 29 additions & 0 deletions server/lib/message/message.purge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { Op } = require('sequelize');
const db = require('../../models');
const logger = require('../../utils/logger');

const DAYS_TO_KEEP = 15;

/**
* @public
* @description Purge.
* @returns {Promise} Resolve.
* @example
* gladys.message.purge();
*/
async function purge() {
const deleteBeforeDate = new Date(new Date().getTime() - DAYS_TO_KEEP * 24 * 60 * 60 * 1000);
logger.info(`Deleting all messages created before = ${deleteBeforeDate}`);
await db.Message.destroy({
where: {
created_at: {
[Op.lte]: deleteBeforeDate,
},
},
});
logger.info('Messages purged!');
}

module.exports = {
purge,
};
14 changes: 7 additions & 7 deletions server/package-lock.json

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

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"supertest": "^3.4.2"
},
"dependencies": {
"@gladysassistant/gladys-gateway-js": "^4.14.0",
"@gladysassistant/gladys-gateway-js": "^4.15.0",
"@hapi/joi": "^17.1.0",
"@hapi/joi-date": "^2.0.1",
"@nlpjs/similarity": "^4.26.1",
Expand Down
14 changes: 14 additions & 0 deletions server/services/caldav/lib/calendar/calendar.syncUserCalendars.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Promise = require('bluebird');
const get = require('get-value');
const logger = require('../../../../utils/logger');
const { ServiceNotConfiguredError, NotFoundError } = require('../../../../utils/coreErrors');

Expand Down Expand Up @@ -108,6 +109,19 @@ async function syncUserCalendars(userId) {
throw new NotFoundError('CALDAV_FAILED_REQUEST_EVENTS');
}

await Promise.map(
jsonEvents,
async (jsonEvent) => {
if (get(jsonEvent, 'rrule.options.until') && jsonEvent.href) {
await this.gladys.calendar.destroyEvents(calendarToUpdate.id, {
url: jsonEvent.href,
from: get(jsonEvent, 'rrule.options.until'),
});
}
},
{ concurrency: 5 },
);

const formatedEvents = this.formatEvents(jsonEvents, calendarToUpdate);

let insertedOrUpdatedEvent = 0;
Expand Down
33 changes: 33 additions & 0 deletions server/services/caldav/package-lock.json

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

1 change: 1 addition & 0 deletions server/services/caldav/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bluebird": "^3.7.0",
"dav-request": "^1.8.0",
"dayjs": "^1.11.10",
"get-value": "^3.0.1",
"ical": "^0.8.0",
"xmldom": "^0.6.0"
}
Expand Down
Loading

0 comments on commit 710f469

Please sign in to comment.