Skip to content

Commit f5cd004

Browse files
authored
Address style issues raised by Prettier. (#2621)
1 parent ca8222c commit f5cd004

File tree

6 files changed

+57
-58
lines changed

6 files changed

+57
-58
lines changed

packages/gui/src/components/nfts/NFTContextualActions.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ type NFTDownloadContextualActionProps = NFTContextualActionProps;
394394
function NFTDownloadContextualAction(props: NFTDownloadContextualActionProps) {
395395
const { selection } = props;
396396

397-
const selectedNfts: (NFTInfo & { $nftId: string})[] = selection?.items || [];
397+
const selectedNfts: (NFTInfo & { $nftId: string })[] = selection?.items || [];
398398

399399
const openDialog = useOpenDialog();
400400
const [, setSelectedNFTIds] = useLocalStorage('gallery-selected-nfts', []);
@@ -435,7 +435,7 @@ function NFTDownloadContextualAction(props: NFTDownloadContextualActionProps) {
435435
throw new Error('No data URI found for NFT');
436436
}
437437

438-
const nftId = nft.$nftId || toBech32m(nft.launcherId, 'nft')
438+
const nftId = nft.$nftId || toBech32m(nft.launcherId, 'nft');
439439

440440
const ext = getFileExtension(url);
441441
const filename = ext ? `${nftId}.${ext}` : nftId;

packages/gui/src/electron/main.tsx

+47-45
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ if (ensureSingleInstance() && ensureCorrectEnvironment()) {
262262
return { err, statusCode, statusMessage, responseBody };
263263
});
264264

265-
266-
267265
ipcMain.handle('showMessageBox', async (_event, options) => dialog.showMessageBox(mainWindow, options));
268266

269267
ipcMain.handle('showOpenDialog', async (_event, options) => dialog.showOpenDialog(options));
@@ -322,53 +320,57 @@ if (ensureSingleInstance() && ensureCorrectEnvironment()) {
322320
return responseObj;
323321
});
324322

