Skip to content

Commit

Permalink
Merge pull request #382 from internxt/feat/fix-reporting-changes
Browse files Browse the repository at this point in the history
[PB-481]: Feat/fix reporting changes
  • Loading branch information
larry-internxt authored Sep 28, 2023
2 parents f9f4015 + 54f0ffe commit 302d133
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 31 deletions.
10 changes: 10 additions & 0 deletions src/main/fordwardToWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ ipcMainDrive.on('FILE_OVERWRITED', (_, payload) => {
});
});

ipcMainDrive.on('FILE_RENAMING', (_, payload) => {
const { nameWithExtension, oldName } = payload;

broadcastToWindows('sync-info-update', {
action: 'RENAMING',
name: nameWithExtension,
oldName,
});
});

ipcMainDrive.on('FILE_RENAMED', (_, payload) => {
const { nameWithExtension } = payload;

Expand Down
1 change: 1 addition & 0 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import './device/handlers';
import './usage/handlers';
import './realtime';
import './tray/tray';
import './tray/handlers';
import './fordwardToWindows';
import './analytics/handlers';
import './platform/handlers';
Expand Down
12 changes: 6 additions & 6 deletions src/shared/IPC/events/sync-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ type FileUpdatePayload = {
};

export type FolderEvents = {
CREATING_FOLDER: (payload: { name: string }) => void;
FOLDER_CREATING: (payload: { name: string }) => void;
FOLDER_CREATED: (payload: { name: string }) => void;

RENAMING_FOLDER: (payload: { oldName: string; newName: string }) => void;
FOLDER_RENAMING: (payload: { oldName: string; newName: string }) => void;
FOLDER_RENAMED: (payload: { oldName: string; newName: string }) => void;
};

export type FilesEvents = {
UPLOADING_FILE: (payload: FileUpdatePayload) => void;
FILE_UPLOADING: (payload: FileUpdatePayload) => void;
FILE_UPLOADED: (payload: FileUpdatePayload) => void;
FILE_DOWNLOAD_ERROR: (payload: {
name: string;
Expand All @@ -59,7 +59,7 @@ export type FilesEvents = {
error: string;
}) => void;

DOWNLOADING_FILE: (payload: FileUpdatePayload) => void;
FILE_DOWNLOADING: (payload: FileUpdatePayload) => void;
FILE_DOWNLOADED: (payload: FileUpdatePayload) => void;
FILE_UPLOAD_ERROR: (payload: {
name: string;
Expand All @@ -68,7 +68,7 @@ export type FilesEvents = {
error: string;
}) => void;

DELETING_FILE: (payload: {
FILE_DELETING: (payload: {
name: string;
extension: string;
nameWithExtension: string;
Expand All @@ -87,7 +87,7 @@ export type FilesEvents = {
error: string;
}) => void;

RENAMING_FILE: (payload: {
FILE_RENAMING: (payload: {
nameWithExtension: string;
oldName: string;
}) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export async function buildFilesContainer(
const filePathUpdater = new FilePathUpdater(
fileRepository,
fileFinderByContentsId,
folderContainer.folderFinder
folderContainer.folderFinder,
ipcRendererSyncEngine
);

const fileCreator = new FileCreator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ContentsDownloader {

private registerEvents(downloader: ContentFileDownloader, file: File) {
downloader.on('start', () => {
this.ipc.send('DOWNLOADING_FILE', {
this.ipc.send('FILE_DOWNLOADING', {
name: file.name,
extension: file.type,
nameWithExtension: file.nameWithExtension,
Expand All @@ -26,7 +26,7 @@ export class ContentsDownloader {
});

downloader.on('progress', (progress: number) => {
this.ipc.send('DOWNLOADING_FILE', {
this.ipc.send('FILE_DOWNLOADING', {
name: file.name,
extension: file.type,
nameWithExtension: file.nameWithExtension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ContentsUploader {
localFileContents: LocalFileContents
) {
uploader.on('start', () => {
this.ipc.send('UPLOADING_FILE', {
this.ipc.send('FILE_UPLOADING', {
name: localFileContents.name,
extension: localFileContents.extension,
nameWithExtension: localFileContents.nameWithExtension,
Expand All @@ -27,7 +27,7 @@ export class ContentsUploader {
});

uploader.on('progress', (progress: number) => {
this.ipc.send('UPLOADING_FILE', {
this.ipc.send('FILE_UPLOADING', {
name: localFileContents.name,
extension: localFileContents.extension,
nameWithExtension: localFileContents.nameWithExtension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class FileDeleter {
return;
}

this.ipc.send('DELETING_FILE', {
this.ipc.send('FILE_DELETING', {
name: file.name,
extension: file.type,
nameWithExtension: file.nameWithExtension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ import { FilePath } from '../domain/FilePath';
export class FilePathFromAbsolutePathCreator {
constructor(private readonly baseFolder: string) {}

private calculateRelativePath(basePath: string, filePath: string): string {
const relativePath = path.relative(basePath, filePath);
private calculateRelativePath(basePathString: string, filePathString: string): string {
const basePath = path.parse(basePathString);
const filePath = path.parse(filePathString);

if (!filePath.root || filePath.root.length === 0 || filePath.root === '\\') {
filePath.root = basePath.root;
filePath.dir = path.join(basePath.root, filePath.dir);
}

const fixedFilePath = path.join(filePath.dir + path.sep + filePath.base);

const relativePath = path.relative(basePathString, fixedFilePath);
const relativeFolders = path.dirname(relativePath);
const fileName = path.basename(filePath);

return path.join(relativeFolders, fileName);
return path.join(relativeFolders, filePath.base);
}

run(absolutePath: string): FilePath {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { File } from '../domain/File';
import { FileRepository } from '../domain/FileRepository';
import { FolderFinder } from '../../folders/application/FolderFinder';
import { FileFinderByContentsId } from './FileFinderByContentsId';
import { SyncEngineIpc } from '../../../ipcRendererSyncEngine';

export class FilePathUpdater {
constructor(
private readonly repository: FileRepository,
private readonly fileFinderByContentsId: FileFinderByContentsId,
private readonly folderFinder: FolderFinder
private readonly folderFinder: FolderFinder,
private readonly ipc: SyncEngineIpc
) {}

private async rename(file: File, path: FilePath) {
Expand All @@ -22,13 +24,13 @@ export class FilePathUpdater {
}

async run(contentsId: string, destination: FilePath) {
// this.ipc.send('WEBDAV_FILE_RENAMING', {
// oldName: file.name,
// nameWithExtension: destination.nameWithExtension(),
// });

const file = this.fileFinderByContentsId.run(contentsId);

this.ipc.send('FILE_RENAMING', {
oldName: file.name,
nameWithExtension: destination.nameWithExtension(),
});

if (file.dirname !== destination.dirname()) {
if (file.nameWithExtension !== destination.nameWithExtension()) {
throw new ActionNotPermitedError('rename and change folder');
Expand All @@ -46,17 +48,21 @@ export class FilePathUpdater {
const destinationFile = this.repository.search(destination);

if (destinationFile) {
// this.ipc.send('WEBDAV_FILE_RENAME_ERROR', {
// name: file.name,
// extension: file.type,
// nameWithExtension: file.nameWithExtension,
// error: 'Renaming error: file already exists',
// });
this.ipc.send('FILE_RENAME_ERROR', {
name: file.name,
extension: file.type,
nameWithExtension: file.nameWithExtension,
error: 'Renaming error: file already exists',
});
throw new FileAlreadyExistsError(destination.name());
}

if (destination.extensionMatch(file.type)) {
await this.rename(file, destination);
this.ipc.send('FILE_RENAMED', {
oldName: file.name,
nameWithExtension: destination.nameWithExtension(),
});
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ import { FileRepositoryMock } from '../__mocks__/FileRepositoryMock';
import { FolderFinder } from '../../../folders/application/FolderFinder';
import { FolderFinderMock } from '../../../folders/test/__mocks__/FolderFinderMock';
import { FileFinderByContentsId } from '../../application/FileFinderByContentsId';
import { IpcRendererSyncEngineMock } from '../../../shared/test/__mock__/IpcRendererSyncEngineMock';

describe('File path updater', () => {
let repository: FileRepositoryMock;
let fileFinderByContentsId: FileFinderByContentsId;
let folderFinder: FolderFinderMock;
let SUT: FilePathUpdater;
let ipcRendererMock: IpcRendererSyncEngineMock;

beforeEach(() => {
repository = new FileRepositoryMock();
folderFinder = new FolderFinderMock();
fileFinderByContentsId = new FileFinderByContentsId(repository);
ipcRendererMock = new IpcRendererSyncEngineMock();

SUT = new FilePathUpdater(
repository,
fileFinderByContentsId,
folderFinder as unknown as FolderFinder
folderFinder as unknown as FolderFinder,
ipcRendererMock
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class FolderCreator {
const folderPath = this.folderPathFromAbsolutePathCreator.fromAbsolute(
PlatformPathConverter.winToPosix(absolutePath)
);
this.ipc.send('CREATING_FOLDER', {
this.ipc.send('FOLDER_CREATING', {
name: folderPath.name(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class FolderRenamer {
) {}

async run(folder: Folder, destination: FolderPath) {
this.ipc.send('RENAMING_FOLDER', {
this.ipc.send('FOLDER_RENAMING', {
oldName: folder.name,
newName: destination.name(),
});
Expand Down

0 comments on commit 302d133

Please sign in to comment.