* WIP * Add debug * Dedupe inserts * Add deterministic ordering * Fix whitespaces * Update insta * Add integration test script * Rename * Add test * Working for non-deletes * omg it mostly works for deletes * Isdeleted fix * remove created dates * update api * Take document id * No max attempt * works * Use string uuids * . * working!!!! (hopefully) * Improve bundling * Add module * lint * . * lint * Fix CI * use toolchain * clean up * Add useSlowFileEvents * Delete fuzz * Fix CI * use docker * fix script * clean up * Clean up * change node version * Build docker image on every commit * fix ci * 1 db per vault * Add scritps folder * Bump versions * Lint * . * Fix tests for real * Style * . * try * Consistent ordering * Fix tests * hmm * . * Clean up diff * Fixes * . * Fix version bump * . * . * .
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import type { SyncClient } from "sync-client";
|
|
import type { TAbstractFile } from "obsidian";
|
|
import { TFile } from "obsidian";
|
|
|
|
export class ObsidianFileEventHandler {
|
|
public constructor(private readonly client: SyncClient) {}
|
|
|
|
public async onCreate(file: TAbstractFile): Promise<void> {
|
|
if (file instanceof TFile) {
|
|
this.client.logger.info(`File created: ${file.path}`);
|
|
|
|
await this.client.syncer.syncLocallyCreatedFile(file.path);
|
|
} else {
|
|
this.client.logger.debug(`Folder created: ${file.path}, ignored`);
|
|
}
|
|
}
|
|
|
|
public async onDelete(file: TAbstractFile): Promise<void> {
|
|
if (file instanceof TFile) {
|
|
this.client.logger.info(`File deleted: ${file.path}`);
|
|
|
|
await this.client.syncer.syncLocallyDeletedFile(file.path);
|
|
} else {
|
|
this.client.logger.debug(`Folder deleted: ${file.path}, ignored`);
|
|
}
|
|
}
|
|
|
|
public async onRename(file: TAbstractFile, oldPath: string): Promise<void> {
|
|
if (file instanceof TFile) {
|
|
this.client.logger.info(`File renamed: ${oldPath} -> ${file.path}`);
|
|
|
|
await this.client.syncer.syncLocallyUpdatedFile({
|
|
oldPath,
|
|
relativePath: file.path
|
|
});
|
|
} else {
|
|
this.client.logger.debug(
|
|
`Folder renamed: ${oldPath} -> ${file.path}, ignored`
|
|
);
|
|
}
|
|
}
|
|
|
|
public async onModify(file: TAbstractFile): Promise<void> {
|
|
if (file instanceof TFile) {
|
|
if (file.basename.startsWith("console-log.iPhone")) {
|
|
return;
|
|
}
|
|
|
|
this.client.logger.info(`File modified: ${file.path}`);
|
|
|
|
await this.client.syncer.syncLocallyUpdatedFile({
|
|
relativePath: file.path
|
|
});
|
|
} else {
|
|
this.client.logger.debug(`Folder modified: ${file.path}, ignored`);
|
|
}
|
|
}
|
|
}
|