Skip to content

Commit b2cf637

Browse files
authored
Remove in memory event repository (#853)
1 parent 1420b37 commit b2cf637

26 files changed

Lines changed: 98 additions & 344 deletions

File tree

‎src/apps/main/device/service.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,14 +544,12 @@ async function downloadDeviceBackupZip({
544544

545545
const folders = await fetchFolders({ folderUuids: folderUuidsToDownload });
546546

547-
const networkApiUrl = process.env.BRIDGE_URL;
548547
const bridgeUser = user.bridgeUser;
549548
const bridgePass = user.userId;
550549
const encryptionKey = getConfig().mnemonic;
551550

552551
await downloadFolder(
553552
device.name,
554-
networkApiUrl,
555553
folders.map((folder) => folder.uuid),
556554
path,
557555
{

‎src/apps/main/network/download.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ async function writeReadableStreamToFile(readableStream: ReadableStream<Uint8Arr
4848

4949
export async function downloadFolder(
5050
deviceName: string,
51-
networkApiUrl: string,
5251
foldersUuid: string[],
5352
targetPath: PathLike,
5453
environment: {
@@ -117,7 +116,6 @@ export async function downloadFolder(
117116
Logger.info('Downloading file:', filePath);
118117

119118
const fileStream = await downloadFile({
120-
networkApiUrl,
121119
bucketId: file.bucket,
122120
fileId: file.fileId,
123121
creds: {
@@ -163,13 +161,12 @@ interface MetadataRequiredForDownload {
163161
}
164162

165163
async function getRequiredFileMetadataWithAuth(
166-
networkApiUrl: string,
167164
bucketId: string,
168165
fileId: string,
169166
creds: NetworkCredentials,
170167
): Promise<MetadataRequiredForDownload> {
171-
const fileMeta: FileInfo = await getFileInfoWithAuth(networkApiUrl, bucketId, fileId, creds);
172-
const mirrors: Mirror[] = await getMirrors(networkApiUrl, bucketId, fileId, creds);
168+
const fileMeta: FileInfo = await getFileInfoWithAuth(bucketId, fileId, creds);
169+
const mirrors: Mirror[] = await getMirrors(bucketId, fileId, creds);
173170

174171
return { fileMeta, mirrors };
175172
}
@@ -187,12 +184,12 @@ async function downloadFile(params: IDownloadParams): Promise<ReadableStream<Uin
187184
}
188185

189186
async function _downloadFile(params: IDownloadParams): Promise<ReadableStream<Uint8Array>> {
190-
const { networkApiUrl, bucketId, fileId, creds } = params;
187+
const { bucketId, fileId, creds } = params;
191188

192189
let metadata: MetadataRequiredForDownload;
193190

194191
if (creds) {
195-
metadata = await getRequiredFileMetadataWithAuth(networkApiUrl, bucketId, fileId, creds);
192+
metadata = await getRequiredFileMetadataWithAuth(bucketId, fileId, creds);
196193
} else {
197194
throw new Error('Download error 1');
198195
}

‎src/apps/main/network/download.types.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { DownloadProgressCallback } from '@internxt/inxt-js/build/lib/core';
22
import { NetworkCredentials } from './requests';
33

44
export interface IDownloadParams {
5-
networkApiUrl: string;
65
bucketId: string;
76
fileId: string;
87
creds: NetworkCredentials;

‎src/apps/main/network/requests.ts‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ function getAuthFromCredentials(creds: NetworkCredentials): AxiosBasicCredential
3535
};
3636
}
3737

38-
function getFileInfo(networkApiUrl: string, bucketId: string, fileId: string, opts?: AxiosRequestConfig): Promise<FileInfo> {
38+
function getFileInfo(bucketId: string, fileId: string, opts?: AxiosRequestConfig): Promise<FileInfo> {
3939
const defaultOpts: AxiosRequestConfig = {
4040
method: 'GET',
41-
url: `${networkApiUrl}/buckets/${bucketId}/files/${fileId}/info`,
41+
url: `${process.env.BRIDGE_URL}/buckets/${bucketId}/files/${fileId}/info`,
4242
maxContentLength: Infinity,
4343
};
4444

@@ -52,8 +52,8 @@ function getFileInfo(networkApiUrl: string, bucketId: string, fileId: string, op
5252
});
5353
}
5454

55-
export function getFileInfoWithAuth(networkApiUrl: string, bucketId: string, fileId: string, creds: NetworkCredentials): Promise<FileInfo> {
56-
return getFileInfo(networkApiUrl, bucketId, fileId, {
55+
export function getFileInfoWithAuth(bucketId: string, fileId: string, creds: NetworkCredentials): Promise<FileInfo> {
56+
return getFileInfo(bucketId, fileId, {
5757
auth: getAuthFromCredentials(creds),
5858
});
5959
}
@@ -78,13 +78,7 @@ export interface Mirror {
7878
operation: string;
7979
}
8080

81-
export async function getMirrors(
82-
networkApiUrl: string,
83-
bucketId: string,
84-
fileId: string,
85-
creds: NetworkCredentials | null,
86-
token?: string,
87-
): Promise<Mirror[]> {
81+
export async function getMirrors(bucketId: string, fileId: string, creds: NetworkCredentials | null, token?: string): Promise<Mirror[]> {
8882
const mirrors: Mirror[] = [];
8983
const limit = 3;
9084

@@ -95,7 +89,7 @@ export async function getMirrors(
9589
};
9690

9791
do {
98-
results = (await getFileMirrors(networkApiUrl, bucketId, fileId, limit, mirrors.length, [], requestConfig))
92+
results = (await getFileMirrors(bucketId, fileId, limit, mirrors.length, [], requestConfig))
9993
.filter((m) => !m.parity)
10094
.sort((mA, mB) => mA.index - mB.index);
10195

@@ -110,7 +104,7 @@ export async function getMirrors(
110104
if (farmerIsOk) {
111105
mirror.farmer.address = mirror.farmer.address.trim();
112106
} else {
113-
mirrors[mirror.index] = await replaceMirror(networkApiUrl, bucketId, fileId, mirror.index, [], requestConfig);
107+
mirrors[mirror.index] = await replaceMirror(bucketId, fileId, mirror.index, [], requestConfig);
114108

115109
if (!isFarmerOk(mirrors[mirror.index].farmer)) {
116110
throw new Error('Missing pointer for shard %s' + mirror.hash);
@@ -126,7 +120,6 @@ export async function getMirrors(
126120
}
127121

128122
async function replaceMirror(
129-
networkApiUrl: string,
130123
bucketId: string,
131124
fileId: string,
132125
pointerIndex: number,
@@ -137,7 +130,7 @@ async function replaceMirror(
137130
let mirror: Mirror;
138131

139132
while (!mirrorIsOk) {
140-
const [newMirror] = await getFileMirrors(networkApiUrl, bucketId, fileId, 1, pointerIndex, excludeNodes, opts);
133+
const [newMirror] = await getFileMirrors(bucketId, fileId, 1, pointerIndex, excludeNodes, opts);
141134

142135
mirror = newMirror;
143136
mirrorIsOk = newMirror.farmer && newMirror.farmer.nodeID && newMirror.farmer.port && newMirror.farmer.address ? true : false;
@@ -148,7 +141,6 @@ async function replaceMirror(
148141
}
149142

150143
function getFileMirrors(
151-
networkApiUrl: string,
152144
bucketId: string,
153145
fileId: string,
154146
limit: number | 3,
@@ -157,7 +149,7 @@ function getFileMirrors(
157149
opts?: AxiosRequestConfig,
158150
): Promise<Mirror[]> {
159151
const excludeNodeIds: string = excludeNodes.join(',');
160-
const path = `${networkApiUrl}/buckets/${bucketId}/files/${fileId}`;
152+
const path = `${process.env.BRIDGE_URL}/buckets/${bucketId}/files/${fileId}`;
161153
const queryParams = `?limit=${limit}&skip=${skip}&exclude=${excludeNodeIds}`;
162154

163155
const defaultOpts: AxiosRequestConfig = {

‎src/apps/main/notification-schema.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,4 @@ const FOLDER_CREATED = EVENT.extend({
4040
}),
4141
});
4242

43-
/**
44-
* v2.5.5 Daniel Jiménez
45-
* TODO: Check this event because I think it doesn't exist and the action done with it can be deleted
46-
*/
47-
export const FOLDER_DELETED = EVENT.extend({
48-
event: z.literal('FOLDER_DELETED'),
49-
});
50-
5143
export const NOTIFICATION_SCHEMA = z.union([ITEMS_TO_TRASH, FILE_CREATED, FOLDER_CREATED]);

‎src/apps/main/preload.d.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ declare interface Window {
154154
hasDiscoveredBackups: () => Promise<boolean>;
155155
discoveredBackups: () => Promise<void>;
156156
};
157-
listenersRefreshBackups(callback: (data: any) => void, eventName?: string): () => void;
158-
159157
backups: {
160158
isAvailable: () => Promise<boolean>;
161159
};

‎src/apps/main/preload.js‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,6 @@ contextBridge.exposeInMainWorld('electron', {
308308
ipcRenderer.send('user.set-has-discovered-backups');
309309
},
310310
},
311-
listenersRefreshBackups(callback, eventName = 'refresh-backup') {
312-
const callbackWrapper = (_, data) => {
313-
Logger.info('Refresh backups');
314-
callback(data);
315-
};
316-
317-
ipcRenderer.on(eventName, callbackWrapper);
318-
319-
return () => ipcRenderer.removeListener(eventName, callbackWrapper);
320-
},
321311
backups: {
322312
isAvailable: () => {
323313
return ipcRenderer.invoke('backups:is-available');

‎src/apps/renderer/hooks/backups/useBackups.tsx‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ export function useBackups(): BackupContextProps {
7676
loadBackups();
7777
}, [selected, devices]);
7878

79-
useEffect(() => {
80-
const removeListener = window.electron.listenersRefreshBackups(fetchBackups, 'refresh-backup');
81-
82-
return removeListener;
83-
}, []);
84-
8579
async function addBackup(): Promise<void> {
8680
try {
8781
await window.electron.addBackup();

‎src/apps/sync-engine/callbacks-controllers/controllers/AddController.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export class AddController extends CallbackController {
1616
// - a file has been added
1717
// - a folder has been added
1818
// - a file has been saved
19-
// - after a file has been moved to a folder
2019

2120
constructor(
2221
private readonly absolutePathToRelativeConverter: AbsolutePathToRelativeConverter,

‎src/apps/sync-engine/dependency-injection/boundaryBridge/build.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ export function buildBoundaryBridgeContainer(
99
contentsContainer: ContentsContainer,
1010
filesContainer: FilesContainer,
1111
): BoundaryBridgeContainer {
12-
const fileCreationOrchestrator = new FileCreationOrchestrator(
13-
contentsContainer.contentsUploader,
14-
filesContainer.fileCreator,
15-
filesContainer.sameFileWasMoved,
16-
);
12+
const fileCreationOrchestrator = new FileCreationOrchestrator(contentsContainer.contentsUploader, filesContainer.fileCreator);
1713

1814
const fileSyncOrchestrator = new FileSyncOrchestrator(filesContainer.fileSyncronizer);
1915

0 commit comments

Comments
 (0)