Skip to content
Open
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build:renderer": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.prod.ts",
"rebuild": "electron-rebuild --parallel --types prod,dev,optional --module-dir .",
"reinstall:nautilus-extension": "NODE_ENV=development ts-node src/apps/nautilus-extension/reload.ts",
"lint": "cross-env NODE_ENV=development eslint . --ext .ts,.tsx --max-warnings=210",
"lint": "cross-env NODE_ENV=development eslint . --ext .ts,.tsx --max-warnings=60",
"lint:fix": "npm run lint --fix",
"format": "prettier src --check",
"format:fix": "prettier src --write",
Expand Down
9 changes: 6 additions & 3 deletions src/apps/backups/BackupService.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Environment } from '@internxt/inxt-js';
import { Mock } from 'vitest';
import { mockDeep } from 'vitest-mock-extended';
import { BackupService } from './BackupService';
Expand All @@ -16,6 +17,7 @@ import { BackupProgressTracker } from '../../backend/features/backup/backup-prog
import * as executeAsyncQueueModule from '../../backend/common/async-queue/execute-async-queue';
import * as addFileToTrashModule from '../../infra/drive-server/services/files/services/add-file-to-trash';
import { partialSpyOn } from '../../../tests/vitest/utils.helper';
import { AbsolutePath } from '../../context/local/localFile/infrastructure/AbsolutePath';

vi.mock(import('../../backend/features/usage/usage.module'));

