diff options
author | Raphael <mail@raphaelkabo.com> | 2024-02-25 21:30:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-25 21:30:46 +0000 |
commit | afd9fc4477fff90e5db917f350d99c3d01fba2bd (patch) | |
tree | 76eb4af4467e9169e97593b2b991be1bddb1a260 /src | |
parent | 7ff0bebd9fbdf1c982d7cc42a7057d36a3e2486a (diff) | |
parent | 1bb89ca09d097c704885c42920efea0f6624dc20 (diff) |
Merge pull request #134 from lowercasename/rk/permanent-events
Set number of days to store concluded events (including permanently!)
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/config.ts | 29 | ||||
-rwxr-xr-x | src/routes.js | 8 |
2 files changed, 32 insertions, 5 deletions
diff --git a/src/lib/config.ts b/src/lib/config.ts index 93c04df..1029be9 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -14,6 +14,7 @@ interface GathioConfig { port: string; email: string; site_name: string; + delete_after_days: number | null; is_federated: boolean; email_logo_url: string; show_kofi: boolean; @@ -32,7 +33,7 @@ interface GathioConfig { sendgrid?: { api_key: string; }; - static_pages: StaticPage[]; + static_pages?: StaticPage[]; } interface FrontendConfig { @@ -42,10 +43,27 @@ interface FrontendConfig { emailLogoUrl: string; showKofi: boolean; showInstanceInformation: boolean; - staticPages: StaticPage[]; + staticPages?: StaticPage[]; version: string; } +const defaultConfig: GathioConfig = { + general: { + domain: "localhost:3000", + email: "contact@example.com", + port: "3000", + site_name: "gathio", + is_federated: true, + delete_after_days: 7, + email_logo_url: "", + show_kofi: false, + mail_service: "nodemailer", + }, + database: { + mongodb_url: "mongodb://localhost:27017/gathio", + }, +}; + export const frontendConfig = (): FrontendConfig => { const config = getConfig(); return { @@ -54,7 +72,7 @@ export const frontendConfig = (): FrontendConfig => { isFederated: config.general.is_federated, emailLogoUrl: config.general.email_logo_url, showKofi: config.general.show_kofi, - showInstanceInformation: config.static_pages?.length > 0, + showInstanceInformation: !!config.static_pages?.length, staticPages: config.static_pages, version: process.env.npm_package_version || "unknown", }; @@ -67,7 +85,10 @@ export const getConfig = (): GathioConfig => { const config = toml.parse( fs.readFileSync("./config/config.toml", "utf-8"), ) as GathioConfig; - return config; + return { + ...defaultConfig, + ...config, + }; } catch { exitWithError( "Configuration file not found! Have you renamed './config/config-example.toml' to './config/config.toml'?", diff --git a/src/routes.js b/src/routes.js index ab12a3a..8ea7e05 100755 --- a/src/routes.js +++ b/src/routes.js @@ -82,7 +82,13 @@ router.use(fileUpload()); // SCHEDULED DELETION schedule.scheduleJob("59 23 * * *", function (fireDate) { - const too_old = moment.tz("Etc/UTC").subtract(7, "days").toDate(); + const deleteAfterDays = config.general.delete_after_days; + if (!deleteAfterDays || deleteAfterDays <= 0) { + // Deletion is disabled + return; + } + + const too_old = moment.tz("Etc/UTC").subtract(deleteAfterDays, "days").toDate(); console.log( "Old event deletion running! Deleting all events concluding before ", too_old, |