Skip to content
Merged
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
2 changes: 2 additions & 0 deletions examples/callbacks/notify-fetch-data.callback.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { logger } from "examples/drive";
import { getInfoItem } from "examples/info-items-manager";

import { sleep } from "@/utils";

type TCallback = (data: boolean, path: string, errorHandler?: () => void) => Promise<{ finished: boolean; progress: number }>;

export const fetchDataCallback = async (id: string, callback: TCallback) => {
logger.info({ fn: "fetchDataCallback", id });
const path = await getInfoItem(id);

let finish = false;
Expand Down
8 changes: 4 additions & 4 deletions examples/handlers/handle-change-size.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { drive, logger } from "examples/drive";
import { v4 } from "uuid";

import { QueueItem } from "@/queue/queueManager";

export const handleChangeSize = async (task: QueueItem) => {
try {
logger.info({ fn: "handleChangeSize", path: task.path });
const result = Math.random().toString(36).substring(2, 7);
drive.convertToPlaceholder(task.path, result);
drive.updateFileIdentity(task.path, result, false);
drive.updateSyncStatus(task.path, task.isFolder, true);
const id = v4();
drive.convertToPlaceholder(task.path, id);
drive.updateFileIdentity(task.path, id, false);
} catch (error) {
logger.error("handleChangeSize", error);
}
Expand Down
5 changes: 4 additions & 1 deletion examples/populate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { v4 } from "uuid";

import settings from "./settings";

const rootFile1 = join(settings.syncRootPath, v4());
const rootFileName1 = v4();
const rootZipFileName = `${v4()}.zip`;
const rootFile1 = join(settings.syncRootPath, rootFileName1);
const rootFile2ChangeSize = join(settings.syncRootPath, `change-size-${v4()}.txt`);
const rootFile3 = join(settings.syncRootPath, `${v4()}.txt`);
const rootFile3Moved = join(settings.syncRootPath, `moved-${v4()}.txt`);
Expand All @@ -22,6 +24,7 @@ execSync(`echo Hello, world! > ${rootFile2ChangeSize}`);
execSync(`echo Hello, world! >> ${rootFile2ChangeSize}`); // Sync
execSync(`echo Hello, world! > ${rootFile3}`);
execSync(`type nul > ${rootFile4}`); // No sync (0 bytes)
execSync(`cd ${settings.syncRootPath} && tar -cf ${rootZipFileName} ${rootFileName1}`); // Sync
execSync(`mv ${rootFile3} ${rootFile3Moved}`); // Sync
execSync(`mkdir ${rootFolder1}`); // Sync
execSync(`mkdir ${rootFolder2}`); // Cloud (no files inside)
Expand Down
14 changes: 0 additions & 14 deletions src/types/placeholder.type.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
// Enum para SyncState
export enum SyncState {
Undefined = -1,
NotInSync = 0,
InSync = 1,
}

// Enum para PinState
export enum PinState {
Inherited = 0,
AlwaysLocal = 1,
OnlineOnly = 2,
Unspecified = 3,
Excluded = 4,
}

// Tipo para combinar ambos estados en un objeto de estado
export type Status = {
pinState: PinState;
syncState: SyncState;
};

export enum Attributes {
OTHER = 0,
NOT_PINNED = 1,
PINNED = 2,
}
4 changes: 1 addition & 3 deletions src/virtual-drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path, { join, win32 } from "path";
import fs from "fs";
import { Watcher } from "./watcher/watcher";
import { ExtraCallbacks, InputSyncCallbacks } from "./types/callbacks.type";
import { Status } from "./types/placeholder.type";
import { IQueueManager } from "./queue/queueManager";

import { createLogger } from "./logger";
Expand All @@ -16,7 +15,6 @@ class VirtualDrive {
syncRootPath: string;
callbacks?: Callbacks;

// private watcherBuilder: WatcherBuilder;
private watcher: Watcher;

constructor(syncRootPath: string, loggerPath?: string) {
Expand Down Expand Up @@ -57,7 +55,7 @@ class VirtualDrive {
}
}

getPlaceholderState(path: string): Status {
getPlaceholderState(path: string) {
return addon.getPlaceholderState({ path: this.fixPath(path) });
}

Expand Down
2 changes: 1 addition & 1 deletion src/watcher/detect-context-menu-action.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class DetectContextMenuActionService {
const isInDevice = self.fileInDevice.has(path);

self.logger.info({
event: "onRaw",
event: "change",
path,
status,
itemId,
Expand Down
6 changes: 3 additions & 3 deletions src/watcher/events/on-add.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export class OnAddService {
try {
const ext = path.split(".").pop();
const { size, birthtime, mtime } = stats;
const fileIntenty = self.addon.getFileIdentity({ path });
const itemId = self.addon.getFileIdentity({ path });

self.logger.info({ fn: "onAdd", path, ext, size, birthtime, mtime, fileIntenty });
self.logger.info({ fn: "onAdd", path, ext, size, birthtime, mtime, itemId });

if (!ext || size === 0 || size > 20 * 1024 * 1024 * 1024) return;

Expand All @@ -27,7 +27,7 @@ export class OnAddService {
let isNewFile = false;
let isMovedFile = false;

if (!fileIntenty) {
if (!itemId) {
// El archivo fue creado recientemente (dentro de los últimos 60 segundos)
isNewFile = true;
} else if (creationTime !== modificationTime) {
Expand Down
37 changes: 15 additions & 22 deletions src/watcher/events/on-raw.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,22 @@ export class OnRawService {
constructor(private readonly detectContextMenuAction: DetectContextMenuActionService = new DetectContextMenuActionService()) {}

async execute({ self, event, path, details }: TProps) {
if (event === "change" && details.prev && details.curr) {
if (extname(path) === "") {
self.logger.info({ event: "onRaw", path, details: "No extension" });
return;
}

const item = await stat(path);
if (item.isDirectory()) {
self.logger.info({ event: "onRaw", path, details: "Is directory" });
return;
}

// // Ignorar archivos vacíos
// if (item.size === 0) {
// self.logger.info("Archivo vacío ignorado", path);
// return;
// }

const action = await this.detectContextMenuAction.execute({ self, details, path, isFolder: false });

if (action) {
self.logger.info({ event: "onRaw", path, action });
try {
if (event === "change" && details.prev && details.curr) {
const item = await stat(path);
if (item.isDirectory()) {
self.logger.info({ event: "change", path, details: "Is directory" });
return;
}

const action = await this.detectContextMenuAction.execute({ self, details, path, isFolder: false });

if (action) {
self.logger.info({ event: "change", path, action });
}
}
} catch (error) {
self.logger.error("Error on change", error);
}
}
}
Expand Down