Expand All @@ -27,12 +29,13 @@ describe('BackupService', () => {
let localTreeBuilder: LocalTreeBuilder;
let remoteTreeBuilder: RemoteTreeBuilder;
let simpleFolderCreator: SimpleFolderCreator;
let environment: Environment;
let mockValidateSpace: Mock;
let abortController: AbortController;
let tracker: BackupProgressTracker;

const info: BackupInfo = {
pathname: '/path/to/backup',
pathname: '/path/to/backup' as AbsolutePath,
folderId: 123,
folderUuid: 'uuid',
tmpPath: '/tmp/path',
Expand All @@ -44,6 +47,7 @@ describe('BackupService', () => {
localTreeBuilder = mockDeep<LocalTreeBuilder>();
remoteTreeBuilder = mockDeep<RemoteTreeBuilder>();
simpleFolderCreator = mockDeep<SimpleFolderCreator>();
environment = mockDeep<Environment>();
tracker = mockDeep<BackupProgressTracker>();

mockValidateSpace = vi.mocked(UsageModule.validateSpace);
Expand All @@ -57,7 +61,7 @@ describe('BackupService', () => {
localTreeBuilder,
remoteTreeBuilder,
simpleFolderCreator,
{} as any,
environment,
'backups-bucket',
);

Expand All @@ -77,7 +81,6 @@ describe('BackupService', () => {
expect(result).toBeUndefined();
expect(localTreeBuilder.run).toHaveBeenCalledWith(info.pathname);
expect(remoteTreeBuilder.run).toHaveBeenCalledWith(info.folderId, info.folderUuid);
expect(tracker.addToTotal).toHaveBeenCalled();
expect(tracker.incrementProcessed).toHaveBeenCalled();
});

Expand Down
3 changes: 1 addition & 2 deletions src/apps/drive/__mocks__/ContainerMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ export class ContainerMock implements Partial<Container> {

get = vi.fn((service) => this.services.get(service));

set<T>(service: any, implementation: T): void {
set<T>(service: Identifier<T>, implementation: T): void {
this.services.set(service, implementation);
}

// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
findTaggedServiceIdentifiers<T = unknown>(tag: string): Array<Identifier<T>> {
return [] as Array<Identifier<T>>;
Expand Down
10 changes: 2 additions & 8 deletions src/apps/drive/fuse/FuseApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ describe('FuseApp', () => {
mountPromiseMock.mockRejectedValue(new Error('mount failed'));

const startPromise = fuseApp.start();
// eslint-disable-next-line no-await-in-loop
for (let i = 0; i < 5; i++) {
await vi.advanceTimersByTimeAsync(3000);
}
await vi.runAllTimersAsync();
await startPromise;

expect(fuseApp.getStatus()).toBe('ERROR');
Expand All @@ -118,10 +115,7 @@ describe('FuseApp', () => {
fuseApp.on('mount-error', mountErrorHandler);

const startPromise = fuseApp.start();
// eslint-disable-next-line no-await-in-loop
for (let i = 0; i < 5; i++) {
await vi.advanceTimersByTimeAsync(3000);
}
await vi.runAllTimersAsync();
await startPromise;

expect(mountErrorHandler).toHaveBeenCalled();
Expand Down
10 changes: 5 additions & 5 deletions src/apps/drive/fuse/callbacks/FuseCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export abstract class FuseCallback<T> {
},
) {}

protected async executeAndCatch(params: any[]): Promise<Either<FuseError, T>> {
protected async executeAndCatch(params: unknown[]): Promise<Either<FuseError, T>> {
// Ensure that an Either is always returned

const stopwatch = new Stopwatch();
Expand Down Expand Up @@ -103,10 +103,10 @@ export abstract class FuseCallback<T> {
logger.debug({ msg: `${this.name}: `, message });
}

async handle(...params: any[]): Promise<void> {
async handle(...params: unknown[]): Promise<void> {
const callback = params.pop() as CallbackWithData<T>;

if (PathsToIgnore.some((regex) => regex.test(params[0]))) {
if (typeof params[0] === 'string' && PathsToIgnore.some((regex) => regex.test(params[0] as string))) {
return callback(FuseCodes.EINVAL);
}

Expand All @@ -126,15 +126,15 @@ export abstract class FuseCallback<T> {
callback(FuseCallback.OK, data);
}

abstract execute(...params: any[]): Promise<Either<FuseError, T>>;
abstract execute(...params: unknown[]): Promise<Either<FuseError, T>>;
}

export abstract class NotifyFuseCallback extends FuseCallback<undefined> {
protected right(): Either<FuseError, undefined> {
return right(undefined);
}

async handle(...params: any[]): Promise<void> {
async handle(...params: unknown[]): Promise<void> {
const callback = params.pop() as Callback;

if (this.debug.input) {
Expand Down
3 changes: 2 additions & 1 deletion src/apps/drive/fuse/callbacks/ReadCallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as handleReadModule from '../../../../backend/features/fuse/on-read/han
import { partialSpyOn } from '../../../../../tests/vitest/utils.helper';
import { left, right } from '../../../../context/shared/domain/Either';
import { FuseNoSuchFileOrDirectoryError } from './FuseErrors';
import { type Container } from 'diod';

const handleReadCallbackMock = partialSpyOn(handleReadModule, 'handleReadCallback');

Expand All @@ -18,7 +19,7 @@ function createMockContainer() {
downloadFinished: vi.fn(),
elapsedTime: vi.fn(),
}),
} as any;
} as Partial<Container> as Container;
}

describe('ReadCallback', () => {
Expand Down
9 changes: 1 addition & 8 deletions src/apps/drive/fuse/callbacks/ReadCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ import Fuse from '@gcas/fuse';
export class ReadCallback {
constructor(private readonly container: Container) {}

async execute(
path: string,
_fd: any,
buf: Buffer,
len: number,
pos: number,
cb: (code: number, params?: any) => void,
) {
async execute(path: string, _fd: number, buf: Buffer, len: number, pos: number, cb: (bytesRead?: number) => void) {
try {
const repo = this.container.get(StorageFilesRepository);
const downloader = this.container.get(StorageFileDownloader);
Expand Down
3 changes: 2 additions & 1 deletion src/apps/drive/fuse/callbacks/ReleaseCallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { right } from '../../../../context/shared/domain/Either';
import * as openFlagsTracker from './../../../../backend/features/fuse/on-open/open-flags-tracker';
import * as handleReleaseModule from '../../../../backend/features/fuse/on-release/handle-release-callback';
import { partialSpyOn } from '../../../../../tests/vitest/utils.helper';
import { Container } from 'diod';

vi.mock(import('@internxt/drive-desktop-core/build/backend'));

describe('ReleaseCallback', () => {
const onReleaseSpy = partialSpyOn(openFlagsTracker, 'onRelease');
const handleReleaseSpy = partialSpyOn(handleReleaseModule, 'handleReleaseCallback');

const container = { get: vi.fn() } as any;
const container = { get: vi.fn() } as unknown as Container;
const releaseCallback = new ReleaseCallback(container);
it('should call onRelease to clean up open flags tracker', async () => {
handleReleaseSpy.mockResolvedValue(right(undefined));
Expand Down
2 changes: 1 addition & 1 deletion src/apps/drive/hydration-api/HydrationApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('HydrationApi', () => {

await hydrationApi.start({ debug: true, timeElapsed: false });

const response = await fetch('http://localhost:4567/hydration/test');
await fetch('http://localhost:4567/hydration/test');
// The request itself may 404, but the debug middleware should have logged
expect(loggerMock.debug).toBeCalledWith(
expect.objectContaining({
Expand Down
1 change: 0 additions & 1 deletion src/apps/drive/hydration-api/controllers/contents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Container } from 'diod';
import { logger } from '@internxt/drive-desktop-core/build/backend';
import { NextFunction, Request, Response } from 'express';
import { extname } from 'path';
import { StorageFileDeleter } from '../../../../context/storage/StorageFiles/application/delete/StorageFileDeleter';
Expand Down
14 changes: 3 additions & 11 deletions src/apps/drive/hydration-api/controllers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@ export function buildFilesControllers(container: Container) {
};

const filter = async (req: Request, res: Response) => {
const filter = Object.entries(req.query)

.map(([key, param]) => {
return { key, value: param };
})
.reduce((partial: Partial<FileAttributes>, { key, value }: any) => {
return {
...partial,
[key]: value.toString(),
};
}, {});
const filter = Object.fromEntries(
Object.entries(req.query).filter((entry): entry is [string, string] => typeof entry[1] === 'string'),
) as Partial<FileAttributes>;

const files = await container.get(FilesSearcherByPartialMatch).run(filter);

Expand Down
44 changes: 22 additions & 22 deletions src/apps/drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ export async function startVirtualDrive() {
await fuseApp.start();
}

export async function stopAndClearFuseApp() {
await stopHydrationApi();
await stopFuseApp();
}

export async function updateFuseApp() {
await fuseApp.update();
}
export async function stopHydrationApi() {
if (!hydrationApi) {
logger.debug({ msg: 'HydrationApi not initialized, skipping stop.' });
return;
}

export function getFuseDriveState() {
if (!fuseApp) {
return 'UNMOUNTED';
try {
logger.debug({ msg: 'Stopping HydrationApi...' });
await hydrationApi.stop();
} catch (error) {
logger.error({ msg: 'Error stopping HydrationApi:', error });
}
return fuseApp.getStatus();
}

async function stopFuseApp() {
Expand All @@ -64,16 +62,18 @@ async function stopFuseApp() {
}
}

export async function stopHydrationApi() {
if (!hydrationApi) {
logger.debug({ msg: 'HydrationApi not initialized, skipping stop.' });
return;
}
export async function stopAndClearFuseApp() {
await stopHydrationApi();
await stopFuseApp();
}

try {
logger.debug({ msg: 'Stopping HydrationApi...' });
await hydrationApi.stop();
} catch (error) {
logger.error({ msg: 'Error stopping HydrationApi:', error });
export async function updateFuseApp() {
await fuseApp.update();
}

export function getFuseDriveState() {
if (!fuseApp) {
return 'UNMOUNTED';
}
return fuseApp.getStatus();
}
Loading
Loading