From d952d2795ad742be2fb4e15146a2ee1194d29dbf Mon Sep 17 00:00:00 2001 From: "i18n.site" Date: Thu, 17 Oct 2024 17:33:47 +0800 Subject: [PATCH 1/5] Update PackageVersionFileController.ts fix https://github.com/cnpm/cnpmcore/issues/696 --- app/port/controller/PackageVersionFileController.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/port/controller/PackageVersionFileController.ts b/app/port/controller/PackageVersionFileController.ts index d68db1ed..8881ed0e 100644 --- a/app/port/controller/PackageVersionFileController.ts +++ b/app/port/controller/PackageVersionFileController.ts @@ -170,6 +170,18 @@ export class PackageVersionFileController extends AbstractController { } return await this.distRepository.getDistStream(file.dist); } + + @HTTPMethod({ + path: `/:fullname@versionSpec/:path(.+)`, + method: HTTPMethodEnum.GET, + }) + async rawNpm(@Context() ctx: EggContext, + @HTTPParam() fullname: string, + @HTTPParam() versionSpec: string, + @HTTPParam() path: string, + @HTTPQuery() meta: string) { + return await this.raw(ctx, fullname, versionSpec, filepath, meta); + } /** * compatibility with unpkg From 7fef0b50f481ad3eccf16b7b62919ba719ce0f89 Mon Sep 17 00:00:00 2001 From: "i18n.site" Date: Thu, 17 Oct 2024 17:35:56 +0800 Subject: [PATCH 2/5] Update PackageVersionFileController.ts --- app/port/controller/PackageVersionFileController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/port/controller/PackageVersionFileController.ts b/app/port/controller/PackageVersionFileController.ts index 8881ed0e..74f6a455 100644 --- a/app/port/controller/PackageVersionFileController.ts +++ b/app/port/controller/PackageVersionFileController.ts @@ -172,7 +172,7 @@ export class PackageVersionFileController extends AbstractController { } @HTTPMethod({ - path: `/:fullname@versionSpec/:path(.+)`, + path: `/:fullname@:versionSpec/:path(.+)`, method: HTTPMethodEnum.GET, }) async rawNpm(@Context() ctx: EggContext, From d0ecb02fd4b9814edf30e3127be99a8ee1a477d8 Mon Sep 17 00:00:00 2001 From: "i18n.site" Date: Thu, 17 Oct 2024 17:44:03 +0800 Subject: [PATCH 3/5] Update PackageVersionFileController.ts --- app/port/controller/PackageVersionFileController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/port/controller/PackageVersionFileController.ts b/app/port/controller/PackageVersionFileController.ts index 74f6a455..f9ecedfd 100644 --- a/app/port/controller/PackageVersionFileController.ts +++ b/app/port/controller/PackageVersionFileController.ts @@ -180,7 +180,7 @@ export class PackageVersionFileController extends AbstractController { @HTTPParam() versionSpec: string, @HTTPParam() path: string, @HTTPQuery() meta: string) { - return await this.raw(ctx, fullname, versionSpec, filepath, meta); + return await this.raw(ctx, fullname, versionSpec, path, meta); } /** From a65090229d2fea0dd132af99b6d7c167d4c408a4 Mon Sep 17 00:00:00 2001 From: "i18n.site" Date: Fri, 18 Oct 2024 10:41:59 +0800 Subject: [PATCH 4/5] Update PackageVersionFileController.ts --- .../controller/PackageVersionFileController.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/port/controller/PackageVersionFileController.ts b/app/port/controller/PackageVersionFileController.ts index f9ecedfd..99e089a9 100644 --- a/app/port/controller/PackageVersionFileController.ts +++ b/app/port/controller/PackageVersionFileController.ts @@ -172,10 +172,10 @@ export class PackageVersionFileController extends AbstractController { } @HTTPMethod({ - path: `/:fullname@:versionSpec/:path(.+)`, + path: `/npm/:fullname@:versionSpec/:path(.+)`, method: HTTPMethodEnum.GET, }) - async rawNpm(@Context() ctx: EggContext, + async rawNpmVer(@Context() ctx: EggContext, @HTTPParam() fullname: string, @HTTPParam() versionSpec: string, @HTTPParam() path: string, @@ -183,6 +183,17 @@ export class PackageVersionFileController extends AbstractController { return await this.raw(ctx, fullname, versionSpec, path, meta); } + @HTTPMethod({ + path: `/npm/:fullname/:path(.+)`, + method: HTTPMethodEnum.GET, + }) + async rawNpm(@Context() ctx: EggContext, + @HTTPParam() fullname: string, + @HTTPParam() path: string, + @HTTPQuery() meta: string) { + return await this.raw(ctx, fullname, "latest", path, meta); + } + /** * compatibility with unpkg * 1. try to match alias entry. e.g. accessing `index.js` or `index.json` using /index From b911abab76fba1b7abca68ee6b26ae8e07579f75 Mon Sep 17 00:00:00 2001 From: "i18n.site" Date: Fri, 18 Oct 2024 10:50:12 +0800 Subject: [PATCH 5/5] Update PackageVersionFileController.ts --- .../PackageVersionFileController.ts | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/port/controller/PackageVersionFileController.ts b/app/port/controller/PackageVersionFileController.ts index 99e089a9..9e2b0cee 100644 --- a/app/port/controller/PackageVersionFileController.ts +++ b/app/port/controller/PackageVersionFileController.ts @@ -172,28 +172,22 @@ export class PackageVersionFileController extends AbstractController { } @HTTPMethod({ - path: `/npm/:fullname@:versionSpec/:path(.+)`, + path: `/npm/:fullname(${FULLNAME_REG_STRING})/:path(.+)`, method: HTTPMethodEnum.GET, }) async rawNpmVer(@Context() ctx: EggContext, @HTTPParam() fullname: string, - @HTTPParam() versionSpec: string, @HTTPParam() path: string, @HTTPQuery() meta: string) { - return await this.raw(ctx, fullname, versionSpec, path, meta); + let ver = fullname.slice(1).split('@')[1]; + if(ver){ + fullname = fullname.slice(0,-1-ver.length) + }else{ + ver = 'latest' + } + return await this.raw(ctx, fullname, ver, path, meta); } - @HTTPMethod({ - path: `/npm/:fullname/:path(.+)`, - method: HTTPMethodEnum.GET, - }) - async rawNpm(@Context() ctx: EggContext, - @HTTPParam() fullname: string, - @HTTPParam() path: string, - @HTTPQuery() meta: string) { - return await this.raw(ctx, fullname, "latest", path, meta); - } - /** * compatibility with unpkg * 1. try to match alias entry. e.g. accessing `index.js` or `index.json` using /index