Further progress on registry UI.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Add package README view support and style adjustments
This commit is contained in:
@ -47,6 +47,8 @@ export const basicauth = (realm: string) => (next: ABC.HandlerFunc) => (
|
||||
|
||||
if (config?.user[username]?.password === passwd) {
|
||||
console.log("User authenticated!");
|
||||
if (!ctx.customContext) ctx.customContext = {};
|
||||
ctx.customContext.user = username;
|
||||
return next(ctx);
|
||||
}
|
||||
}
|
||||
@ -62,6 +64,7 @@ export const basicauth = (realm: string) => (next: ABC.HandlerFunc) => (
|
||||
|
||||
export function extractPackagePath(path: string): [string, string | undefined] {
|
||||
let packageName = "";
|
||||
path = path.toLowerCase();
|
||||
if (path.startsWith("@")) {
|
||||
packageName = "@";
|
||||
path = path.slice(1);
|
||||
@ -84,3 +87,48 @@ export function extractPackagePath(path: string): [string, string | undefined] {
|
||||
|
||||
return [packageName, packageVersion];
|
||||
}
|
||||
|
||||
import db from "./db.ts";
|
||||
|
||||
import bucket from "./s3.ts";
|
||||
import { S3 } from "./deps.ts";
|
||||
|
||||
export async function getFile(
|
||||
pkgName: string,
|
||||
version: string | null | undefined,
|
||||
file: string
|
||||
): Promise<Uint8Array | null> {
|
||||
const meta = await db.package.findOne({ name: pkgName });
|
||||
|
||||
if (!meta || meta.versions.length < 1) return null;
|
||||
|
||||
const versions = meta.versions.sort(sortVersions).reverse();
|
||||
|
||||
if (!version) {
|
||||
version = versions[0];
|
||||
} else {
|
||||
const v = versions.filter((e) => e.startsWith(version as string));
|
||||
if (v.length < 1) return null;
|
||||
version = v[0];
|
||||
}
|
||||
|
||||
const bucketPath = (
|
||||
"packages/" +
|
||||
pkgName +
|
||||
"/" +
|
||||
version +
|
||||
"/" +
|
||||
file
|
||||
).replace(/@/g, "§");
|
||||
|
||||
console.log("Getting file from:", bucketPath);
|
||||
|
||||
try {
|
||||
const data = (await bucket.getObject(bucketPath))?.body;
|
||||
return data;
|
||||
} catch (err) {
|
||||
const msg = err.message as string;
|
||||
if (msg.indexOf("404") >= 0) return null;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user