323+
ipcMain.handle(
324+
'startMultipleDownload',
325+
async (_event: any, options: { folder: string; tasks: { url: string; filename: string }[] }) => {
326+
/* eslint no-await-in-loop: off -- we want to handle each file separately! */
327+
let totalDownloadedSize = 0;
328+
let successFileCount = 0;
329+
let errorFileCount = 0;
330+
331+
const { folder, tasks } = options;
332+
333+
for (let i = 0; i < tasks.length; i++) {
334+
const { url: downloadUrl, filename } = tasks[i];
335+
336+
try {
337+
const sanitizedFilename = sanitizeFilename(filename);
338+
if (sanitizedFilename !== filename) {
339+
throw new Error(
340+
`Filename ${filename} contains invalid characters. Filename sanitized to ${sanitizedFilename}`,
341+
);
342+
}
343+
344+
const filePath = path.join(folder, sanitizedFilename);
345+
346+
await downloadFile(downloadUrl, filePath, {
347+
onProgress: (progress) => {
348+
mainWindow?.webContents.send('multipleDownloadProgress', {
349+
progress,
350+
url: downloadUrl,
351+
index: i,
352+
total: tasks.length,
353+
});
354+
},
355+
});
325356

326-
ipcMain.handle('startMultipleDownload', async (_event: any, options: { folder: string, tasks: { url: string; filename: string }[] }) => {
327-
/* eslint no-await-in-loop: off -- we want to handle each file separately! */
328-
let totalDownloadedSize = 0;
329-
let successFileCount = 0;
330-
let errorFileCount = 0;
331-
332-
const { folder, tasks } = options;
333-
334-
for (let i = 0; i < tasks.length; i++) {
335-
const { url: downloadUrl, filename } = tasks[i];
336-
337-
try {
338-
const sanitizedFilename = sanitizeFilename(filename);
339-
if (sanitizedFilename !== filename) {
340-
throw new Error(`Filename ${filename} contains invalid characters. Filename sanitized to ${sanitizedFilename}`);
341-
}
342-
343-
const filePath = path.join(folder, sanitizedFilename);
344-
345-
await downloadFile(downloadUrl, filePath, {
346-
onProgress: (progress) => {
347-
mainWindow?.webContents.send('multipleDownloadProgress', {
348-
progress,
349-
url: downloadUrl,
350-
index: i,
351-
total: tasks.length,
352-
});
353-
},
354-
});
355-
356-
const fileStats = await fs.promises.stat(filePath);
357+
const fileStats = await fs.promises.stat(filePath);
357358

358-
totalDownloadedSize += fileStats.size;
359-
successFileCount++;
360-
} catch (e: any) {
361-
if (e.message === 'download aborted' && abortDownloadingFiles) {
362-
break;
359+
totalDownloadedSize += fileStats.size;
360+
successFileCount++;
361+
} catch (e: any) {
362+
if (e.message === 'download aborted' && abortDownloadingFiles) {
363+
break;
364+
}
365+
mainWindow?.webContents.send('errorDownloadingUrl', downloadUrl);
366+
errorFileCount++;
363367
}
364-
mainWindow?.webContents.send('errorDownloadingUrl', downloadUrl);
365-
errorFileCount++;
366368
}
367-
}
368-
abortDownloadingFiles = false;
369-
mainWindow?.webContents.send('multipleDownloadDone', { totalDownloadedSize, successFileCount, errorFileCount });
370-
return true;
371-
});
369+
abortDownloadingFiles = false;
370+
mainWindow?.webContents.send('multipleDownloadDone', { totalDownloadedSize, successFileCount, errorFileCount });
371+
return true;
372+
},
373+
);
372374

373375
ipcMain.handle('abortDownloadingFiles', async (_event: any) => {
374376
abortDownloadingFiles = true;

packages/gui/src/electron/utils/downloadFile.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class WriteStreamPromise {
1313

1414
private writePromises: Promise<void>[] = [];
1515

16-
constructor(private path: string, overrideFile = false) {
16+
constructor(
17+
private path: string,
18+
overrideFile = false,
19+
) {
1720
this.stream = createWriteStream(path, {
1821
flags: overrideFile ? 'w' : 'wx', // w - override if exists, wx - fail if exists
1922
});
@@ -69,13 +72,7 @@ type DownloadFileOptions = {
6972
export default async function downloadFile(
7073
url: string,
7174
localPath: string,
72-
{
73-
timeout = 30_000,
74-
signal,
75-
maxSize = 100 * 1024 * 1024,
76-
onProgress,
77-
overrideFile = false,
78-
}: DownloadFileOptions = {},
75+
{ timeout = 30_000, signal, maxSize = 100 * 1024 * 1024, onProgress, overrideFile = false }: DownloadFileOptions = {},
7976
): Promise<Headers> {
8077
const tempFilePath = `${localPath}.tmp`;
8178
const request = net.request(url);

packages/gui/src/electron/utils/fileExists.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export default async function fileExists(filePath: string): Promise<boolean> {
77
} catch {
88
return false;
99
}
10-
}
10+
}

packages/gui/src/util/getFileExtension.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ describe('getFileExtension', () => {
7272
expect(getFileExtension('https://example.com/file.txt#fragment')).toBe('txt');
7373
expect(getFileExtension('https://example.com/file;param=value.txt')).toBe('txt');
7474
});
75-
});
75+
});

packages/gui/src/util/getFileExtension.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function getFileExtension(url?: string, allowedExtensions?: strin
1616
if (dotIndex === -1 || dotIndex === lastSegment.length - 1) {
1717
return undefined;
1818
}
19-
19+
2020
const extension = lastSegment.substring(dotIndex + 1).toLowerCase();
2121
if (allowedExtensions && !allowedExtensions.includes(extension)) {
2222
return undefined;

0 commit comments

Comments
 (0)