Lint files

This commit is contained in:
Andras Schmelczer 2024-12-20 16:14:46 +00:00
parent 2f7cad602a
commit ff5af8aea5
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
11 changed files with 184 additions and 276 deletions

View file

@ -1,4 +1,4 @@
import { TAbstractFile } from "obsidian";
import type { TAbstractFile } from "obsidian";
export interface FileEventHandler {
onCreate: (path: TAbstractFile) => Promise<void>;

View file

@ -1,57 +1,48 @@
import { TAbstractFile, TFile } from "obsidian";
import { FileEventHandler } from "./file-event-handler";
import { Logger } from "src/logger";
import { SyncService } from "src/services/sync-service";
import { Database } from "src/database/database";
import type { TAbstractFile } from "obsidian";
import { TFile } from "obsidian";
import type { FileEventHandler } from "./file-event-handler";
import type { SyncService } from "src/services/sync-service";
import type { Database } from "src/database/database";
import { syncLocallyDeletedFile } from "src/sync-operations/sync-locally-deleted-file";
import { syncLocallyUpdatedFile } from "src/sync-operations/sync-locally-updated-file";
import { FileOperations } from "src/file-operations/file-operations";
import type { FileOperations } from "src/file-operations/file-operations";
import { syncLocallyCreatedFile } from "src/sync-operations/sync-locally-created-file";
import { Logger } from "src/tracing/logger";
import type { SyncHistory } from "src/tracing/sync-history";
export class SyncEventHandler implements FileEventHandler {
export class ObsidianFileEventHandler implements FileEventHandler {
public constructor(
private database: Database,
private syncServer: SyncService,
private operations: FileOperations
private readonly database: Database,
private readonly syncServer: SyncService,
private readonly operations: FileOperations,
private readonly history: SyncHistory
) {}
async onCreate(file: TAbstractFile): Promise<void> {
public async onCreate(file: TAbstractFile): Promise<void> {
if (file instanceof TFile) {
Logger.getInstance().info(`File created: ${file.path}`);
if (!this.database.getSettings().isSyncEnabled) {
Logger.getInstance().info(
`Sync is disabled, not syncing ${file.path}`
);
return;
}
await syncLocallyCreatedFile({
database: this.database,
syncServer: this.syncServer,
operations: this.operations,
updateTime: new Date(file.stat.ctime),
filePath: file.path,
relativePath: file.path,
history: this.history,
});
} else {
Logger.getInstance().info(`Folder created: ${file.path}, ignored`);
}
}
async onDelete(file: TAbstractFile): Promise<void> {
public async onDelete(file: TAbstractFile): Promise<void> {
if (file instanceof TFile) {
Logger.getInstance().info(`File deleted: ${file.path}`);
if (!this.database.getSettings().isSyncEnabled) {
Logger.getInstance().info(
`Sync is disabled, not syncing ${file.path}`
);
return;
}
await syncLocallyDeletedFile({
database: this.database,
syncServer: this.syncServer,
history: this.history,
relativePath: file.path,
});
} else {
@ -59,25 +50,19 @@ export class SyncEventHandler implements FileEventHandler {
}
}
async onRename(file: TAbstractFile, oldPath: string): Promise<void> {
public async onRename(file: TAbstractFile, oldPath: string): Promise<void> {
if (file instanceof TFile) {
Logger.getInstance().info(
`File renamed: ${oldPath} -> ${file.path}`
);
if (!this.database.getSettings().isSyncEnabled) {
Logger.getInstance().info(
`Sync is disabled, not syncing ${file.path}`
);
return;
}
await syncLocallyUpdatedFile({
database: this.database,
syncServer: this.syncServer,
operations: this.operations,
history: this.history,
updateTime: new Date(file.stat.ctime),
filePath: file.path,
relativePath: file.path,
oldPath,
});
} else {
@ -87,23 +72,17 @@ export class SyncEventHandler implements FileEventHandler {
}
}
async onModify(file: TAbstractFile): Promise<void> {
public async onModify(file: TAbstractFile): Promise<void> {
if (file instanceof TFile) {
Logger.getInstance().info(`File modified: ${file.path}`);
if (!this.database.getSettings().isSyncEnabled) {
Logger.getInstance().info(
`Sync is disabled, not syncing ${file.path}`
);
return;
}
await syncLocallyUpdatedFile({
database: this.database,
syncServer: this.syncServer,
operations: this.operations,
history: this.history,
updateTime: new Date(file.stat.ctime),
filePath: file.path,
relativePath: file.path,
});
} else {
Logger.getInstance().info(`Folder modified: ${file.path}, ignored`);