Skip to content

Commit

Permalink
[_] feat: add time metadata to placeholders (internxt#379)
Browse files Browse the repository at this point in the history
* feat: add tiem metadata to placeholder

* chore: use PlaceholderCreator on files module

* feat: use use case to print the placeholder tree
  • Loading branch information
JoanVicens authored Sep 28, 2023
1 parent 2453439 commit 5bc68f0
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 63 deletions.
26 changes: 0 additions & 26 deletions src/workers/sync-engine/BindingManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Logger from 'electron-log';
import { Folder } from './modules/folders/domain/Folder';
import { File } from './modules/files/domain/File';
import { DependencyContainer } from './dependency-injection/DependencyContainer';
import { buildControllers } from './callbacks-controllers/buildControllers';

Expand All @@ -15,30 +13,6 @@ export class BindingsManager {
}
) {}

public createFolderPlaceholder(folder: Folder) {
// In order to create a folder placeholder it's path must en with /
const folderPath = `${folder.path.value}/`;

this.container.virtualDrive.createItemByPath(folderPath, folder.uuid);
}
public createFilePlaceholder(file: File) {
this.container.virtualDrive.createItemByPath(
file.path.value,
file.contentsId,
file.size
);
}

public createPlaceHolders(items: Array<File | Folder>) {
items.forEach((item) => {
if (item.isFile()) {
return this.createFilePlaceholder(item);
}

this.createFolderPlaceholder(item);
});
}

