From af8293473c46f26d530fc021a454c9da735e59d8 Mon Sep 17 00:00:00 2001 From: thefirstspine Date: Sun, 22 Nov 2020 19:23:17 +0100 Subject: [PATCH 1/4] Handled events from calendar service --- api/controllers/EventsController.js | 15 +++++++++++++-- api/helpers/get-events.js | 21 +++++++++++++++++++++ api/models/Event.js | 11 ----------- views/elements/event-online-target.ejs | 4 ++-- 4 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 api/helpers/get-events.js diff --git a/api/controllers/EventsController.js b/api/controllers/EventsController.js index 3262189..b68ec05 100644 --- a/api/controllers/EventsController.js +++ b/api/controllers/EventsController.js @@ -8,7 +8,8 @@ module.exports = { async index(req, res) { - const events = await sails.models.event.find({ + // Getting internal events + const internalEvents = await sails.models.event.find({ sort: 'datetimeFrom ASC', where: { language: req.session.locale, @@ -16,12 +17,22 @@ module.exports = { }, }); + const eventsFromCalendar = await sails.helpers.getEvents(); + return res.view( 'pages/events.ejs', { ...await sails.helpers.layoutConfig(req.user_id), title: 'events.title', - events, + events: [ + ...internalEvents, + ...eventsFromCalendar.map( + (event) => { + event.type = `online:${event.type}`; + return event; + } + ), + ], gkey: process.env.GKEY, } ); diff --git a/api/helpers/get-events.js b/api/helpers/get-events.js new file mode 100644 index 0000000..e056059 --- /dev/null +++ b/api/helpers/get-events.js @@ -0,0 +1,21 @@ +const fetch = require('node-fetch'); + +module.exports = { + + inputs: { + }, + + fn: async function(inputs, exits) { + try { + const baseUrl = process.env.CALENDAR_URL; + const date = (new Date()).toISOString(); + const url = `${baseUrl}/events?filter=datetimeTo||gt||${date}`; + const result = await fetch(url); + const resultJson = await result.json(); + return exits.success(resultJson); + } catch (e) { + console.log(e); + return exits.success(false); + } + } +} diff --git a/api/models/Event.js b/api/models/Event.js index 6dbb0ef..d1f4437 100644 --- a/api/models/Event.js +++ b/api/models/Event.js @@ -16,17 +16,6 @@ module.exports = { title: { type: 'string', required: true }, text: { type: 'string', required: true }, type: { type: 'string', isIn: [ - 'online', // deprecated - 'offline', // deprecated - 'online:target:933', - 'online:target:934', - 'online:target:935', - 'online:target:1141', - 'online:corsairs', - 'online:tournament', - 'online:tricks-celebration', - 'online:scheduled-loot', - 'online:triple-shards', 'offline:festival', 'offline:tournament', 'offline:demo', diff --git a/views/elements/event-online-target.ejs b/views/elements/event-online-target.ejs index 46d4c49..8df17de 100644 --- a/views/elements/event-online-target.ejs +++ b/views/elements/event-online-target.ejs @@ -18,9 +18,9 @@ From aee636681a41cd5b483fc50a105e057169a5efe4 Mon Sep 17 00:00:00 2001 From: thefirstspine Date: Sun, 22 Nov 2020 19:51:05 +0100 Subject: [PATCH 2/4] Added calendar service to statuses --- config/locales/en.json | 1 + config/locales/fr.json | 1 + views/pages/arena.ejs | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/config/locales/en.json b/config/locales/en.json index ece7828..969d0b1 100644 --- a/config/locales/en.json +++ b/config/locales/en.json @@ -91,6 +91,7 @@ "arena": "Online games", "auth": "Authentication", "bots": "PvE", + "calendar": "Calendrier", "messaging": "Live notifications", "rest": "Resources", "rooms": "Discussion rooms", diff --git a/config/locales/fr.json b/config/locales/fr.json index 336132e..8aefbe6 100644 --- a/config/locales/fr.json +++ b/config/locales/fr.json @@ -91,6 +91,7 @@ "arena": "Parties en ligne", "auth": "Authentification", "bots": "JcE", + "calendar": "Calendrier", "messaging": "Notifications en direct", "rest": "Ressources", "rooms": "Espaces de discussions", diff --git a/views/pages/arena.ejs b/views/pages/arena.ejs index 8f75d75..988029f 100644 --- a/views/pages/arena.ejs +++ b/views/pages/arena.ejs @@ -107,6 +107,14 @@

+
+
+

<%= __("arena.calendar") %>

+

+ +

+
+

<%= __("arena.messaging") %>

From fd117be3b797566696a1c68db9237388c3bbea7e Mon Sep 17 00:00:00 2001 From: thefirstspine Date: Wed, 25 Nov 2020 17:05:59 +0100 Subject: [PATCH 3/4] Removed scheduled loots --- api/controllers/ScheduledLootController.js | 71 ---------------------- api/models/ScheduledLoot.js | 35 ----------- api/models/UserScheduledLoot.js | 34 ----------- config/policies.js | 2 - config/routes.js | 3 - 5 files changed, 145 deletions(-) delete mode 100644 api/controllers/ScheduledLootController.js delete mode 100644 api/models/ScheduledLoot.js delete mode 100644 api/models/UserScheduledLoot.js diff --git a/api/controllers/ScheduledLootController.js b/api/controllers/ScheduledLootController.js deleted file mode 100644 index edbc4c4..0000000 --- a/api/controllers/ScheduledLootController.js +++ /dev/null @@ -1,71 +0,0 @@ -/** - * ScheduledLootController - * - * @description :: Server-side actions for handling incoming requests. - * @help :: See https://sailsjs.com/docs/concepts/actions - */ - -const fetch = require('node-fetch'); - -module.exports = { - - async index(req, res) { - // Getting the loot of the day - const scheduledLoot = await sails.models.scheduledloot.findOne({ - datetimeFrom: { '<': Date.now() }, - datetimeTo: { '>': Date.now() }, - }); - if (!scheduledLoot) { - return res.notFound(); - } - - // Getting the user-loot relation - const userScheduledLoot = await sails.models.userscheduledloot.findOne({ - scheduledLootId: scheduledLoot.id, - user: req.user_id, - }); - if (userScheduledLoot) { - // User was already rewarded - return res.json( - { - rewarded: false, - scheduledLoot, - } - ); - } - - // Reward the user - const promises = Object.keys(scheduledLoot.loots).map((lootName) => { - return fetch( - `${process.env.ARENA_URL}/wizard/${req.user_id}/reward`, - { - method: 'POST', - body: JSON.stringify({ - name: lootName, - num: scheduledLoot.loots[lootName], - }), - headers: { - 'X-Client-Cert': Buffer.from(process.env.ARENA_PUBLIC_KEY.replace(/\\n/gm, '\n')).toString('base64'), - 'Content-type': 'application/json', - }, - }); - }); - await Promise.all(promises); - - // Create user-loot relation - await sails.models.userscheduledloot.create({ - scheduledLootId: scheduledLoot.id, - user: req.user_id, - }); - - // Send response - return res.json( - { - rewarded: true, - scheduledLoot, - } - ); - } - -}; - diff --git a/api/models/ScheduledLoot.js b/api/models/ScheduledLoot.js deleted file mode 100644 index 4ca80e6..0000000 --- a/api/models/ScheduledLoot.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * ScheduledLoot.js - * - * @description :: A model definition represents a database table/collection. - * @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models - */ - -module.exports = { - - attributes: { - - // ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗ - // ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗ - // ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝ - - loots: { type: 'json', required: true }, - datetimeFrom: { type: 'string', columnType: 'bigint', required: true }, - datetimeTo: { type: 'string', columnType: 'bigint', required: true }, - createdAt: { type: 'number', autoCreatedAt: true }, - updatedAt: { type: 'number', autoUpdatedAt: true }, - - - // ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗ - // ║╣ ║║║╠╩╗║╣ ║║╚═╗ - // ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝ - - - // ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗ - // ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗ - // ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝ - - }, - -}; - diff --git a/api/models/UserScheduledLoot.js b/api/models/UserScheduledLoot.js deleted file mode 100644 index e597d6b..0000000 --- a/api/models/UserScheduledLoot.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * UserScheduledLoot.js - * - * @description :: A model definition represents a database table/collection. - * @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models - */ - -module.exports = { - - attributes: { - - // ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗ - // ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗ - // ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝ - - scheduledLootId: { type: 'number', required: true }, - user: { type: 'number', required: true }, - createdAt: { type: 'number', autoCreatedAt: true }, - updatedAt: { type: 'number', autoUpdatedAt: true }, - - - // ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗ - // ║╣ ║║║╠╩╗║╣ ║║╚═╗ - // ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝ - - - // ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗ - // ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗ - // ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝ - - }, - -}; - diff --git a/config/policies.js b/config/policies.js index 6068109..d798e83 100644 --- a/config/policies.js +++ b/config/policies.js @@ -43,7 +43,5 @@ module.exports.policies = { 'event/findOne':[], 'code/*':['load-user', 'is-logged-in', 'is-admin'], 'refer/*':['load-user', 'is-logged-in', 'is-admin'], - 'scheduledloot/*':['load-user', 'is-logged-in', 'is-admin'], - 'userScheduledloot/*':['load-user', 'is-logged-in', 'is-admin'], }; diff --git a/config/routes.js b/config/routes.js index 0102f4a..e7b8c01 100644 --- a/config/routes.js +++ b/config/routes.js @@ -82,7 +82,4 @@ module.exports.routes = { 'GET /report/:id': 'ReportController.index', 'POST /report/:id': 'ReportController.report', - // Scheduled loots - 'POST /scheduled-loot': 'ScheduledLoot.index', - }; From b900b0359415b4445fd0ceea6cc4034129ff1ddb Mon Sep 17 00:00:00 2001 From: thefirstspine Date: Wed, 25 Nov 2020 17:25:05 +0100 Subject: [PATCH 4/4] Used calendar for cycle loading --- api/helpers/get-cycle.js | 6 ++---- views/pages/homepage.ejs | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/api/helpers/get-cycle.js b/api/helpers/get-cycle.js index 0eca7a1..4198626 100644 --- a/api/helpers/get-cycle.js +++ b/api/helpers/get-cycle.js @@ -11,10 +11,8 @@ module.exports = { fn: async function(inputs, exits) { try { - const baseUrl = process.env ? - process.env.REST_URL : - process.env.REST_URL; - const url = `${baseUrl}/rest/cycles/${inputs.id}`; + const baseUrl = process.env.CALENDAR_URL; + const url = `${baseUrl}/cycles/${inputs.id}`; const result = await fetch(url); const resultJson = await result.json(); return exits.success(resultJson); diff --git a/views/pages/homepage.ejs b/views/pages/homepage.ejs index eaf0268..1a88680 100644 --- a/views/pages/homepage.ejs +++ b/views/pages/homepage.ejs @@ -32,13 +32,13 @@
-
+

<%= __("home.currentCycle") %>

-

<%= cycle.current.name[__("locale")] %>

+

<%= cycle.current[`title_${__("locale")}`] %>

-

<%= cycle.current.description[__("locale")] %>

+

<%= cycle.current[`text_${__("locale")}`] %>

<%= __("home.playOnline") %>