-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconfig.ts
More file actions
71 lines (54 loc) · 2.26 KB
/
Copy pathconfig.ts
File metadata and controls
71 lines (54 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import 'dotenv/config';
import fs from 'fs';
import path from 'path';
type Environment = 'development' | 'production';
export type EnvironmentName = 'stage' | 'prod' | 'development';
export const TRPC_WS_PATH = `/trpc/ws`;
const ONE_KB_IN_BYTES = 1000;
const ONE_MB_IN_BYTES = ONE_KB_IN_BYTES * 1000;
const ONE_GB_IN_BYTES = ONE_MB_IN_BYTES * 1000;
const appConfig = {
file_dir: `/tmp/send-suite-dev-dir`,
max_file_size: ONE_GB_IN_BYTES * 20, // 20 GB
};
const packageJson = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8')
);
export const VERSION = packageJson.version as string;
const ENVIRONMENT = process.env.NODE_ENV || ('development' as Environment);
const BASE_URL = process.env.BASE_URL;
export const IS_ENV_DEV = ENVIRONMENT === 'development';
export const IS_ENV_PROD = ENVIRONMENT === 'production';
export const IS_ENV_TEST = process.env.NODE_ENV === 'test';
export const IS_USING_BUCKET_STORAGE = process.env.STORAGE_BACKEND !== 'fs';
// Time constants
const ONE_MINUTE = 60 * 1000;
const ONE_HOUR = ONE_MINUTE * 60;
const ONE_DAY = 1;
const ONE_WEEK = ONE_DAY * 7;
// File expiry time in days
export const DAYS_TO_EXPIRY = 15;
// We're not enforcing the limit right now, we only use it to display a value on the frontend
const ONE_TB_IN_BYTES = 1 * 1_000 * 1_000 * 1_000 * 1_000; // 1 TB (roughly)
export const TOTAL_STORAGE_LIMIT = ONE_TB_IN_BYTES;
// JWT expiry
export const JWT_EXPIRY_IN_MILLISECONDS = ONE_HOUR;
export const JWT_REFRESH_TOKEN_EXPIRY_IN_DAYS = ONE_WEEK;
// Determines how many times a file can be attempted to be downloaded with the wrong password before it gets locked
export const MAX_ACCESS_LINK_RETRIES = 5;
// Response header that tells the client its session is gone and it should clear
// local auth and return to login (#960). Lives here (a dependency-light module)
// so both the Express middleware and the tRPC middleware can import it without
// pulling in the heavier models/prisma graph.
export const X_LOGOUT_HEADER = 'x-logout';
export function getEnvironmentName(): EnvironmentName {
if (BASE_URL.includes('send-backend.tb.pro')) {
return 'prod';
}
if (BASE_URL.includes('send-backend-stage.tb.pro')) {
return 'stage';
}
return 'development';
}
export { ENVIRONMENT };
export default appConfig;