mirror of
https://github.com/docmost/docmost.git
synced 2026-05-08 07:13:06 +08:00
restructure directories
* set log level based on env
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import * as path from 'path';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
|
||||
export const envPath = path.resolve(process.cwd(), '..', '..', '.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 type RedisConfig = {
|
||||
host: string;
|
||||
port: number;
|
||||
password?: string;
|
||||
};
|
||||
|
||||
export function parseRedisUrl(redisUrl: string): RedisConfig {
|
||||
// format - redis[s]://[[username][:password]@][host][:port][/db-number]
|
||||
const { hostname, port, password } = new URL(redisUrl);
|
||||
const portInt = parseInt(port, 10);
|
||||
|
||||
return { host: hostname, port: portInt, password };
|
||||
}
|
||||
|
||||
export function createRetryStrategy() {
|
||||
return function (times: number): number {
|
||||
return Math.max(Math.min(Math.exp(times), 20000), 3000);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user