server/utils/config.ts

362 lines
5.8 KiB
TypeScript
Raw Normal View History

2023-09-11 05:31:08 +02:00
import data from "../config/config.toml";
2023-09-11 05:46:20 +02:00
export interface ConfigType {
2023-09-11 05:31:08 +02:00
database: {
host: string;
port: number;
username: string;
password: string;
database: string;
2023-09-13 02:29:13 +02:00
};
2023-09-15 03:22:27 +02:00
2023-11-27 02:40:44 +01:00
redis: {
queue: {
host: string;
port: number;
password: string;
2023-11-27 06:30:57 +01:00
database: number | null;
2023-11-27 02:40:44 +01:00
};
2023-12-02 00:00:00 +01:00
cache: {
host: string;
port: number;
password: string;
database: number | null;
enabled: boolean;
};
2023-11-27 02:40:44 +01:00
};
meilisearch: {
host: string;
port: number;
api_key: string;
enabled: boolean;
};
oidc: {
providers: {
name: string;
id: string;
url: string;
client_id: string;
client_secret: string;
icon: string;
}[];
};
2023-09-11 05:54:14 +02:00
http: {
base_url: string;
bind: string;
bind_port: string;
banned_ips: string[];
2023-09-13 02:29:13 +02:00
};
2023-09-15 03:22:27 +02:00
instance: {
name: string;
description: string;
banner: string;
logo: string;
};
2023-10-17 21:12:53 +02:00
smtp: {
server: string;
port: number;
username: string;
password: string;
tls: boolean;
};
2023-09-13 07:30:45 +02:00
validation: {
max_displayname_size: number;
max_bio_size: number;
max_username_size: number;
max_note_size: number;
2023-09-13 21:02:16 +02:00
max_avatar_size: number;
max_header_size: number;
2023-09-13 07:30:45 +02:00
max_media_size: number;
max_media_attachments: number;
max_media_description_size: number;
max_poll_options: number;
max_poll_option_size: number;
min_poll_duration: number;
max_poll_duration: number;
2023-09-13 07:30:45 +02:00
username_blacklist: string[];
blacklist_tempmail: boolean;
email_blacklist: string[];
url_scheme_whitelist: string[];
enforce_mime_types: boolean;
allowed_mime_types: string[];
2023-09-13 07:30:45 +02:00
};
2023-09-15 03:22:27 +02:00
2023-10-17 21:12:53 +02:00
media: {
backend: string;
deduplicate_media: boolean;
conversion: {
convert_images: boolean;
convert_to: string;
};
};
s3: {
endpoint: string;
access_key: string;
secret_access_key: string;
region: string;
bucket_name: string;
public_url: string;
};
defaults: {
visibility: string;
language: string;
avatar: string;
header: string;
};
2023-10-17 21:12:53 +02:00
email: {
send_on_report: boolean;
send_on_suspend: boolean;
send_on_unsuspend: boolean;
};
2023-09-15 03:22:27 +02:00
activitypub: {
use_tombstones: boolean;
2023-09-18 07:38:08 +02:00
reject_activities: string[];
force_followers_only: string[];
discard_reports: string[];
discard_deletes: string[];
discard_banners: string[];
discard_avatars: string[];
2023-10-16 08:04:03 +02:00
discard_updates: string[];
discard_follows: string[];
2023-09-18 07:38:08 +02:00
force_sensitive: string[];
remove_media: string[];
2023-10-23 02:23:15 +02:00
fetch_all_collection_members: boolean;
2023-10-16 08:07:39 +02:00
authorized_fetch: boolean;
2023-09-15 03:22:27 +02:00
};
2023-09-15 05:21:38 +02:00
filters: {
note_filters: string[];
username_filters: string[];
displayname_filters: string[];
bio_filters: string[];
emoji_filters: string[];
};
logging: {
log_requests: boolean;
log_requests_verbose: boolean;
log_filters: boolean;
};
ratelimits: {
duration_coeff: number;
max_coeff: number;
};
custom_ratelimits: Record<
string,
{
duration: number;
max: number;
}
>;
2023-09-13 02:29:13 +02:00
[key: string]: unknown;
2023-09-11 05:31:08 +02:00
}
2023-09-15 03:22:27 +02:00
export const configDefaults: ConfigType = {
http: {
bind: "http://0.0.0.0",
bind_port: "8000",
2023-10-17 00:03:29 +02:00
base_url: "http://lysand.localhost:8000",
banned_ips: [],
2023-09-15 03:22:27 +02:00
},
database: {
host: "localhost",
port: 5432,
username: "postgres",
password: "postgres",
2023-09-15 07:08:59 +02:00
database: "lysand",
2023-09-15 03:22:27 +02:00
},
2023-11-27 02:40:44 +01:00
redis: {
queue: {
host: "localhost",
port: 6379,
password: "",
2023-12-02 00:00:00 +01:00
database: 0,
},
cache: {
host: "localhost",
port: 6379,
password: "",
database: 1,
enabled: false,
2023-11-27 02:40:44 +01:00
},
},
meilisearch: {
host: "localhost",
port: 1491,
api_key: "",
enabled: false,
},
oidc: {
providers: [],
},
instance: {
banner: "",
description: "",
logo: "",
name: "",
},
2023-10-17 21:12:53 +02:00
smtp: {
password: "",
port: 465,
server: "",
tls: true,
username: "",
},
media: {
backend: "local",
deduplicate_media: true,
conversion: {
convert_images: false,
convert_to: "webp",
},
},
email: {
send_on_report: false,
send_on_suspend: false,
send_on_unsuspend: false,
},
s3: {
access_key: "",
bucket_name: "",
endpoint: "",
public_url: "",
region: "",
secret_access_key: "",
},
2023-09-15 03:22:27 +02:00
validation: {
max_displayname_size: 50,
max_bio_size: 6000,
max_note_size: 5000,
max_avatar_size: 5_000_000,
max_header_size: 5_000_000,
max_media_size: 40_000_000,
max_media_attachments: 10,
2023-09-15 03:22:27 +02:00
max_media_description_size: 1000,
max_poll_options: 20,
max_poll_option_size: 500,
min_poll_duration: 60,
max_poll_duration: 1893456000,
2023-09-15 03:22:27 +02:00
max_username_size: 30,
username_blacklist: [
".well-known",
"~",
"about",
"activities",
"api",
"auth",
"dev",
"inbox",
"internal",
"main",
"media",
"nodeinfo",
"notice",
"oauth",
"objects",
"proxy",
"push",
"registration",
"relay",
"settings",
"status",
"tag",
"users",
"web",
"search",
"mfa",
],
blacklist_tempmail: false,
email_blacklist: [],
url_scheme_whitelist: [
"http",
"https",
"ftp",
"dat",
"dweb",
"gopher",
"hyper",
"ipfs",
"ipns",
"irc",
"xmpp",
"ircs",
"magnet",
"mailto",
"mumble",
"ssb",
],
enforce_mime_types: false,
allowed_mime_types: [],
2023-09-15 03:22:27 +02:00
},
defaults: {
visibility: "public",
language: "en",
avatar: "",
header: "",
},
2023-09-15 03:22:27 +02:00
activitypub: {
use_tombstones: true,
2023-09-18 07:38:08 +02:00
reject_activities: [],
force_followers_only: [],
discard_reports: [],
discard_deletes: [],
discard_banners: [],
discard_avatars: [],
force_sensitive: [],
2023-10-16 08:04:03 +02:00
discard_updates: [],
discard_follows: [],
2023-09-18 07:38:08 +02:00
remove_media: [],
2023-10-23 02:23:15 +02:00
fetch_all_collection_members: false,
2023-10-16 08:07:39 +02:00
authorized_fetch: false,
2023-09-15 03:22:27 +02:00
},
2023-09-15 05:21:38 +02:00
filters: {
note_filters: [],
username_filters: [],
displayname_filters: [],
bio_filters: [],
emoji_filters: [],
},
logging: {
log_requests: false,
log_requests_verbose: false,
log_filters: true,
},
ratelimits: {
duration_coeff: 1,
max_coeff: 1,
},
custom_ratelimits: {},
2023-09-15 03:22:27 +02:00
};
2023-09-11 05:31:08 +02:00
export const getConfig = () => {
2023-09-15 03:22:27 +02:00
return {
...configDefaults,
...(data as ConfigType),
};
2023-09-13 02:29:13 +02:00
};
2023-09-11 05:54:14 +02:00
export const getHost = () => {
const url = new URL(getConfig().http.base_url);
return url.host;
2023-09-13 02:29:13 +02:00
};