mirror of
https://github.com/docmost/docmost.git
synced 2025-11-21 09:01:16 +10:00
restructure directories
* set log level based on env
This commit is contained in:
2
apps/server/src/common/helpers/constants.ts
Normal file
2
apps/server/src/common/helpers/constants.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export const APP_DATA_PATH = 'data';
|
||||
export const LOCAL_STORAGE_PATH = `${APP_DATA_PATH}/storage`;
|
||||
7
apps/server/src/common/helpers/file.helper.ts
Normal file
7
apps/server/src/common/helpers/file.helper.ts
Normal 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';
|
||||
}
|
||||
4
apps/server/src/common/helpers/index.ts
Normal file
4
apps/server/src/common/helpers/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './utils';
|
||||
export * from './nanoid.utils';
|
||||
export * from './file.helper';
|
||||
export * from './constants';
|
||||
9
apps/server/src/common/helpers/nanoid.utils.ts
Normal file
9
apps/server/src/common/helpers/nanoid.utils.ts
Normal 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);
|
||||
16
apps/server/src/common/helpers/types/permission.ts
Normal file
16
apps/server/src/common/helpers/types/permission.ts
Normal 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
|
||||
}
|
||||
36
apps/server/src/common/helpers/utils.ts
Normal file
36
apps/server/src/common/helpers/utils.ts
Normal 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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user