Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ AUTH_PASSKEY_ENABLED=true
# Retention
RETENTION_CRON="* * * * *"

# Optional prefix for backup files stored in configured storage channels.
# Defaults to "backups" when unset.
#BACKUP_FILE_PREFIX=backups

TRUSTED_DOMAINS="http://localhost:8887, http://localhost:3055, http://localhost:3056"

#OPENAPI_ENABLED=true
Expand Down
8 changes: 8 additions & 0 deletions src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import packageJson from "../package.json" with {type: "json"};

const {version} = packageJson;

export function getBackupFilePrefix() {
const separator = String.fromCharCode(47);
return env.BACKUP_FILE_PREFIX?.trim().split(separator).filter(Boolean).join(separator) || "backups";
}

export const env = createEnv({
emptyStringAsUndefined: true,
server: {
Expand Down Expand Up @@ -66,6 +71,8 @@ export const env = createEnv({

STALE_BACKUP_THRESHOLD_HOURS: z.coerce.number().default(6),

BACKUP_FILE_PREFIX: z.string().optional(),

AUTH_OIDC_ID: z.string().optional().default("oidc"),
AUTH_OIDC_TITLE: z.string().optional(),
AUTH_OIDC_DESC: z.string().optional(),
Expand Down Expand Up @@ -154,6 +161,7 @@ export const env = createEnv({
RETENTION_CRON: process.env.RETENTION_CRON,
CLEANING_HEALTHCHECK_LOGS_CRON: process.env.CLEANING_HEALTHCHECK_LOGS_CRON,
STALE_BACKUP_THRESHOLD_HOURS: process.env.STALE_BACKUP_THRESHOLD_HOURS,
BACKUP_FILE_PREFIX: process.env.BACKUP_FILE_PREFIX,

AUTH_OIDC_ID: process.env.AUTH_OIDC_ID,
AUTH_OIDC_TITLE: process.env.AUTH_OIDC_TITLE,
Expand Down
6 changes: 6 additions & 0 deletions src/features/agents/utils/status/storage-channels.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as drizzleDb from "@/db";
import {db} from "@/db";
import {eq} from "drizzle-orm";
import {getBackupFilePrefix} from "@/env";

export type PingDatabaseStorageChannels = {
id: string;
config: any
provider: string
prefix: string
}

export async function getDatabaseStorageChannels(databaseId: string): Promise<PingDatabaseStorageChannels[]> {
Expand All @@ -24,6 +26,8 @@ export async function getDatabaseStorageChannels(databaseId: string): Promise<Pi
return []
}

const prefix = getBackupFilePrefix();

const settings = await db.query.setting.findFirst({
where: eq(drizzleDb.schemas.setting.name, "system"),
with: {storageChannel: true},
Expand All @@ -34,6 +38,7 @@ export async function getDatabaseStorageChannels(databaseId: string): Promise<Pi
id: settings.storageChannel.id,
provider: settings.storageChannel.provider,
config: settings.storageChannel.config,
prefix,
}]
: [];

Expand All @@ -52,6 +57,7 @@ export async function getDatabaseStorageChannels(databaseId: string): Promise<Pi
id: storageChannel.id,
config: storageChannel.config,
provider: storageChannel.provider,
prefix,
} as PingDatabaseStorageChannels;
})
);
Expand Down
3 changes: 2 additions & 1 deletion src/features/storages/utils/storages.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {db} from "@/db";
import {createHash} from "crypto";
import {getServerUrl} from "@/utils/get-server-url";
import path from "path";
import {getBackupFilePrefix} from "@/env";

function computeChecksum(buffer: Buffer): string {
return createHash("sha256").update(buffer).digest("hex");
Expand Down Expand Up @@ -55,7 +56,7 @@ export async function storeBackupFiles(
return [];
}

const path = `backups/${database.project?.slug}/${fileName}`;
const path = `${getBackupFilePrefix()}/${database.project?.slug}/${fileName}`;
const size = file.length;
const checksum = computeChecksum(file);

Expand Down