diff --git a/app/port/controller/AbstractController.ts b/app/port/controller/AbstractController.ts index 9b5f8326..30c41f2e 100644 --- a/app/port/controller/AbstractController.ts +++ b/app/port/controller/AbstractController.ts @@ -146,25 +146,25 @@ export abstract class AbstractController extends MiddlewareController { return new UnavailableForLegalReasonsError(`${message}, reason: ${reason}`); } - protected async getPackageEntityByFullname(fullname: string): Promise { + protected async getPackageEntityByFullname(fullname: string, allowSync?: boolean): Promise { const [ scope, name ] = getScopeAndName(fullname); - return await this.getPackageEntity(scope, name); + return await this.getPackageEntity(scope, name, allowSync); } // try to get package entity, throw NotFoundError when package not exists - protected async getPackageEntity(scope: string, name: string): Promise { + protected async getPackageEntity(scope: string, name: string, allowSync?:boolean): Promise { const packageEntity = await this.packageRepository.findPackage(scope, name); if (!packageEntity) { const fullname = getFullname(scope, name); - throw this.createPackageNotFoundErrorWithRedirect(fullname); + throw this.createPackageNotFoundErrorWithRedirect(fullname, undefined, allowSync); } return packageEntity; } - protected async getPackageVersionEntity(pkg: PackageEntity, version: string): Promise { + protected async getPackageVersionEntity(pkg: PackageEntity, version: string, allowSync?: boolean): Promise { const packageVersion = await this.packageRepository.findPackageVersion(pkg.packageId, version); if (!packageVersion) { - throw this.createPackageNotFoundErrorWithRedirect(pkg.fullname, version); + throw this.createPackageNotFoundErrorWithRedirect(pkg.fullname, version, allowSync); } return packageVersion; } diff --git a/app/port/controller/package/DownloadPackageVersionTar.ts b/app/port/controller/package/DownloadPackageVersionTar.ts index dd9ff0bb..c14763ca 100644 --- a/app/port/controller/package/DownloadPackageVersionTar.ts +++ b/app/port/controller/package/DownloadPackageVersionTar.ts @@ -28,14 +28,15 @@ export class DownloadPackageVersionTarController extends AbstractController { method: HTTPMethodEnum.GET, }) async download(@Context() ctx: EggContext, @HTTPParam() fullname: string, @HTTPParam() filenameWithVersion: string) { - // try nfs url first, avoid db query + // can not try nfs url first, pnpm project with lock will try to get tgz file path directly. // tgz file storeKey: `/packages/${this.fullname}/${version}/${filename}` const version = this.getAndCheckVersionFromFilename(ctx, fullname, filenameWithVersion); const storeKey = `/packages/${fullname}/${version}/${filenameWithVersion}.tgz`; const downloadUrl = await this.nfsAdapter.getDownloadUrl(storeKey); // check package version in database - const pkg = await this.getPackageEntityByFullname(fullname); - const packageVersion = await this.getPackageVersionEntity(pkg, version); + const allowSync = this.getAllowSync(ctx); + const pkg = await this.getPackageEntityByFullname(fullname, allowSync); + const packageVersion = await this.getPackageVersionEntity(pkg, version, allowSync); // read by nfs url if (downloadUrl) {