Skip to content

Commit d7b5cf0

Browse files
Merge pull request #156 from internxt/refactor-method
Refactor Properties in Methods and Solution for Special Characters in File Paths (Windows)
2 parents 41f660e + d3fca28 commit d7b5cf0

23 files changed

Lines changed: 306 additions & 123 deletions

.github/workflows/pull-request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Pull request checks
22

33
on:
44
pull_request:
5+
types: [opened, synchronize, reopened]
56

67
jobs:
78
checks:

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
importOrderParserPlugins: ["typescript", "decorators-legacy"],
88
importOrderSeparation: true,
99
plugins: [require.resolve("@trivago/prettier-plugin-sort-imports")],
10-
printWidth: 140,
10+
printWidth: 120,
1111
proseWrap: "never",
1212
semi: true,
1313
singleQuote: false,
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { logger } from "examples/drive";
22

3-
export const notifyMessageCallback = (message: string, action: string, errorName: string, callback: (response: boolean) => void) => {
3+
export const notifyMessageCallback = (
4+
message: string,
5+
action: string,
6+
errorName: string,
7+
callback: (response: boolean) => void,
8+
) => {
49
logger.info({ event: "notifyMessageCallback", message, action, errorName });
510
callback(true);
611
};

examples/get-state.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ const { data } = z.object({ file: z.string() }).safeParse(argv);
1818

1919
if (data) {
2020
const path = data.file;
21-
const state = drive.getPlaceholderState(path);
21+
const state = drive.getPlaceholderState({
22+
path,
23+
});
2224
logger.info({ state });
2325
} else {
2426
logger.error("Por favor especifica un archivo con --file <path>");

examples/handlers/handle-add.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ export const handleAdd = async (task: QueueItem) => {
88
try {
99
logger.info({ fn: "handleAdd", task });
1010
const id = task.isFolder ? v4() : addInfoItem(task.path);
11-
drive.convertToPlaceholder(task.path, id);
11+
drive.convertToPlaceholder({
12+
itemPath: task.path,
13+
id,
14+
});
1215
} catch (error) {
1316
logger.error("handleAdd", error);
1417
}

examples/handlers/handle-change-size.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ export const handleChangeSize = async (task: QueueItem) => {
77
try {
88
logger.info({ fn: "handleChangeSize", path: task.path });
99
const id = v4();
10-
drive.convertToPlaceholder(task.path, id);
11-
drive.updateFileIdentity(task.path, id, false);
10+
drive.convertToPlaceholder({
11+
itemPath: task.path,
12+
id,
13+
});
14+
drive.updateFileIdentity({
15+
itemPath: task.path,
16+
id,
17+
isDirectory: task.isFolder,
18+
});
1219
} catch (error) {
1320
logger.error("handleChangeSize", error);
1421
}

examples/handlers/handle-dehydrate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { QueueItem } from "@/queue/queueManager";
55
export const handleDehydrate = async (task: QueueItem) => {
66
try {
77
logger.info({ fn: "handleDehydrate", path: task.path });
8-
drive.dehydrateFile(task.path);
8+
drive.dehydrateFile({
9+
itemPath: task.path,
10+
});
911
} catch (error) {
1012
logger.error("handleDehydrate", error);
1113
}

examples/handlers/handle-hydrate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { QueueItem } from "@/queue/queueManager";
55
export const handleHydrate = async (task: QueueItem) => {
66
try {
77
logger.info({ fn: "handleHydrate", path: task.path });
8-
await drive.hydrateFile(task.path);
8+
await drive.hydrateFile({
9+
itemPath: task.path,
10+
});
911
} catch (error) {
1012
logger.error("handleHydrate", error);
1113
}

examples/register.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { QueueManager } from "@/queue/queue-manager";
2-
import VirtualDrive from "@/virtual-drive";
32

43
import { cancelFetchDataCallback } from "./callbacks/cancel-fetch-data.callback";
54
import { notifyDeleteCallback } from "./callbacks/notify-delete.callback";
@@ -14,18 +13,28 @@ import { handleHydrate } from "./handlers/handle-hydrate";
1413
import { initInfoItems } from "./info-items-manager";
1514
import settings from "./settings";
1615

17-
const callbacks = { notifyDeleteCallback, notifyRenameCallback, fetchDataCallback, cancelFetchDataCallback, notifyMessageCallback };
16+
const callbacks = {
17+
notifyDeleteCallback,
18+
notifyRenameCallback,
19+
fetchDataCallback,
20+
cancelFetchDataCallback,
21+
notifyMessageCallback,
22+
};
1823
const handlers = { handleAdd, handleHydrate, handleDehydrate, handleChangeSize };
1924

20-
const notify = { onTaskSuccess: async () => undefined, onTaskProcessing: async () => undefined };
21-
const queueManager = new QueueManager(handlers, notify, settings.queuePersistPath);
25+
const queueManager = new QueueManager({ handlers, persistPath: settings.queuePersistPath });
2226

23-
drive.registerSyncRoot(settings.driveName, settings.driveVersion, callbacks, settings.iconPath);
27+
drive.registerSyncRoot({
28+
providerName: settings.driveName,
29+
providerVersion: settings.driveVersion,
30+
callbacks,
31+
logoPath: settings.iconPath,
32+
});
2433
drive.connectSyncRoot();
2534

2635
try {
2736
initInfoItems();
28-
drive.watchAndWait(settings.syncRootPath, queueManager, settings.watcherLogPath);
37+
drive.watchAndWait({ queueManager });
2938
} catch (error) {
3039
logger.error(error);
3140
drive.disconnectSyncRoot();

examples/utils/generate-random-file-tree.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ async function createStructureRecursively(
5353
const createdAt = Date.now() - (timeOffset || 0);
5454
const updatedAt = Date.now() - (timeOffset || 0) + 2000;
5555

56-
drive.createFileByPath(fullPath, fileId, fileSize, createdAt, updatedAt);
56+
drive.createFileByPath({
57+
relativePath: fullPath,
58+
itemId: fileId,
59+
size: fileSize,
60+
creationTime: createdAt,
61+
lastWriteTime: updatedAt,
62+
});
5763

5864
result[fileId] = fullPath;
5965
}
@@ -66,13 +72,21 @@ async function createStructureRecursively(
6672
const createdAt = Date.now() - (timeOffset || 0) - 10000; // Ejemplo
6773
const updatedAt = Date.now() - (timeOffset || 0);
6874

69-
drive.createFolderByPath(newFolderPath, folderId, 1000, createdAt, updatedAt);
75+
drive.createFolderByPath({
76+
relativePath: newFolderPath,
77+
itemId: folderId,
78+
creationTime: createdAt,
79+
lastWriteTime: updatedAt,
80+
});
7081

7182
await createStructureRecursively(drive, newFolderPath, level - 1, options, result);
7283
}
7384
}
7485

75-
async function generateRandomFilesAndFolders(drive: VirtualDrive, options: GenerateOptions): Promise<Record<string, string>> {
86+
async function generateRandomFilesAndFolders(
87+
drive: VirtualDrive,
88+
options: GenerateOptions,
89+
): Promise<Record<string, string>> {
7690
const { rootPath } = options;
7791

7892
const result: Record<string, string> = {};

0 commit comments

Comments
 (0)