websockets implemented
This commit is contained in:
@@ -2,7 +2,7 @@ import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import User from './user.js';
|
||||
import UserParamType from '../type/user_param.js';
|
||||
import { encrypt, decrypt, generateIv } from '../../utils/encryption.js';
|
||||
import { encrypt, decrypt } from '../../utils/encryption.js';
|
||||
|
||||
const UserParam = sequelize.define('user_param', {
|
||||
userId: {
|
||||
@@ -10,45 +10,43 @@ const UserParam = sequelize.define('user_param', {
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: User,
|
||||
key: 'id'
|
||||
}
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
paramTypeId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: UserParamType,
|
||||
key: 'id'
|
||||
}
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
value: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
set(value) {
|
||||
console.log('.... [set param value]', value);
|
||||
if (value) {
|
||||
try {
|
||||
const iv = generateIv();
|
||||
this.setDataValue('iv', iv.toString('hex'));
|
||||
this.setDataValue('value', encrypt(value.toString(), iv));
|
||||
const encrypted = encrypt(value.toString());
|
||||
console.log('.... [encrypted param value]', encrypted);
|
||||
this.setDataValue('value', encrypted);
|
||||
} catch (error) {
|
||||
this.setDataValue('value', '');
|
||||
console.error('.... Error encrypting param value:', error);
|
||||
this.setDataValue('value', '');
|
||||
}
|
||||
}
|
||||
},
|
||||
get() {
|
||||
try {
|
||||
const value = this.getDataValue('value');
|
||||
const iv = Buffer.from(this.getDataValue('iv'), 'hex');
|
||||
return decrypt(value, iv);
|
||||
const value = this.getDataValue('value');
|
||||
return decrypt(value);
|
||||
} catch (error) {
|
||||
console.error('.... Error decrypting param value:', error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
iv: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'user_param',
|
||||
schema: 'community',
|
||||
@@ -56,9 +54,9 @@ const UserParam = sequelize.define('user_param', {
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['user_id', 'param_type_id']
|
||||
}
|
||||
]
|
||||
fields: ['user_id', 'param_type_id'],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export default UserParam;
|
||||
|
||||
Reference in New Issue
Block a user