Files
zerobyte/app/server/core/restic.ts
Nico 332e5bffda refactor: extract restic in core package (#651)
* refactor: extract restic in core package

* chore: add turbo task runner

* refactor: split server utils

* chore: simplify withDeps signature and fix non-null assertion
2026-03-11 21:56:07 +01:00

33 lines
1.0 KiB
TypeScript

import { createRestic } from "@zerobyte/core/restic/server";
import type { ResticDeps } from "@zerobyte/core/restic";
import { DEFAULT_EXCLUDES, RESTIC_CACHE_DIR, RESTIC_PASS_FILE } from "./constants";
import { config } from "./config";
import { cryptoUtils } from "../utils/crypto";
import { db } from "../db/db";
export const resticDeps: ResticDeps = {
resolveSecret: cryptoUtils.resolveSecret,
getOrganizationResticPassword: async (organizationId: string) => {
const org = await db.query.organization.findFirst({
where: { id: organizationId },
});
if (!org) {
throw new Error(`Organization ${organizationId} not found`);
}
const metadata = org.metadata as { resticPassword?: string } | null;
if (!metadata?.resticPassword) {
throw new Error(`Restic password not configured for organization ${organizationId}`);
}
return metadata.resticPassword;
},
resticCacheDir: RESTIC_CACHE_DIR,
resticPassFile: RESTIC_PASS_FILE,
defaultExcludes: DEFAULT_EXCLUDES,
hostname: config.resticHostname,
};
export const restic = createRestic(resticDeps);