Skip to content

Commit 4d12a51

Browse files
fix: Auto-sync now only downloads truly new scripts
- Fixed isScriptDownloaded logic to check ALL script files before considering a script downloaded - Modified auto-sync to filter and only process scripts that haven't been downloaded before - Added proper logging to show how many new scripts were found vs total scripts - Made isScriptDownloaded method public in TypeScript version This ensures auto-sync only downloads scripts that are actually new, not re-downloading existing scripts or processing unchanged content.
1 parent e0bea6c commit 4d12a51

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

src/server/services/autoSyncService.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,26 @@ export class AutoSyncService {
264264
// @ts-ignore - syncedFiles exists in the JavaScript version
265265
if (syncResult.syncedFiles && syncResult.syncedFiles.length > 0) {
266266
// @ts-ignore - syncedFiles exists in the JavaScript version
267-
console.log(`Loading scripts for ${syncResult.syncedFiles.length} synced JSON files...`);
267+
console.log(`Processing ${syncResult.syncedFiles.length} synced JSON files for new scripts...`);
268+
269+
// Get all scripts from synced files
268270
// @ts-ignore - syncedFiles exists in the JavaScript version
269-
const syncedScripts = await githubJsonService.getScriptsForFiles(syncResult.syncedFiles);
271+
const allSyncedScripts = await githubJsonService.getScriptsForFiles(syncResult.syncedFiles);
272+
273+
// Filter to only truly NEW scripts (not previously downloaded)
274+
const newScripts = [];
275+
for (const script of allSyncedScripts) {
276+
const isDownloaded = await scriptDownloaderService.isScriptDownloaded(script);
277+
if (!isDownloaded) {
278+
newScripts.push(script);
279+
}
280+
}
281+
282+
console.log(`Found ${newScripts.length} new scripts out of ${allSyncedScripts.length} total scripts`);
270283

271-
if (settings.autoDownloadNew) {
272-
console.log('Auto-downloading new scripts from synced files...');
273-
const downloadResult = await scriptDownloaderService.autoDownloadNewScripts(syncedScripts);
284+
if (settings.autoDownloadNew && newScripts.length > 0) {
285+
console.log(`Auto-downloading ${newScripts.length} new scripts...`);
286+
const downloadResult = await scriptDownloaderService.autoDownloadNewScripts(newScripts);
274287
// @ts-ignore - Type assertion needed for dynamic assignment
275288
results.newScripts = downloadResult.downloaded;
276289
// @ts-ignore - Type assertion needed for dynamic assignment
@@ -279,7 +292,7 @@ export class AutoSyncService {
279292

280293
if (settings.autoUpdateExisting) {
281294
console.log('Auto-updating existing scripts from synced files...');
282-
const updateResult = await scriptDownloaderService.autoUpdateExistingScripts(syncedScripts);
295+
const updateResult = await scriptDownloaderService.autoUpdateExistingScripts(allSyncedScripts);
283296
// @ts-ignore - Type assertion needed for dynamic assignment
284297
results.updatedScripts = updateResult.updated;
285298
// @ts-ignore - Type assertion needed for dynamic assignment

src/server/services/scriptDownloader.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ echo "Script downloaded: ${filePath}"
220220
async isScriptDownloaded(script) {
221221
if (!script.install_methods?.length) return false;
222222

223+
// Check if ALL script files are downloaded
223224
for (const method of script.install_methods) {
224225
if (method.script) {
225226
const scriptPath = method.script;
@@ -261,15 +262,17 @@ echo "Script downloaded: ${filePath}"
261262

262263
try {
263264
await readFile(filePath, 'utf8');
264-
return true; // File exists
265+
// File exists, continue checking other methods
265266
} catch {
266-
// File doesn't exist, continue checking other methods
267+
// File doesn't exist, script is not fully downloaded
268+
return false;
267269
}
268270
}
269271
}
270272
}
271273

272-
return false;
274+
// All files exist, script is downloaded
275+
return true;
273276
}
274277

275278
/**

src/server/services/scriptDownloader.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,10 @@ export class ScriptDownloaderService {
239239
/**
240240
* Check if a script is already downloaded
241241
*/
242-
private async isScriptDownloaded(script: Script): Promise<boolean> {
242+
async isScriptDownloaded(script: Script): Promise<boolean> {
243243
if (!script.install_methods?.length) return false;
244244

245+
// Check if ALL script files are downloaded
245246
for (const method of script.install_methods) {
246247
if (method.script) {
247248
const scriptPath = method.script;
@@ -283,15 +284,17 @@ export class ScriptDownloaderService {
283284

284285
try {
285286
await readFile(filePath, 'utf8');
286-
return true; // File exists
287+
// File exists, continue checking other methods
287288
} catch {
288-
// File doesn't exist, continue checking other methods
289+
// File doesn't exist, script is not fully downloaded
290+
return false;
289291
}
290292
}
291293
}
292294
}
293295

294-
return false;
296+
// All files exist, script is downloaded
297+
return true;
295298
}
296299

297300
/**

0 commit comments

Comments
 (0)