diff --git a/app/core/service/BinarySyncerService.ts b/app/core/service/BinarySyncerService.ts index e7808d1d7..0bb7c9849 100644 --- a/app/core/service/BinarySyncerService.ts +++ b/app/core/service/BinarySyncerService.ts @@ -250,6 +250,9 @@ export class BinarySyncerService extends AbstractService { for (const item of existsItems) { existsMap.set(item.name, item); } + const latestItem = sortBy(fetchItems, item => { + return new Date(item.date); + }).pop(); const diffItems: { item: Binary; reason: string }[] = []; for (const item of fetchItems) { const existsItem = existsMap.get(item.name); @@ -276,7 +279,7 @@ export class BinarySyncerService extends AbstractService { existsItem.ignoreDownloadStatuses = item.ignoreDownloadStatuses; existsItem.date = item.date; } else if (dir.endsWith(latestVersionParent)) { - const isLatestItem = sortBy(fetchItems, [ 'date' ]).pop()?.name === item.name; + const isLatestItem = latestItem?.name === item.name; if (isLatestItem && existsItem.isDir) { diffItems.push({ item: existsItem, diff --git a/test/core/service/BinarySyncerService/executeTask.test.ts b/test/core/service/BinarySyncerService/executeTask.test.ts index 8896a06af..cfe974b87 100644 --- a/test/core/service/BinarySyncerService/executeTask.test.ts +++ b/test/core/service/BinarySyncerService/executeTask.test.ts @@ -296,6 +296,9 @@ describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => { return { items: [ { name: 'latest/', isDir: true, url: '', size: '-', date: '17-Dec-2021 23:17' }, + { name: 'old/', isDir: true, url: '', size: '-', date: '15-Dec-2021 23:17' }, + // old2 使用 yyyy-mm-dd 日期格式,用于检查 diff 的日期排序 + { name: 'old2/', isDir: true, url: '', size: '-', date: '2021-11-10T05:49:35.321Z' }, { name: 'index.json', isDir: false, url: 'https://nodejs.org/dist/index.json', size: '219862', date: '17-Dec-2021 23:16' }, ], }; @@ -324,7 +327,7 @@ describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => { assert(stream); let log = await TestUtil.readStreamToLog(stream); // console.log(log); - assert(log.includes('Syncing diff: 2 => 2')); + assert(log.includes('Syncing diff: 4 => 4')); assert(log.includes('[/] 🟢 Synced dir success')); assert(log.includes('[/latest/] 🟢 Synced dir success')); assert(log.includes('[/latest/docs/] 🟢 Synced dir success')); @@ -339,9 +342,9 @@ describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => { log = await TestUtil.readStreamToLog(stream); // console.log(log); assert(log.includes('reason: revalidate latest version')); - assert(log.includes('Syncing diff: 2 => 1')); + assert(log.includes('Syncing diff: 4 => 1')); assert(log.includes('[/] 🟢 Synced dir success')); - + assert(log.includes('[/latest/] 🟢 Synced dir success')); // mock version change // console.log(binaryRepository.findBinary('node'));