Skip to content

Commit

Permalink
fix: can create sync task by 'GET /:fullname/-/:filenameWithVersion.tgz'
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhengxu2018 committed Jun 19, 2023
1 parent 84499bc commit 80a7ebf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions app/port/controller/AbstractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,25 @@ export abstract class AbstractController extends MiddlewareController {
return new UnavailableForLegalReasonsError(`${message}, reason: ${reason}`);
}

protected async getPackageEntityByFullname(fullname: string): Promise<PackageEntity> {
protected async getPackageEntityByFullname(fullname: string, allowSync?: boolean): Promise<PackageEntity> {
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<PackageEntity> {
protected async getPackageEntity(scope: string, name: string, allowSync?:boolean): Promise<PackageEntity> {
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<PackageVersionEntity> {
protected async getPackageVersionEntity(pkg: PackageEntity, version: string, allowSync?: boolean): Promise<PackageVersionEntity> {
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;
}
Expand Down
7 changes: 4 additions & 3 deletions app/port/controller/package/DownloadPackageVersionTar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 80a7ebf

Please sign in to comment.