mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-09-14 10:52:34 +00:00
Convert backend to ESM
- About 5 years overdue - Remove eslint, use bomejs instead
This commit is contained in:
@@ -1,103 +1,98 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const helpers = require('../lib/helpers');
|
||||
const Model = require('objection').Model;
|
||||
const User = require('./user');
|
||||
const AccessListAuth = require('./access_list_auth');
|
||||
const AccessListClient = require('./access_list_client');
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.js";
|
||||
import AccessListAuth from "./access_list_auth.js";
|
||||
import AccessListClient from "./access_list_client.js";
|
||||
import now from "./now_helper.js";
|
||||
import ProxyHostModel from "./proxy_host.js";
|
||||
import User from "./user.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
const boolFields = [
|
||||
'is_deleted',
|
||||
'satisfy_any',
|
||||
'pass_auth',
|
||||
];
|
||||
const boolFields = ["is_deleted", "satisfy_any", "pass_auth"];
|
||||
|
||||
class AccessList extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
}
|
||||
|
||||
$parseDatabaseJson(json) {
|
||||
json = super.$parseDatabaseJson(json);
|
||||
return helpers.convertIntFieldsToBool(json, boolFields);
|
||||
const thisJson = super.$parseDatabaseJson(json);
|
||||
return convertIntFieldsToBool(thisJson, boolFields);
|
||||
}
|
||||
|
||||
$formatDatabaseJson(json) {
|
||||
json = helpers.convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(json);
|
||||
const thisJson = convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(thisJson);
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'AccessList';
|
||||
static get name() {
|
||||
return "AccessList";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'access_list';
|
||||
static get tableName() {
|
||||
return "access_list";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['meta'];
|
||||
static get jsonAttributes() {
|
||||
return ["meta"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
const ProxyHost = require('./proxy_host');
|
||||
|
||||
static get relationMappings() {
|
||||
return {
|
||||
owner: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'access_list.owner_user_id',
|
||||
to: 'user.id'
|
||||
join: {
|
||||
from: "access_list.owner_user_id",
|
||||
to: "user.id",
|
||||
},
|
||||
modify: (qb) => {
|
||||
qb.where("user.is_deleted", 0);
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('user.is_deleted', 0);
|
||||
}
|
||||
},
|
||||
items: {
|
||||
relation: Model.HasManyRelation,
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: AccessListAuth,
|
||||
join: {
|
||||
from: 'access_list.id',
|
||||
to: 'access_list_auth.access_list_id'
|
||||
}
|
||||
join: {
|
||||
from: "access_list.id",
|
||||
to: "access_list_auth.access_list_id",
|
||||
},
|
||||
},
|
||||
clients: {
|
||||
relation: Model.HasManyRelation,
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: AccessListClient,
|
||||
join: {
|
||||
from: 'access_list.id',
|
||||
to: 'access_list_client.access_list_id'
|
||||
}
|
||||
join: {
|
||||
from: "access_list.id",
|
||||
to: "access_list_client.access_list_id",
|
||||
},
|
||||
},
|
||||
proxy_hosts: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: ProxyHost,
|
||||
join: {
|
||||
from: 'access_list.id',
|
||||
to: 'proxy_host.access_list_id'
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: ProxyHostModel,
|
||||
join: {
|
||||
from: "access_list.id",
|
||||
to: "proxy_host.access_list_id",
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('proxy_host.is_deleted', 0);
|
||||
}
|
||||
}
|
||||
modify: (qb) => {
|
||||
qb.where("proxy_host.is_deleted", 0);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AccessList;
|
||||
export default AccessList;
|
||||
|
@@ -1,54 +1,55 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const Model = require('objection').Model;
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import accessListModel from "./access_list.js";
|
||||
import now from "./now_helper.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
class AccessListAuth extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'AccessListAuth';
|
||||
static get name() {
|
||||
return "AccessListAuth";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'access_list_auth';
|
||||
static get tableName() {
|
||||
return "access_list_auth";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['meta'];
|
||||
static get jsonAttributes() {
|
||||
return ["meta"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
static get relationMappings() {
|
||||
return {
|
||||
access_list: {
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: require('./access_list'),
|
||||
join: {
|
||||
from: 'access_list_auth.access_list_id',
|
||||
to: 'access_list.id'
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: accessListModel,
|
||||
join: {
|
||||
from: "access_list_auth.access_list_id",
|
||||
to: "access_list.id",
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('access_list.is_deleted', 0);
|
||||
}
|
||||
}
|
||||
modify: (qb) => {
|
||||
qb.where("access_list.is_deleted", 0);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AccessListAuth;
|
||||
export default AccessListAuth;
|
||||
|
@@ -1,54 +1,55 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const Model = require('objection').Model;
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import accessListModel from "./access_list.js";
|
||||
import now from "./now_helper.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
class AccessListClient extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'AccessListClient';
|
||||
static get name() {
|
||||
return "AccessListClient";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'access_list_client';
|
||||
static get tableName() {
|
||||
return "access_list_client";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['meta'];
|
||||
static get jsonAttributes() {
|
||||
return ["meta"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
static get relationMappings() {
|
||||
return {
|
||||
access_list: {
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: require('./access_list'),
|
||||
join: {
|
||||
from: 'access_list_client.access_list_id',
|
||||
to: 'access_list.id'
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: accessListModel,
|
||||
join: {
|
||||
from: "access_list_client.access_list_id",
|
||||
to: "access_list.id",
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('access_list.is_deleted', 0);
|
||||
}
|
||||
}
|
||||
modify: (qb) => {
|
||||
qb.where("access_list.is_deleted", 0);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AccessListClient;
|
||||
export default AccessListClient;
|
||||
|
@@ -1,52 +1,52 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const Model = require('objection').Model;
|
||||
const User = require('./user');
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import now from "./now_helper.js";
|
||||
import User from "./user.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
class AuditLog extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'AuditLog';
|
||||
static get name() {
|
||||
return "AuditLog";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'audit_log';
|
||||
static get tableName() {
|
||||
return "audit_log";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['meta'];
|
||||
static get jsonAttributes() {
|
||||
return ["meta"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
static get relationMappings() {
|
||||
return {
|
||||
user: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'audit_log.user_id',
|
||||
to: 'user.id'
|
||||
}
|
||||
}
|
||||
join: {
|
||||
from: "audit_log.user_id",
|
||||
to: "user.id",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuditLog;
|
||||
export default AuditLog;
|
||||
|
@@ -1,59 +1,53 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const bcrypt = require('bcrypt');
|
||||
const db = require('../db');
|
||||
const helpers = require('../lib/helpers');
|
||||
const Model = require('objection').Model;
|
||||
const User = require('./user');
|
||||
const now = require('./now_helper');
|
||||
import bcrypt from "bcrypt";
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.js";
|
||||
import now from "./now_helper.js";
|
||||
import User from "./user.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
const boolFields = [
|
||||
'is_deleted',
|
||||
];
|
||||
const boolFields = ["is_deleted"];
|
||||
|
||||
function encryptPassword () {
|
||||
/* jshint -W040 */
|
||||
let _this = this;
|
||||
|
||||
if (_this.type === 'password' && _this.secret) {
|
||||
return bcrypt.hash(_this.secret, 13)
|
||||
.then(function (hash) {
|
||||
_this.secret = hash;
|
||||
});
|
||||
function encryptPassword() {
|
||||
if (this.type === "password" && this.secret) {
|
||||
return bcrypt.hash(this.secret, 13).then((hash) => {
|
||||
this.secret = hash;
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
class Auth extends Model {
|
||||
$beforeInsert (queryContext) {
|
||||
this.created_on = now();
|
||||
$beforeInsert(queryContext) {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
|
||||
return encryptPassword.apply(this, queryContext);
|
||||
}
|
||||
|
||||
$beforeUpdate (queryContext) {
|
||||
$beforeUpdate(queryContext) {
|
||||
this.modified_on = now();
|
||||
return encryptPassword.apply(this, queryContext);
|
||||
}
|
||||
|
||||
$parseDatabaseJson(json) {
|
||||
json = super.$parseDatabaseJson(json);
|
||||
return helpers.convertIntFieldsToBool(json, boolFields);
|
||||
const thisJson = super.$parseDatabaseJson(json);
|
||||
return convertIntFieldsToBool(thisJson, boolFields);
|
||||
}
|
||||
|
||||
$formatDatabaseJson(json) {
|
||||
json = helpers.convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(json);
|
||||
const thisJson = convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(thisJson);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,37 +56,37 @@ class Auth extends Model {
|
||||
* @param {String} password
|
||||
* @returns {Promise}
|
||||
*/
|
||||
verifyPassword (password) {
|
||||
verifyPassword(password) {
|
||||
return bcrypt.compare(password, this.secret);
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'Auth';
|
||||
static get name() {
|
||||
return "Auth";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'auth';
|
||||
static get tableName() {
|
||||
return "auth";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['meta'];
|
||||
static get jsonAttributes() {
|
||||
return ["meta"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
static get relationMappings() {
|
||||
return {
|
||||
user: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'auth.user_id',
|
||||
to: 'user.id'
|
||||
join: {
|
||||
from: "auth.user_id",
|
||||
to: "user.id",
|
||||
},
|
||||
filter: {
|
||||
is_deleted: 0
|
||||
}
|
||||
}
|
||||
is_deleted: 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Auth;
|
||||
export default Auth;
|
||||
|
@@ -1,124 +1,121 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const helpers = require('../lib/helpers');
|
||||
const Model = require('objection').Model;
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.js";
|
||||
import deadHostModel from "./dead_host.js";
|
||||
import now from "./now_helper.js";
|
||||
import proxyHostModel from "./proxy_host.js";
|
||||
import redirectionHostModel from "./redirection_host.js";
|
||||
import userModel from "./user.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
const boolFields = [
|
||||
'is_deleted',
|
||||
];
|
||||
const boolFields = ["is_deleted"];
|
||||
|
||||
class Certificate extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for expires_on
|
||||
if (typeof this.expires_on === 'undefined') {
|
||||
if (typeof this.expires_on === "undefined") {
|
||||
this.expires_on = now();
|
||||
}
|
||||
|
||||
// Default for domain_names
|
||||
if (typeof this.domain_names === 'undefined') {
|
||||
if (typeof this.domain_names === "undefined") {
|
||||
this.domain_names = [];
|
||||
}
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
|
||||
this.domain_names.sort();
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
|
||||
// Sort domain_names
|
||||
if (typeof this.domain_names !== 'undefined') {
|
||||
if (typeof this.domain_names !== "undefined") {
|
||||
this.domain_names.sort();
|
||||
}
|
||||
}
|
||||
|
||||
$parseDatabaseJson(json) {
|
||||
json = super.$parseDatabaseJson(json);
|
||||
return helpers.convertIntFieldsToBool(json, boolFields);
|
||||
const thisJson = super.$parseDatabaseJson(json);
|
||||
return convertIntFieldsToBool(thisJson, boolFields);
|
||||
}
|
||||
|
||||
$formatDatabaseJson(json) {
|
||||
json = helpers.convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(json);
|
||||
const thisJson = convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(thisJson);
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'Certificate';
|
||||
static get name() {
|
||||
return "Certificate";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'certificate';
|
||||
static get tableName() {
|
||||
return "certificate";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['domain_names', 'meta'];
|
||||
static get jsonAttributes() {
|
||||
return ["domain_names", "meta"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
const ProxyHost = require('./proxy_host');
|
||||
const DeadHost = require('./dead_host');
|
||||
const User = require('./user');
|
||||
const RedirectionHost = require('./redirection_host');
|
||||
|
||||
static get relationMappings() {
|
||||
return {
|
||||
owner: {
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'certificate.owner_user_id',
|
||||
to: 'user.id'
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: userModel,
|
||||
join: {
|
||||
from: "certificate.owner_user_id",
|
||||
to: "user.id",
|
||||
},
|
||||
modify: (qb) => {
|
||||
qb.where("user.is_deleted", 0);
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('user.is_deleted', 0);
|
||||
}
|
||||
},
|
||||
proxy_hosts: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: ProxyHost,
|
||||
join: {
|
||||
from: 'certificate.id',
|
||||
to: 'proxy_host.certificate_id'
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: proxyHostModel,
|
||||
join: {
|
||||
from: "certificate.id",
|
||||
to: "proxy_host.certificate_id",
|
||||
},
|
||||
modify: (qb) => {
|
||||
qb.where("proxy_host.is_deleted", 0);
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('proxy_host.is_deleted', 0);
|
||||
}
|
||||
},
|
||||
dead_hosts: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: DeadHost,
|
||||
join: {
|
||||
from: 'certificate.id',
|
||||
to: 'dead_host.certificate_id'
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: deadHostModel,
|
||||
join: {
|
||||
from: "certificate.id",
|
||||
to: "dead_host.certificate_id",
|
||||
},
|
||||
modify: (qb) => {
|
||||
qb.where("dead_host.is_deleted", 0);
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('dead_host.is_deleted', 0);
|
||||
}
|
||||
},
|
||||
redirection_hosts: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: RedirectionHost,
|
||||
join: {
|
||||
from: 'certificate.id',
|
||||
to: 'redirection_host.certificate_id'
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: redirectionHostModel,
|
||||
join: {
|
||||
from: "certificate.id",
|
||||
to: "redirection_host.certificate_id",
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('redirection_host.is_deleted', 0);
|
||||
}
|
||||
}
|
||||
modify: (qb) => {
|
||||
qb.where("redirection_host.is_deleted", 0);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Certificate;
|
||||
export default Certificate;
|
||||
|
@@ -1,99 +1,92 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const helpers = require('../lib/helpers');
|
||||
const Model = require('objection').Model;
|
||||
const User = require('./user');
|
||||
const Certificate = require('./certificate');
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.js";
|
||||
import Certificate from "./certificate.js";
|
||||
import now from "./now_helper.js";
|
||||
import User from "./user.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
const boolFields = [
|
||||
'is_deleted',
|
||||
'ssl_forced',
|
||||
'http2_support',
|
||||
'enabled',
|
||||
'hsts_enabled',
|
||||
'hsts_subdomains',
|
||||
];
|
||||
const boolFields = ["is_deleted", "ssl_forced", "http2_support", "enabled", "hsts_enabled", "hsts_subdomains"];
|
||||
|
||||
class DeadHost extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for domain_names
|
||||
if (typeof this.domain_names === 'undefined') {
|
||||
if (typeof this.domain_names === "undefined") {
|
||||
this.domain_names = [];
|
||||
}
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
|
||||
this.domain_names.sort();
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
|
||||
// Sort domain_names
|
||||
if (typeof this.domain_names !== 'undefined') {
|
||||
if (typeof this.domain_names !== "undefined") {
|
||||
this.domain_names.sort();
|
||||
}
|
||||
}
|
||||
|
||||
$parseDatabaseJson(json) {
|
||||
json = super.$parseDatabaseJson(json);
|
||||
return helpers.convertIntFieldsToBool(json, boolFields);
|
||||
const thisJson = super.$parseDatabaseJson(json);
|
||||
return convertIntFieldsToBool(thisJson, boolFields);
|
||||
}
|
||||
|
||||
$formatDatabaseJson(json) {
|
||||
json = helpers.convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(json);
|
||||
const thisJson = convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(thisJson);
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'DeadHost';
|
||||
static get name() {
|
||||
return "DeadHost";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'dead_host';
|
||||
static get tableName() {
|
||||
return "dead_host";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['domain_names', 'meta'];
|
||||
static get jsonAttributes() {
|
||||
return ["domain_names", "meta"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
static get relationMappings() {
|
||||
return {
|
||||
owner: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'dead_host.owner_user_id',
|
||||
to: 'user.id'
|
||||
join: {
|
||||
from: "dead_host.owner_user_id",
|
||||
to: "user.id",
|
||||
},
|
||||
modify: (qb) => {
|
||||
qb.where("user.is_deleted", 0);
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('user.is_deleted', 0);
|
||||
}
|
||||
},
|
||||
certificate: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: Certificate,
|
||||
join: {
|
||||
from: 'dead_host.certificate_id',
|
||||
to: 'certificate.id'
|
||||
join: {
|
||||
from: "dead_host.certificate_id",
|
||||
to: "certificate.id",
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('certificate.is_deleted', 0);
|
||||
}
|
||||
}
|
||||
modify: (qb) => {
|
||||
qb.where("certificate.is_deleted", 0);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DeadHost;
|
||||
export default DeadHost;
|
||||
|
@@ -1,13 +1,12 @@
|
||||
const db = require('../db');
|
||||
const config = require('../lib/config');
|
||||
const Model = require('objection').Model;
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import { isSqlite } from "../lib/config.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
module.exports = function () {
|
||||
if (config.isSqlite()) {
|
||||
// eslint-disable-next-line
|
||||
export default () => {
|
||||
if (isSqlite()) {
|
||||
return Model.raw("datetime('now','localtime')");
|
||||
}
|
||||
return Model.raw('NOW()');
|
||||
return Model.raw("NOW()");
|
||||
};
|
||||
|
@@ -1,114 +1,114 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const helpers = require('../lib/helpers');
|
||||
const Model = require('objection').Model;
|
||||
const User = require('./user');
|
||||
const AccessList = require('./access_list');
|
||||
const Certificate = require('./certificate');
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.js";
|
||||
import AccessList from "./access_list.js";
|
||||
import Certificate from "./certificate.js";
|
||||
import now from "./now_helper.js";
|
||||
import User from "./user.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
const boolFields = [
|
||||
'is_deleted',
|
||||
'ssl_forced',
|
||||
'caching_enabled',
|
||||
'block_exploits',
|
||||
'allow_websocket_upgrade',
|
||||
'http2_support',
|
||||
'enabled',
|
||||
'hsts_enabled',
|
||||
'hsts_subdomains',
|
||||
"is_deleted",
|
||||
"ssl_forced",
|
||||
"caching_enabled",
|
||||
"block_exploits",
|
||||
"allow_websocket_upgrade",
|
||||
"http2_support",
|
||||
"enabled",
|
||||
"hsts_enabled",
|
||||
"hsts_subdomains",
|
||||
];
|
||||
|
||||
class ProxyHost extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for domain_names
|
||||
if (typeof this.domain_names === 'undefined') {
|
||||
if (typeof this.domain_names === "undefined") {
|
||||
this.domain_names = [];
|
||||
}
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
|
||||
this.domain_names.sort();
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
|
||||
// Sort domain_names
|
||||
if (typeof this.domain_names !== 'undefined') {
|
||||
if (typeof this.domain_names !== "undefined") {
|
||||
this.domain_names.sort();
|
||||
}
|
||||
}
|
||||
|
||||
$parseDatabaseJson(json) {
|
||||
json = super.$parseDatabaseJson(json);
|
||||
return helpers.convertIntFieldsToBool(json, boolFields);
|
||||
const thisJson = super.$parseDatabaseJson(json);
|
||||
return convertIntFieldsToBool(thisJson, boolFields);
|
||||
}
|
||||
|
||||
$formatDatabaseJson(json) {
|
||||
json = helpers.convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(json);
|
||||
const thisJson = convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(thisJson);
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'ProxyHost';
|
||||
static get name() {
|
||||
return "ProxyHost";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'proxy_host';
|
||||
static get tableName() {
|
||||
return "proxy_host";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['domain_names', 'meta', 'locations'];
|
||||
static get jsonAttributes() {
|
||||
return ["domain_names", "meta", "locations"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
static get relationMappings() {
|
||||
return {
|
||||
owner: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'proxy_host.owner_user_id',
|
||||
to: 'user.id'
|
||||
join: {
|
||||
from: "proxy_host.owner_user_id",
|
||||
to: "user.id",
|
||||
},
|
||||
modify: (qb) => {
|
||||
qb.where("user.is_deleted", 0);
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('user.is_deleted', 0);
|
||||
}
|
||||
},
|
||||
access_list: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: AccessList,
|
||||
join: {
|
||||
from: 'proxy_host.access_list_id',
|
||||
to: 'access_list.id'
|
||||
join: {
|
||||
from: "proxy_host.access_list_id",
|
||||
to: "access_list.id",
|
||||
},
|
||||
modify: (qb) => {
|
||||
qb.where("access_list.is_deleted", 0);
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('access_list.is_deleted', 0);
|
||||
}
|
||||
},
|
||||
certificate: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: Certificate,
|
||||
join: {
|
||||
from: 'proxy_host.certificate_id',
|
||||
to: 'certificate.id'
|
||||
join: {
|
||||
from: "proxy_host.certificate_id",
|
||||
to: "certificate.id",
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('certificate.is_deleted', 0);
|
||||
}
|
||||
}
|
||||
modify: (qb) => {
|
||||
qb.where("certificate.is_deleted", 0);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ProxyHost;
|
||||
export default ProxyHost;
|
||||
|
@@ -1,102 +1,101 @@
|
||||
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const helpers = require('../lib/helpers');
|
||||
const Model = require('objection').Model;
|
||||
const User = require('./user');
|
||||
const Certificate = require('./certificate');
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.js";
|
||||
import Certificate from "./certificate.js";
|
||||
import now from "./now_helper.js";
|
||||
import User from "./user.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
const boolFields = [
|
||||
'is_deleted',
|
||||
'enabled',
|
||||
'preserve_path',
|
||||
'ssl_forced',
|
||||
'block_exploits',
|
||||
'hsts_enabled',
|
||||
'hsts_subdomains',
|
||||
'http2_support',
|
||||
"is_deleted",
|
||||
"enabled",
|
||||
"preserve_path",
|
||||
"ssl_forced",
|
||||
"block_exploits",
|
||||
"hsts_enabled",
|
||||
"hsts_subdomains",
|
||||
"http2_support",
|
||||
];
|
||||
|
||||
class RedirectionHost extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for domain_names
|
||||
if (typeof this.domain_names === 'undefined') {
|
||||
if (typeof this.domain_names === "undefined") {
|
||||
this.domain_names = [];
|
||||
}
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
|
||||
this.domain_names.sort();
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
|
||||
// Sort domain_names
|
||||
if (typeof this.domain_names !== 'undefined') {
|
||||
if (typeof this.domain_names !== "undefined") {
|
||||
this.domain_names.sort();
|
||||
}
|
||||
}
|
||||
|
||||
$parseDatabaseJson(json) {
|
||||
json = super.$parseDatabaseJson(json);
|
||||
return helpers.convertIntFieldsToBool(json, boolFields);
|
||||
const thisJson = super.$parseDatabaseJson(json);
|
||||
return convertIntFieldsToBool(thisJson, boolFields);
|
||||
}
|
||||
|
||||
$formatDatabaseJson(json) {
|
||||
json = helpers.convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(json);
|
||||
const thisJson = convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(thisJson);
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'RedirectionHost';
|
||||
static get name() {
|
||||
return "RedirectionHost";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'redirection_host';
|
||||
static get tableName() {
|
||||
return "redirection_host";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['domain_names', 'meta'];
|
||||
static get jsonAttributes() {
|
||||
return ["domain_names", "meta"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
static get relationMappings() {
|
||||
return {
|
||||
owner: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'redirection_host.owner_user_id',
|
||||
to: 'user.id'
|
||||
join: {
|
||||
from: "redirection_host.owner_user_id",
|
||||
to: "user.id",
|
||||
},
|
||||
modify: (qb) => {
|
||||
qb.where("user.is_deleted", 0);
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('user.is_deleted', 0);
|
||||
}
|
||||
},
|
||||
certificate: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: Certificate,
|
||||
join: {
|
||||
from: 'redirection_host.certificate_id',
|
||||
to: 'certificate.id'
|
||||
join: {
|
||||
from: "redirection_host.certificate_id",
|
||||
to: "certificate.id",
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('certificate.is_deleted', 0);
|
||||
}
|
||||
}
|
||||
modify: (qb) => {
|
||||
qb.where("certificate.is_deleted", 0);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RedirectionHost;
|
||||
export default RedirectionHost;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const Model = require('objection').Model;
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
@@ -27,4 +27,4 @@ class Setting extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Setting;
|
||||
export default Setting;
|
||||
|
@@ -1,82 +1,77 @@
|
||||
const Model = require('objection').Model;
|
||||
const db = require('../db');
|
||||
const helpers = require('../lib/helpers');
|
||||
const User = require('./user');
|
||||
const Certificate = require('./certificate');
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.js";
|
||||
import Certificate from "./certificate.js";
|
||||
import now from "./now_helper.js";
|
||||
import User from "./user.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
const boolFields = [
|
||||
'is_deleted',
|
||||
'enabled',
|
||||
'tcp_forwarding',
|
||||
'udp_forwarding',
|
||||
];
|
||||
const boolFields = ["is_deleted", "enabled", "tcp_forwarding", "udp_forwarding"];
|
||||
|
||||
class Stream extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for meta
|
||||
if (typeof this.meta === 'undefined') {
|
||||
if (typeof this.meta === "undefined") {
|
||||
this.meta = {};
|
||||
}
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
}
|
||||
|
||||
$parseDatabaseJson(json) {
|
||||
json = super.$parseDatabaseJson(json);
|
||||
return helpers.convertIntFieldsToBool(json, boolFields);
|
||||
const thisJson = super.$parseDatabaseJson(json);
|
||||
return convertIntFieldsToBool(thisJson, boolFields);
|
||||
}
|
||||
|
||||
$formatDatabaseJson(json) {
|
||||
json = helpers.convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(json);
|
||||
const thisJson = convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(thisJson);
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'Stream';
|
||||
static get name() {
|
||||
return "Stream";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'stream';
|
||||
static get tableName() {
|
||||
return "stream";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['meta'];
|
||||
static get jsonAttributes() {
|
||||
return ["meta"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
static get relationMappings() {
|
||||
return {
|
||||
owner: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'stream.owner_user_id',
|
||||
to: 'user.id'
|
||||
join: {
|
||||
from: "stream.owner_user_id",
|
||||
to: "user.id",
|
||||
},
|
||||
modify: (qb) => {
|
||||
qb.where("user.is_deleted", 0);
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('user.is_deleted', 0);
|
||||
}
|
||||
},
|
||||
certificate: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: Certificate,
|
||||
join: {
|
||||
from: 'stream.certificate_id',
|
||||
to: 'certificate.id'
|
||||
join: {
|
||||
from: "stream.certificate_id",
|
||||
to: "certificate.id",
|
||||
},
|
||||
modify: function (qb) {
|
||||
qb.where('certificate.is_deleted', 0);
|
||||
}
|
||||
}
|
||||
modify: (qb) => {
|
||||
qb.where("certificate.is_deleted", 0);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Stream;
|
||||
export default Stream;
|
||||
|
@@ -3,16 +3,16 @@
|
||||
and then has abilities after that.
|
||||
*/
|
||||
|
||||
const _ = require('lodash');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const crypto = require('crypto');
|
||||
const config = require('../lib/config');
|
||||
const error = require('../lib/error');
|
||||
const logger = require('../logger').global;
|
||||
const ALGO = 'RS256';
|
||||
import crypto from "node:crypto";
|
||||
import jwt from "jsonwebtoken";
|
||||
import _ from "lodash";
|
||||
import { getPrivateKey, getPublicKey } from "../lib/config.js";
|
||||
import errs from "../lib/error.js";
|
||||
import { global as logger } from "../logger.js";
|
||||
|
||||
module.exports = function () {
|
||||
const ALGO = "RS256";
|
||||
|
||||
export default () => {
|
||||
let token_data = {};
|
||||
|
||||
const self = {
|
||||
@@ -21,28 +21,26 @@ module.exports = function () {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
create: (payload) => {
|
||||
if (!config.getPrivateKey()) {
|
||||
logger.error('Private key is empty!');
|
||||
if (!getPrivateKey()) {
|
||||
logger.error("Private key is empty!");
|
||||
}
|
||||
// sign with RSA SHA256
|
||||
const options = {
|
||||
algorithm: ALGO,
|
||||
expiresIn: payload.expiresIn || '1d'
|
||||
expiresIn: payload.expiresIn || "1d",
|
||||
};
|
||||
|
||||
payload.jti = crypto.randomBytes(12)
|
||||
.toString('base64')
|
||||
.substring(-8);
|
||||
payload.jti = crypto.randomBytes(12).toString("base64").substring(-8);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
jwt.sign(payload, config.getPrivateKey(), options, (err, token) => {
|
||||
jwt.sign(payload, getPrivateKey(), options, (err, token) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
token_data = payload;
|
||||
resolve({
|
||||
token: token,
|
||||
payload: payload
|
||||
token: token,
|
||||
payload: payload,
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -53,42 +51,47 @@ module.exports = function () {
|
||||
* @param {String} token
|
||||
* @returns {Promise}
|
||||
*/
|
||||
load: function (token) {
|
||||
if (!config.getPublicKey()) {
|
||||
logger.error('Public key is empty!');
|
||||
load: (token) => {
|
||||
if (!getPublicKey()) {
|
||||
logger.error("Public key is empty!");
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (!token || token === null || token === 'null') {
|
||||
reject(new error.AuthError('Empty token'));
|
||||
if (!token || token === null || token === "null") {
|
||||
reject(new errs.AuthError("Empty token"));
|
||||
} else {
|
||||
jwt.verify(token, config.getPublicKey(), {ignoreExpiration: false, algorithms: [ALGO]}, (err, result) => {
|
||||
if (err) {
|
||||
|
||||
if (err.name === 'TokenExpiredError') {
|
||||
reject(new error.AuthError('Token has expired', err));
|
||||
jwt.verify(
|
||||
token,
|
||||
getPublicKey(),
|
||||
{ ignoreExpiration: false, algorithms: [ALGO] },
|
||||
(err, result) => {
|
||||
if (err) {
|
||||
if (err.name === "TokenExpiredError") {
|
||||
reject(new errs.AuthError("Token has expired", err));
|
||||
} else {
|
||||
reject(err);
|
||||
}
|
||||
} else {
|
||||
reject(err);
|
||||
token_data = result;
|
||||
|
||||
// Hack: some tokens out in the wild have a scope of 'all' instead of 'user'.
|
||||
// For 30 days at least, we need to replace 'all' with user.
|
||||
if (
|
||||
typeof token_data.scope !== "undefined" &&
|
||||
_.indexOf(token_data.scope, "all") !== -1
|
||||
) {
|
||||
token_data.scope = ["user"];
|
||||
}
|
||||
|
||||
resolve(token_data);
|
||||
}
|
||||
|
||||
} else {
|
||||
token_data = result;
|
||||
|
||||
// Hack: some tokens out in the wild have a scope of 'all' instead of 'user'.
|
||||
// For 30 days at least, we need to replace 'all' with user.
|
||||
if ((typeof token_data.scope !== 'undefined' && _.indexOf(token_data.scope, 'all') !== -1)) {
|
||||
token_data.scope = ['user'];
|
||||
}
|
||||
|
||||
resolve(token_data);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -97,16 +100,14 @@ module.exports = function () {
|
||||
* @param {String} scope
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
hasScope: function (scope) {
|
||||
return typeof token_data.scope !== 'undefined' && _.indexOf(token_data.scope, scope) !== -1;
|
||||
},
|
||||
hasScope: (scope) => typeof token_data.scope !== "undefined" && _.indexOf(token_data.scope, scope) !== -1,
|
||||
|
||||
/**
|
||||
* @param {String} key
|
||||
* @return {*}
|
||||
*/
|
||||
get: function (key) {
|
||||
if (typeof token_data[key] !== 'undefined') {
|
||||
get: (key) => {
|
||||
if (typeof token_data[key] !== "undefined") {
|
||||
return token_data[key];
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ module.exports = function () {
|
||||
* @param {String} key
|
||||
* @param {*} value
|
||||
*/
|
||||
set: function (key, value) {
|
||||
set: (key, value) => {
|
||||
token_data[key] = value;
|
||||
},
|
||||
|
||||
@@ -126,13 +127,13 @@ module.exports = function () {
|
||||
* @returns {Integer}
|
||||
*/
|
||||
getUserId: (default_value) => {
|
||||
const attrs = self.get('attrs');
|
||||
if (attrs && typeof attrs.id !== 'undefined' && attrs.id) {
|
||||
const attrs = self.get("attrs");
|
||||
if (attrs && typeof attrs.id !== "undefined" && attrs.id) {
|
||||
return attrs.id;
|
||||
}
|
||||
|
||||
return default_value || 0;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return self;
|
||||
|
@@ -1,69 +1,65 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const helpers = require('../lib/helpers');
|
||||
const Model = require('objection').Model;
|
||||
const UserPermission = require('./user_permission');
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.js";
|
||||
import now from "./now_helper.js";
|
||||
import UserPermission from "./user_permission.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
const boolFields = [
|
||||
'is_deleted',
|
||||
'is_disabled',
|
||||
];
|
||||
const boolFields = ["is_deleted", "is_disabled"];
|
||||
|
||||
class User extends Model {
|
||||
$beforeInsert () {
|
||||
this.created_on = now();
|
||||
$beforeInsert() {
|
||||
this.created_on = now();
|
||||
this.modified_on = now();
|
||||
|
||||
// Default for roles
|
||||
if (typeof this.roles === 'undefined') {
|
||||
if (typeof this.roles === "undefined") {
|
||||
this.roles = [];
|
||||
}
|
||||
}
|
||||
|
||||
$beforeUpdate () {
|
||||
$beforeUpdate() {
|
||||
this.modified_on = now();
|
||||
}
|
||||
|
||||
$parseDatabaseJson(json) {
|
||||
json = super.$parseDatabaseJson(json);
|
||||
return helpers.convertIntFieldsToBool(json, boolFields);
|
||||
const thisJson = super.$parseDatabaseJson(json);
|
||||
return convertIntFieldsToBool(thisJson, boolFields);
|
||||
}
|
||||
|
||||
$formatDatabaseJson(json) {
|
||||
json = helpers.convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(json);
|
||||
const thisJson = convertBoolFieldsToInt(json, boolFields);
|
||||
return super.$formatDatabaseJson(thisJson);
|
||||
}
|
||||
|
||||
static get name () {
|
||||
return 'User';
|
||||
static get name() {
|
||||
return "User";
|
||||
}
|
||||
|
||||
static get tableName () {
|
||||
return 'user';
|
||||
static get tableName() {
|
||||
return "user";
|
||||
}
|
||||
|
||||
static get jsonAttributes () {
|
||||
return ['roles'];
|
||||
static get jsonAttributes() {
|
||||
return ["roles"];
|
||||
}
|
||||
|
||||
static get relationMappings () {
|
||||
static get relationMappings() {
|
||||
return {
|
||||
permissions: {
|
||||
relation: Model.HasOneRelation,
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: UserPermission,
|
||||
join: {
|
||||
from: 'user.id',
|
||||
to: 'user_permission.user_id'
|
||||
}
|
||||
}
|
||||
join: {
|
||||
from: "user.id",
|
||||
to: "user_permission.user_id",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = User;
|
||||
export default User;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
// Objection Docs:
|
||||
// http://vincit.github.io/objection.js/
|
||||
|
||||
const db = require('../db');
|
||||
const Model = require('objection').Model;
|
||||
const now = require('./now_helper');
|
||||
import { Model } from "objection";
|
||||
import db from "../db.js";
|
||||
import now from "./now_helper.js";
|
||||
|
||||
Model.knex(db);
|
||||
|
||||
@@ -26,4 +26,4 @@ class UserPermission extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserPermission;
|
||||
export default UserPermission;
|
||||
|
Reference in New Issue
Block a user