Nikky 4 years ago
parent
commit
d62cc582c9
  1. 2
      src/config/database.config.js
  2. 34
      src/logic/spam.js
  3. 10
      src/logic/utils.js
  4. 10
      src/model/user.model.js

2
src/config/database.config.js

@ -1,4 +1,6 @@
// https://sequelize.org/master/manual/getting-started.html#connecting-to-a-database
export const DatabaseConfig = {
dialect: 'sqlite',
storage: './database.sqlite',

34
src/logic/spam.js

@ -0,0 +1,34 @@
export class CacheTable{
constructor(threshold){
this.entries = {};
this.count = 0;
this.threshold = threshold || 1024;
}
set(key, val){
if(this.entries[key] === undefined){
if(this.count < this.threshold){
this.count++;
}else{
for(var otherKey in this.entries){
delete this.entries[otherKey];
break;
}
}
}
this.entries[key] = val;
}
remove(key){
if(this.entries[key] !== undefined){
delete this.entries[key];
this.count--;
}
}
get(key){ return this.entries[key]; }
allEntries(){ return this.entries; }
}
export class SpamTable{
}

10
src/logic/utils.js

@ -9,7 +9,7 @@ export function checkStringParam(param, min, max){
export function errorOut(reply, msg, code){
reply.code(code || 400);
reply.send(msg) || 'Bad request.';
reply.send(msg || 'Bad request.');
}
export function reverseString(str){
@ -24,11 +24,3 @@ export function notYet(date){
if(!date) return false;
return (new Date() <= date);
}
// export class CacheTable{
// constructor(){
// this.data = {};
// }
// }

10
src/model/user.model.js

@ -1,5 +1,10 @@
import Sequelize from 'sequelize';
/**
* @param {Object} props
* @param {import('sequelize/types').Sequelize} props.db
*/
const UserEntity = ({db}) => (
db.define('Users', {
uuid: {type: Sequelize.DataTypes.UUID, defaultValue: Sequelize.UUIDV4},
@ -15,6 +20,11 @@ const UserEntity = ({db}) => (
restoreCode: Sequelize.TEXT,
restoreExpiry: Sequelize.DATE
}, {
indexes: [
{ fields: ['token'], unique: true },
{ fields: ['email'], unique: true }
]
})
);

Loading…
Cancel
Save