Skip to content

Commit

Permalink
fix: convert stream
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhengxu2018 committed Aug 29, 2024
1 parent 732be72 commit 63d610b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/port/controller/package/DownloadPackageVersionTar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PassThrough } from 'node:stream';
import { pipeline } from 'node:stream';
import {
NotFoundError,
} from 'egg-errors';
Expand Down Expand Up @@ -73,7 +75,13 @@ export class DownloadPackageVersionTarController extends AbstractController {
// proxy mode package version not found.
const tgzStream = await this.getTgzProxyStream(ctx, fullname, version);
this.packageManagerService.plusPackageVersionCounter(fullname, version);
return tgzStream;
const passThroughRemoteStream = new PassThrough();
pipeline(
tgzStream,
passThroughRemoteStream,
);
ctx.attachment(`${filenameWithVersion}.tgz`);
return passThroughRemoteStream;
}
throw error;
}
Expand Down Expand Up @@ -113,7 +121,7 @@ export class DownloadPackageVersionTarController extends AbstractController {
}

private async getTgzProxyStream(ctx: EggContext, fullname: string, version: string) {
const { res: tgzStream, headers, status } = await this.proxyCacheService.getPackageVersionTarResponse(fullname, ctx);
const { headers, status, res } = await this.proxyCacheService.getPackageVersionTarResponse(fullname, ctx);
ctx.status = status;
ctx.set(headers as { [key: string]: string | string[] });
ctx.runInBackground(async () => {
Expand All @@ -127,6 +135,6 @@ export class DownloadPackageVersionTarController extends AbstractController {
ctx.logger.info('[DownloadPackageVersionTarController.createSyncTask:success] taskId: %s, fullname: %s',
task.taskId, fullname);
});
return tgzStream;
return res;
}
}

0 comments on commit 63d610b

Please sign in to comment.