Skip to content

Commit

Permalink
Merge pull request #117 from thefirstspine/next
Browse files Browse the repository at this point in the history
Release 3.4.0
  • Loading branch information
thefirstspine authored Jul 16, 2024
2 parents a14f857 + 304fc38 commit e7b6c74
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 132 deletions.
28 changes: 28 additions & 0 deletions api/controllers/GoController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* CodesController
*
* @description :: Server-side actions for handling incoming requests.
* @help :: See https://sailsjs.com/docs/concepts/actions
*/

const { default: axios } = require("axios");

module.exports = {

async index(req, res) {
const code = req.params?.code;
if (!code) {
return res.redirect(301, '/');
}

const link = await sails.models.link.findOne({code});
if (!link) {
return res.redirect(301, '/');
}

await sails.models.linkclick.create({ code, ip: req.ip, userAgant: req.headers?['user-agent'] ?? req.headers['user-agent'] : 'unknown' });
return res.redirect(301, link.url);
},

};

2 changes: 1 addition & 1 deletion api/helpers/get-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
try {
const baseUrl = process.env.CALENDAR_URL;
const date = (new Date()).toISOString();
const url = `${baseUrl}/events?filter=datetimeTo||gt||${date}&sort=datetimeFrom,ASC`;
const url = `${baseUrl}/events/next`;
const result = await axios.get(url);
const resultJson = result.data;
return exits.success(resultJson);
Expand Down
33 changes: 33 additions & 0 deletions api/models/Link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Code.js
*
* @description :: A model definition represents a database table/collection.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/

module.exports = {

attributes: {

// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝

code: { type: 'string', required: true },
url: { type: 'string', required: true },
createdAt: { type: 'number', autoCreatedAt: true },
updatedAt: { type: 'number', autoUpdatedAt: true },

// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝


// ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝

},

};

34 changes: 34 additions & 0 deletions api/models/LinkClick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Code.js
*
* @description :: A model definition represents a database table/collection.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/

module.exports = {

attributes: {

// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝

code: { type: 'string', required: true },
ip: { type: 'string' },
userAgent: { type: 'string' },
createdAt: { type: 'number', autoCreatedAt: true },
updatedAt: { type: 'number', autoUpdatedAt: true },

// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝


// ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝

},

};

1 change: 1 addition & 0 deletions config/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ module.exports.policies = {
'code/*':['load-user', 'is-logged-in', 'is-admin'],
'mailinglist/*':['load-user', 'is-logged-in', 'is-admin'],
'steamcode/*':['load-user', 'is-logged-in', 'is-admin'],
'link/*':['load-user', 'is-logged-in', 'is-admin'],

};
2 changes: 2 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ module.exports.routes = {
'GET /report/:id': 'ReportController.index',
'POST /report/:id': 'ReportController.report',

// Go
'GET /go/:code': 'GoController.index',
};
Loading

0 comments on commit e7b6c74

Please sign in to comment.