Skip to content

Commit 78f1bf8

Browse files
committed
fix: clamp download range and use trailing-slash files root
- Clamp the download range to at least 1 so range<=0 no longer produces an inverted /downloads/range/:from::to/ request - Request the files root with a trailing slash (/files/?) consistent with subdirectory listings and getFileContent
1 parent dfd84c0 commit 78f1bf8

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

apps/web/app/lib/registry/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function getRegistryStats() {
6161
export function getDownloads(pkg: string, range = 7) {
6262
const end = new Date();
6363
const start = new Date();
64-
start.setDate(end.getDate() - (range - 1));
64+
start.setDate(end.getDate() - (Math.max(1, range) - 1));
6565
const fmt = (d: Date) =>
6666
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(
6767
d.getDate(),
@@ -72,7 +72,8 @@ export function getDownloads(pkg: string, range = 7) {
7272
}
7373

7474
export function getDir(pkg: string, spec: string, path: string) {
75-
const dirPath = path && path !== "/" ? `${encodeFilePath(ensureLeadingSlash(path))}/` : "";
75+
const dirPath =
76+
path && path !== "/" ? `${encodeFilePath(ensureLeadingSlash(path))}/` : "/";
7677
return registryJson<RegistryFilesResponse>(
7778
`/${pkgPath(pkg)}/${encodeURIComponent(spec)}/files${dirPath}?meta`,
7879
);

0 commit comments

Comments
 (0)