Skip to content

Commit

Permalink
feat: set number of days to store concluded events (including permane…
Browse files Browse the repository at this point in the history
…ntly)
  • Loading branch information
lowercasename committed Feb 25, 2024
1 parent b17238e commit 3965dd1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ port = "3000"
email = "[email protected]"
site_name = "gathio"
is_federated = true
# Events will be deleted this many days after they have ended. Set to 0 to
# disable automatic deletion (old events will never be deleted).
delete_after_days = 7
# If left blank, this defaults to
# https://yourdomain.com/images/gathio-email-logo.gif. Set a full URL here to
# change it to your own logo (or just change the file itself).
Expand Down
29 changes: 25 additions & 4 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@ interface GathioConfig {
sendgrid?: {
api_key: string;
};
static_pages: StaticPage[];
static_pages?: StaticPage[];
}

interface FrontendConfig {
Expand All @@ -41,10 +42,27 @@ interface FrontendConfig {
emailLogoUrl: string;
showKofi: boolean;
showInstanceInformation: boolean;
staticPages: StaticPage[];
staticPages?: StaticPage[];
version: string;
}

const defaultConfig: GathioConfig = {
general: {
domain: "localhost:3000",
email: "[email protected]",
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 {
Expand All @@ -53,7 +71,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",
};
Expand All @@ -66,7 +84,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'?",
Expand Down
8 changes: 7 additions & 1 deletion src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3965dd1

Please sign in to comment.