restructure directories

* set log level based on env
This commit is contained in:
Philipinho
2024-06-09 15:57:52 +01:00
parent 2e61fb7c11
commit d4eefa48a8
49 changed files with 124 additions and 82 deletions

View File

@ -0,0 +1,2 @@
export const APP_DATA_PATH = 'data';
export const LOCAL_STORAGE_PATH = `${APP_DATA_PATH}/storage`;

View File

@ -0,0 +1,7 @@
import * as mime from 'mime-types';
import * as path from 'node:path';
export function getMimeType(filePath: string): string {
const ext = path.extname(filePath);
return mime.contentType(ext) || 'application/octet-stream';
}

View File

@ -0,0 +1,4 @@
export * from './utils';
export * from './nanoid.utils';
export * from './file.helper';
export * from './constants';

View File

@ -0,0 +1,9 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { customAlphabet } = require('fix-esm').require('nanoid');
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
export const nanoIdGen = customAlphabet(alphabet, 10);
const slugIdAlphabet =
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
export const generateSlugId = customAlphabet(slugIdAlphabet, 12);

View File

@ -0,0 +1,16 @@
export enum UserRole {
OWNER = 'owner',
ADMIN = 'admin', // can have owner permissions but cannot delete workspace
MEMBER = 'member',
}
export enum SpaceRole {
ADMIN = 'admin', // can manage space settings, members, and delete space
WRITER = 'writer', // can read and write pages in space
READER = 'reader', // can only read pages in space
}
export enum SpaceVisibility {
OPEN = 'open', // any workspace member can see that it exists and join.
PRIVATE = 'private', // only added space users can see
}

View File

@ -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);
};
}