From 2e960f94d386e099db72f40b4068a39cb43245d3 Mon Sep 17 00:00:00 2001 From: sunlei Date: Mon, 22 Jun 2026 18:01:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=81=BF=E5=85=8DNapCat=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E9=95=9C=E5=83=8F=E5=88=9B=E5=BB=BA=E6=97=B6=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E6=8B=89=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qqbot-napcat-container.service.ts | 7 ++++++- .../qqbot-napcat-container.service.spec.ts | 21 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/modules/qqbot/napcat/infrastructure/integration/container/qqbot-napcat-container.service.ts b/src/modules/qqbot/napcat/infrastructure/integration/container/qqbot-napcat-container.service.ts index 3ed2be0..432fac0 100644 --- a/src/modules/qqbot/napcat/infrastructure/integration/container/qqbot-napcat-container.service.ts +++ b/src/modules/qqbot/napcat/infrastructure/integration/container/qqbot-napcat-container.service.ts @@ -1402,7 +1402,12 @@ docker logs --since "$SINCE" --tail 300 "$NAME" 2>&1 || true const passwordRunFlag = loginPassword ? ' -e NAPCAT_QUICK_PASSWORD="$NAPCAT_QUICK_PASSWORD" \\\n' : ''; - const pullCmd = input.skipPull ? '' : 'docker pull "$IMAGE" >/dev/null\n'; + const pullCmd = input.skipPull + ? '' + : `if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then + docker pull "$IMAGE" >/dev/null +fi +`; const deviceHeader = input.deviceIdentity ? [ `NAPCAT_HOSTNAME=${this.sh(input.deviceIdentity.hostname)}`, diff --git a/test/qqbot/napcat/qqbot-napcat-container.service.spec.ts b/test/qqbot/napcat/qqbot-napcat-container.service.spec.ts index 82773b0..b3e0c5e 100644 --- a/test/qqbot/napcat/qqbot-napcat-container.service.spec.ts +++ b/test/qqbot/napcat/qqbot-napcat-container.service.spec.ts @@ -436,7 +436,7 @@ describe('QqbotNapcatContainerService', () => { expect(withoutAccount).not.toContain('NAPCAT_QUICK_PASSWORD'); }); - it('skips docker pull when recreating in place for quick login', () => { + it('checks the local image before pulling when creating a container', () => { const service = new QqbotNapcatContainerService( { get: jest.fn().mockReturnValue('') } as any, {} as any, @@ -453,10 +453,21 @@ describe('QqbotNapcatContainerService', () => { token: 'token-test', }; - expect(service.buildRemoteCreateScript(baseInput)).toContain('docker pull'); - expect( - service.buildRemoteCreateScript({ ...baseInput, skipPull: true }), - ).not.toContain('docker pull'); + const createScript = service.buildRemoteCreateScript(baseInput); + expect(createScript).toContain( + 'if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then', + ); + expect(createScript).toContain('docker pull "$IMAGE" >/dev/null'); + expect(createScript.indexOf('docker image inspect')).toBeLessThan( + createScript.indexOf('docker pull "$IMAGE"'), + ); + + const quickLoginScript = service.buildRemoteCreateScript({ + ...baseInput, + skipPull: true, + }); + expect(quickLoginScript).not.toContain('docker image inspect "$IMAGE"'); + expect(quickLoginScript).not.toContain('docker pull'); }); it('generates Chinese desktop runtime flags and account config files', () => {