Skip to content

Commit 70a93da

Browse files
authoredFeb 25, 2020
fix: tarball urls for web/package (fix #1714) (#1716)

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed
 

‎src/api/web/endpoint/package.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
parseReadme,
88
formatAuthor,
99
convertDistRemoteToLocalTarballUrls,
10+
getLocalRegistryTarballUri,
1011
isVersionValid
1112
} from '../../../lib/utils';
1213
import { allow } from '../../middleware';
@@ -21,7 +22,7 @@ const getOrder = (order = 'asc') => {
2122
return order === 'asc';
2223
};
2324

24-
export type PackcageAuthor = Package & { author: any };
25+
export type PackcageExt = Package & { author: any, dist?: {tarball: string} };
2526

2627
function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth, config: Config): void {
2728
const can = allow(auth);
@@ -53,8 +54,8 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth,
5354
throw err;
5455
}
5556

56-
async function processPermissionsPackages(packages: PackcageAuthor[] = []): Promise<any> {
57-
const permissions: PackcageAuthor[] = [];
57+
async function processPackages(packages: PackcageExt[] = []): Promise<any> {
58+
const permissions: PackcageExt[] = [];
5859
const packgesCopy = packages.slice();
5960
for (const pkg of packgesCopy) {
6061
const pkgCopy = { ...pkg };
@@ -64,6 +65,9 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth,
6465
if (config.web) {
6566
pkgCopy.author.avatar = generateGravatarUrl(pkgCopy.author.email, config.web.gravatar);
6667
}
68+
if (!_.isNil(pkgCopy.dist) && !_.isNull(pkgCopy.dist.tarball)) {
69+
pkgCopy.dist.tarball = getLocalRegistryTarballUri(pkgCopy.dist.tarball, pkg.name, req, config.url_prefix);
70+
}
6771
permissions.push(pkgCopy);
6872
}
6973
} catch (err) {
@@ -79,7 +83,7 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth,
7983
// @ts-ignore
8084
const order: boolean = config.web ? getOrder(web.sort_packages) : true;
8185

82-
next(sortByName(await processPermissionsPackages(packages), order));
86+
next(sortByName(await processPackages(packages), order));
8387
});
8488
});
8589

0 commit comments

Comments
 (0)
Please sign in to comment.