Skip to content

Commit

Permalink
fix: tarball urls for web/package (fix #1714) (#1716)
Browse files Browse the repository at this point in the history
  • Loading branch information
stek29 authored Feb 25, 2020
1 parent 1f3f8cd commit 70a93da
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/api/web/endpoint/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
parseReadme,
formatAuthor,
convertDistRemoteToLocalTarballUrls,
getLocalRegistryTarballUri,
isVersionValid
} from '../../../lib/utils';
import { allow } from '../../middleware';
Expand All @@ -21,7 +22,7 @@ const getOrder = (order = 'asc') => {
return order === 'asc';
};

export type PackcageAuthor = Package & { author: any };
export type PackcageExt = Package & { author: any, dist?: {tarball: string} };

function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth, config: Config): void {
const can = allow(auth);
Expand Down Expand Up @@ -53,8 +54,8 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth,
throw err;
}

async function processPermissionsPackages(packages: PackcageAuthor[] = []): Promise<any> {
const permissions: PackcageAuthor[] = [];
async function processPackages(packages: PackcageExt[] = []): Promise<any> {
const permissions: PackcageExt[] = [];
const packgesCopy = packages.slice();
for (const pkg of packgesCopy) {
const pkgCopy = { ...pkg };
Expand All @@ -64,6 +65,9 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth,
if (config.web) {
pkgCopy.author.avatar = generateGravatarUrl(pkgCopy.author.email, config.web.gravatar);
}
if (!_.isNil(pkgCopy.dist) && !_.isNull(pkgCopy.dist.tarball)) {
pkgCopy.dist.tarball = getLocalRegistryTarballUri(pkgCopy.dist.tarball, pkg.name, req, config.url_prefix);
}
permissions.push(pkgCopy);
}
} catch (err) {
Expand All @@ -79,7 +83,7 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth,
// @ts-ignore
const order: boolean = config.web ? getOrder(web.sort_packages) : true;

next(sortByName(await processPermissionsPackages(packages), order));
next(sortByName(await processPackages(packages), order));
});
});

Expand Down

0 comments on commit 70a93da

Please sign in to comment.