async start(version: string, providerId: string) {
await this.stop();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { ContentsContainer } from './contents/ContentsContainer';
import { FilesContainer } from './files/FilesContainer';
import { FoldersContainer } from './folders/FoldersContainer';
import { ItemsContainer } from './items/ItemsContainer';
import { PlaceholderContainer } from './placeholders/PlaceholdersContainer';

export interface DependencyContainer
extends ItemsContainer,
ContentsContainer,
FilesContainer,
FoldersContainer {
FoldersContainer,
PlaceholderContainer {
fileCreator: FileCreator;
filePathUpdater: FilePathUpdater;
fileSearcher: FileSearcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ export class DependencyContainerFactory {
const { bus } = DependencyInjectionEventBus;
const { virtualDrive } = DependencyInjectionVirtualDrive;

const PlaceholderContainer = buildPlaceholdersContainer();
const itemsContainer = buildItemsContainer();
const placeholderContainer = buildPlaceholdersContainer(itemsContainer);
const contentsContainer = await buildContentsContainer();
const foldersContainer = await buildFoldersContainer(PlaceholderContainer);
const foldersContainer = await buildFoldersContainer(placeholderContainer);
const { container: filesContainer } = await buildFilesContainer(
foldersContainer
foldersContainer,
placeholderContainer
);

const container = {
Expand All @@ -56,6 +57,7 @@ export class DependencyContainerFactory {
...contentsContainer,
...filesContainer,
...foldersContainer,
...placeholderContainer,

virtualDrive,
};
Expand Down
17 changes: 7 additions & 10 deletions src/workers/sync-engine/dependency-injection/files/builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { CreateFilePlaceholderEmitter } from 'workers/sync-engine/modules/files/application/CreateFilePlaceholderEmitter';
import { CreateFilePlaceholderOnDeletionFailed } from 'workers/sync-engine/modules/files/application/CreateFilePlaceholderOnDeletionFailed';
import { FilePlaceholderCreatorFromContentsId } from 'workers/sync-engine/modules/files/application/FilePlaceholderCreatorFromContentsId';
import crypt from '../../../utils/crypt';
import { ipcRendererSyncEngine } from '../../ipcRendererSyncEngine';
import { FileByPartialSearcher } from '../../modules/files/application/FileByPartialSearcher';
Expand All @@ -16,14 +18,12 @@ import { DependencyInjectionLocalRootFolderPath } from '../common/localRootFolde
import { DependencyInjectionTraverserProvider } from '../common/traverser';
import { DependencyInjectionUserProvider } from '../common/user';
import { FoldersContainer } from '../folders/FoldersContainer';
import { PlaceholderContainer } from '../placeholders/PlaceholdersContainer';
import { FilesContainer } from './FilesContainer';
import { FilePlaceholderCreatorFromContentsId } from 'workers/sync-engine/modules/files/application/FilePlaceholderCreatorFromContentsId';
import { FilePlaceholderCreator } from 'workers/sync-engine/modules/files/infrastructure/FilePlaceholderCreator';
import { CreateFilePlaceholderOnDeletionFailed } from 'workers/sync-engine/modules/files/application/CreateFilePlaceholderOnDeletionFailed';
import { DependencyInjectionVirtualDrive } from '../common/virtualDrive';

export async function buildFilesContainer(
folderContainer: FoldersContainer
folderContainer: FoldersContainer,
placeholderContainer: PlaceholderContainer
): Promise<{
container: FilesContainer;
subscribers: any;
Expand All @@ -33,7 +33,6 @@ export async function buildFilesContainer(
const user = DependencyInjectionUserProvider.get();
const localRootFolderPath = DependencyInjectionLocalRootFolderPath.get();
const { bus: eventBus } = DependencyInjectionEventBus;
const { virtualDrive } = DependencyInjectionVirtualDrive;

const fileRepository = new HttpFileRepository(
crypt,
Expand All @@ -53,13 +52,11 @@ export async function buildFilesContainer(
fileRepository
);

const placeholderCreator = new FilePlaceholderCreator(virtualDrive);

const fileDeleter = new FileDeleter(
fileRepository,
fileFinderByContentsId,
folderContainer.parentFoldersExistForDeletion,
placeholderCreator,
placeholderContainer.placeholderCreator,
ipcRendererSyncEngine
);

Expand Down Expand Up @@ -90,7 +87,7 @@ export async function buildFilesContainer(
const filePlaceholderCreatorFromContentsId =
new FilePlaceholderCreatorFromContentsId(
fileFinderByContentsId,
placeholderCreator
placeholderContainer.placeholderCreator
);

const createFilePlaceholderOnDeletionFailed =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { TreePlaceholderCreator } from 'workers/sync-engine/modules/placeholders/application/TreePlaceholderCreator';
import { PlaceholderCreator } from '../../modules/placeholders/domain/PlaceholderCreator';

export interface PlaceholderContainer {
placeholderCreator: PlaceholderCreator;
treePlaceholderCreator: TreePlaceholderCreator;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { TreePlaceholderCreator } from 'workers/sync-engine/modules/placeholders/application/TreePlaceholderCreator';
import { DependencyInjectionVirtualDrive } from '../common/virtualDrive';
import { PlaceholderContainer } from './PlaceholdersContainer';
import { VirtualDrivePlaceholderCreator } from 'workers/sync-engine/modules/placeholders/infrastructure/VirtualDrivePlaceholderCreator';
import { ItemsContainer } from '../items/ItemsContainer';

export function buildPlaceholdersContainer(): PlaceholderContainer {
export function buildPlaceholdersContainer(
itemsContainer: ItemsContainer
): PlaceholderContainer {
const { virtualDrive } = DependencyInjectionVirtualDrive;

const placeholderCreator = new VirtualDrivePlaceholderCreator(virtualDrive);

return { placeholderCreator };
const treePlaceholderCreator = new TreePlaceholderCreator(
itemsContainer.treeBuilder,
placeholderCreator
);

return { placeholderCreator, treePlaceholderCreator };
}
4 changes: 1 addition & 3 deletions src/workers/sync-engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ async function setUp() {
'{E9D7EB38-B229-5DC5-9396-017C449D59CD}'
);

const tree = await container.treeBuilder.run();

bindings.createPlaceHolders(tree);
container.treePlaceholderCreator.run();

bindings.watch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { ParentFoldersExistForDeletion } from '../../folders/application/ParentF
import { FileRepository } from '../domain/FileRepository';
import { FileStatuses } from '../domain/FileStatus';
import { FileFinderByContentsId } from './FileFinderByContentsId';
import { FilePlaceholderCreator } from '../infrastructure/FilePlaceholderCreator';
import { PlaceholderCreator } from '../../placeholders/domain/PlaceholderCreator';

export class FileDeleter {
constructor(
private readonly repository: FileRepository,
private readonly fileFinder: FileFinderByContentsId,
private readonly parentFoldersExistForDeletion: ParentFoldersExistForDeletion,
// TODO: don't import it directly from infrastructure
private readonly filePlaceholderCreator: FilePlaceholderCreator,
private readonly placeholderCreator: PlaceholderCreator,
private readonly ipc: SyncEngineIpc
) {}

Expand Down Expand Up @@ -68,7 +67,7 @@ export class FileDeleter {
error: message,
});

this.filePlaceholderCreator.run(file);
this.placeholderCreator.file(file);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { PlaceholderCreator } from '../../placeholders/domain/PlaceholderCreator';
import { File } from '../domain/File';
import { FilePlaceholderCreator } from '../infrastructure/FilePlaceholderCreator';
import { FileFinderByContentsId } from './FileFinderByContentsId';

export class FilePlaceholderCreatorFromContentsId {
constructor(
private readonly finder: FileFinderByContentsId,
private readonly placeholderCreator: FilePlaceholderCreator
private readonly placeholderCreator: PlaceholderCreator
) {}

run(contentsId: File['contentsId']) {
const file = this.finder.run(contentsId);

this.placeholderCreator.run(file);
this.placeholderCreator.file(file);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TreeBuilder } from '../../items/application/TreeBuilder';
import { PlaceholderCreator } from '../domain/PlaceholderCreator';

export class TreePlaceholderCreator {
constructor(
// TODO: fix the import form infra
private readonly treeBuilder: TreeBuilder,
private readonly placeholderCreator: PlaceholderCreator
) {}

async run(): Promise<void> {
const tree = await this.treeBuilder.run();

tree.forEach((item) => {
if (item.isFile()) {
return this.placeholderCreator.file(item);
}

this.placeholderCreator.folder(item);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export class VirtualDrivePlaceholderCreator implements PlaceholderCreator {
}

file(file: File): void {
this.drive.createItemByPath(file.path.value, file.contentsId, file.size);
this.drive.createItemByPath(
file.path.value,
file.contentsId,
file.size,
file.createdAt.getTime(),
file.updatedAt.getTime()
);
}
}

0 comments on commit 5bc68f0

Please sign in to comment.