mirror of
https://github.com/zadam/trilium.git
synced 2026-05-06 15:45:47 +02:00
refactor(backup): pass in options service directly
This commit is contained in:
@@ -13,8 +13,8 @@ export default class StandaloneBackupService extends BackupService {
|
||||
private backupDir: FileSystemDirectoryHandle | null = null;
|
||||
private opfsAvailable: boolean | null = null;
|
||||
|
||||
constructor(getOptions: () => BackupOptionsService) {
|
||||
super(getOptions);
|
||||
constructor(options: BackupOptionsService) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
private isOpfsAvailable(): boolean {
|
||||
|
||||
@@ -176,7 +176,7 @@ async function initialize(): Promise<void> {
|
||||
request: new FetchRequestProvider(),
|
||||
platform: new StandalonePlatformProvider(queryString),
|
||||
log: logService,
|
||||
backup: new StandaloneBackupService(() => coreModule!.options),
|
||||
backup: new StandaloneBackupService(coreModule!.options),
|
||||
translations: translationProvider,
|
||||
schema: schemaModule.default,
|
||||
getDemoArchive: async () => {
|
||||
|
||||
@@ -130,7 +130,7 @@ beforeAll(async () => {
|
||||
});
|
||||
},
|
||||
platform: new StandalonePlatformProvider(""),
|
||||
backup: new StandaloneBackupService(() => options),
|
||||
backup: new StandaloneBackupService(options),
|
||||
schema: schemaSql,
|
||||
dbConfig: {
|
||||
provider: sqlProvider,
|
||||
|
||||
@@ -151,7 +151,7 @@ async function main() {
|
||||
// both source and bundled-production modes.
|
||||
getDemoArchive: async () => fs.readFileSync(path.join(RESOURCE_DIR, "db", "demo.zip")),
|
||||
inAppHelp: new NodejsInAppHelpProvider(),
|
||||
backup: new ServerBackupService(() => options),
|
||||
backup: new ServerBackupService(options),
|
||||
image: (await import("@triliumnext/server/src/services/image_provider.js")).serverImageProvider,
|
||||
extraAppInfo: {
|
||||
nodeVersion: process.version,
|
||||
|
||||
@@ -44,6 +44,6 @@ beforeAll(async () => {
|
||||
platform: new ServerPlatformProvider(),
|
||||
translations: initializeTranslationsWithParams,
|
||||
inAppHelp: new NodejsInAppHelpProvider(),
|
||||
backup: new ServerBackupService(() => options)
|
||||
backup: new ServerBackupService(options)
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,8 +8,8 @@ import log from "./services/log.js";
|
||||
import sql from "./services/sql.js";
|
||||
|
||||
export default class ServerBackupService extends BackupService {
|
||||
constructor(getOptions: () => BackupOptionsService) {
|
||||
super(getOptions);
|
||||
constructor(options: BackupOptionsService) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
override getExistingBackups(): DatabaseBackup[] {
|
||||
|
||||
@@ -81,7 +81,7 @@ async function startApplication() {
|
||||
// both source and bundled-production modes.
|
||||
getDemoArchive: async () => fs.readFileSync(path.join(RESOURCE_DIR, "db", "demo.zip")),
|
||||
inAppHelp: new NodejsInAppHelpProvider(),
|
||||
backup: new ServerBackupService(() => options),
|
||||
backup: new ServerBackupService(options),
|
||||
image: (await import("./services/image_provider.js")).serverImageProvider,
|
||||
extraAppInfo: {
|
||||
nodeVersion: process.version,
|
||||
|
||||
@@ -15,7 +15,7 @@ export interface BackupOptionsService {
|
||||
* Platform-specific implementations must extend this class.
|
||||
*/
|
||||
export default abstract class BackupService {
|
||||
constructor(protected readonly getOptions: () => BackupOptionsService) {}
|
||||
constructor(protected readonly options: BackupOptionsService) {}
|
||||
|
||||
/**
|
||||
* Create a backup with the given name.
|
||||
@@ -59,7 +59,7 @@ export default abstract class BackupService {
|
||||
backupType === "weekly" ? "weeklyBackupEnabled" :
|
||||
"monthlyBackupEnabled";
|
||||
|
||||
return this.getOptions().getOptionBool(optionName);
|
||||
return this.options.getOptionBool(optionName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,13 +74,12 @@ export default abstract class BackupService {
|
||||
return;
|
||||
}
|
||||
|
||||
const options = this.getOptions();
|
||||
const now = new Date();
|
||||
const lastBackupDate = dateUtils.parseDateTime(options.getOption(optionName));
|
||||
const lastBackupDate = dateUtils.parseDateTime(this.options.getOption(optionName));
|
||||
|
||||
if (now.getTime() - lastBackupDate.getTime() > periodInSeconds * 1000) {
|
||||
await this.backupNow(backupType);
|
||||
options.setOption(optionName, dateUtils.utcNowDateTime());
|
||||
this.options.setOption(optionName, dateUtils.utcNowDateTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user