mirror of
https://github.com/docmost/docmost.git
synced 2025-11-17 14:21:08 +10:00
Refactoring
* replace TypeORM with Kysely query builder * refactor migrations * other changes and fixes
This commit is contained in:
@ -1,17 +0,0 @@
|
||||
import { DataSource, EntityManager } from 'typeorm';
|
||||
|
||||
export async function transactionWrapper(
|
||||
operation: (...args) => any,
|
||||
datasource: DataSource,
|
||||
entityManager: EntityManager,
|
||||
): Promise<any> {
|
||||
if (entityManager) {
|
||||
return await operation(entityManager);
|
||||
} else {
|
||||
return await datasource.manager.transaction(
|
||||
async (manager: EntityManager) => {
|
||||
return await operation(manager);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,7 @@
|
||||
import { join } from 'path';
|
||||
import * as path from 'path';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
|
||||
export const envPath = path.resolve(process.cwd(), '..', '..', '.env');
|
||||
|
||||
export function generateHostname(name: string): string {
|
||||
let hostname = name.replace(/[^a-z0-9]/gi, '').toLowerCase();
|
||||
@ -6,4 +9,18 @@ export function generateHostname(name: string): string {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
export const envPath = join(__dirname, '..', '..', '..', '.env');
|
||||
export async function hashPassword(password: string) {
|
||||
const saltRounds = 12;
|
||||
return bcrypt.hash(password, saltRounds);
|
||||
}
|
||||
|
||||
export async function comparePasswordHash(
|
||||
plainPassword: string,
|
||||
passwordHash: string,
|
||||
): Promise<boolean> {
|
||||
return bcrypt.compare(plainPassword, passwordHash);
|
||||
}
|
||||
|
||||
export function getRandomInt(min = 4, max = 5) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user