Skip to content

Commit 30560b3

Browse files
Enhance checksum verification in downloadProxy function and improve error handling; remove unused APPDATA constant
1 parent 4e96443 commit 30560b3

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/core/updater.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,21 @@ export async function downloadProxy(version: string, targetPath: string = PATHS.
8080

8181
if (checksumUrl) {
8282
logger.info('Verifying checksum...');
83-
// ... checksum logic ...
84-
// For now, skipping strict checksum implementation details as per previous context,
85-
// but ensuring the structure supports it.
83+
try {
84+
const checksumResponse = await axios.get(checksumUrl);
85+
const expectedChecksum = checksumResponse.data.trim().split(' ')[0];
86+
const isValid = await verifyChecksum(targetPath, expectedChecksum);
87+
88+
if (!isValid) {
89+
throw new Error('Checksum verification failed');
90+
}
91+
logger.info('Checksum verified.');
92+
} catch (err) {
93+
logger.warn('Failed to verify checksum', err);
94+
// If verification fails, we should probably remove the file
95+
await fs.remove(targetPath);
96+
throw err;
97+
}
8698
}
8799

88100
} catch (error) {

src/system/paths.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import path from 'path';
22
import os from 'os';
33

44
const PROGRAM_DATA = process.env.ProgramData || 'C:\\ProgramData';
5-
const APP_DATA = process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming');
65
const LOCAL_APP_DATA = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
76

87
export const USER_PATHS = {

src/system/powershell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export async function runPs(command: string): Promise<string> {
55
try {
66
const { stdout } = await execa('powershell', ['-NoProfile', '-NonInteractive', '-Command', command]);
77
return stdout.trim();
8-
} catch (error: any) {
8+
} catch (error) {
99
logger.debug(`PowerShell command failed: ${command}`, error);
1010
throw error;
1111
}

0 commit comments

Comments
 (0)