Skip to content

Commit

Permalink
delete get usage photo
Browse files Browse the repository at this point in the history
  • Loading branch information
ArceDanielShok committed Oct 2, 2024
1 parent c61760e commit a18c669
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
21 changes: 21 additions & 0 deletions src/apps/backups/Backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AbsolutePath } from '../../context/local/localFile/infrastructure/Absol
import LocalTreeBuilder from '../../context/local/localTree/application/LocalTreeBuilder';
import { LocalTree } from '../../context/local/localTree/domain/LocalTree';
import { File } from '../../context/virtual-drive/files/domain/File';
import { Folder } from '../../context/virtual-drive/folders/domain/Folder';
import { SimpleFolderCreator } from '../../context/virtual-drive/folders/application/create/SimpleFolderCreator';
import { BackupInfo } from './BackupInfo';
import { BackupsIPCRenderer } from './BackupsIPCRenderer';
Expand All @@ -32,6 +33,7 @@ export class Backup {
private readonly fileBatchUploader: FileBatchUploader,
private readonly fileBatchUpdater: FileBatchUpdater,
private readonly remoteFileDeleter: FileDeleter,
// private readonly remoteFolderDeleter: FileDeleter,
private readonly simpleFolderCreator: SimpleFolderCreator,
private readonly userAvaliableSpaceValidator: UserAvaliableSpaceValidator
) {}
Expand Down Expand Up @@ -133,6 +135,8 @@ export class Backup {
Logger.info('[BACKUPS] Backing folders');
Logger.info('[BACKUPS] Folders added', diff.added.length);

// const { added, modified, deleted } = diff;

await Promise.all(
diff.added.map(async (localFolder) => {
const relativePath = relativeV2(local.root.path, localFolder.path);
Expand Down Expand Up @@ -260,4 +264,21 @@ export class Backup {
this.backed += deleted.length;
BackupsIPCRenderer.send('backups.progress-update', this.backed);
}

// private async deleteRemoteFolders(
// deleted: Array<Folder>,
// abortController: AbortController
// ) {
// for (const folder of deleted) {
// if (abortController.signal.aborted) {
// return;
// }

// // eslint-disable-next-line no-await-in-loop
// await this.remoteFileDeleter.run(folder);
// }

// this.backed += deleted.length;
// BackupsIPCRenderer.send('backups.progress-update', this.backed);
// }
}
16 changes: 11 additions & 5 deletions src/apps/main/usage/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Logger from 'electron-log';
import { ipcMain } from 'electron';
import eventBus from '../event-bus';
import { buildUsageService } from './serviceBuilder';
Expand All @@ -15,13 +16,18 @@ function registerUsageHandlers() {
});

AccountIpcMain.handle('account.get-usage', async () => {
if (!service) {
service = buildUsageService();
}
try {
if (!service) {
service = buildUsageService();
}

const raw = await service.raw();
const raw = await service.raw();

return raw;
return raw;
} catch (error) {
Logger.error('Error getting usage', error);
throw error;
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/apps/main/usage/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class UserUsageService {
) {}

private async getPhotosUsage(): Promise<number> {
const { usage } = await this.photos.getUsage();
return usage;
// const { usage } = await this.photos.getUsage();
return 0;
}

private async getDriveUsage(): Promise<number> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export class CachedHttpUserUsageRepository implements UserUsageRepository {
if (this.cachedUserUsage) return this.cachedUserUsage;

const drive = await this.getDriveUsage();
const { usage: photos } = await this.photosSubmodule.getUsage();
// const { usage: photos } = await this.photosSubmodule.getUsage();
const limit = await this.getLimit();

const usage = UserUsage.from({
drive,
photos,
photos: 0,
limit,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export class CachedHttpUserUsageRepository implements UserUsageRepository {
) {}

private async getDriveUsage(): Promise<number> {
const response = await this.driveClient.get(
`${process.env.API_URL}/usage`
);
const response = await this.driveClient.get(`${process.env.API_URL}/usage`);

if (response.status !== 200) {
throw new Error('Error retriving drive usage');
Expand All @@ -40,12 +38,12 @@ export class CachedHttpUserUsageRepository implements UserUsageRepository {
if (this.cahdedUserUsage) return this.cahdedUserUsage;

const drive = await this.getDriveUsage();
const { usage: photos } = await this.photosSubmodule.getUsage();
// const { usage: photos } = await this.photosSubmodule.getUsage();
const limit = await this.getLimit();

const usage = UserUsage.from({
drive,
photos,
photos: 0,
limit,
});

Expand Down

0 comments on commit a18c669

Please sign in to comment.