Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions routes/github/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { Request, Response } from "express";
import { seconds } from "../../utils/misc.js";
import { getCommits } from "./lib/commits.js";

export default async function route(req: Request, res: Response) {
type Params = { org: string; repo: string };
type Query = { from: string; to?: string; path?: string };
type IRequest = Request<Params, any, any, Query>;

export default async function route(req: IRequest, res: Response) {
const { org, repo } = req.params;
const { from, to , path } = req.query;
const { from, to, path } = req.query;
if (!from || typeof from !== "string") {
res.set("Content-Type", "text/plain");
return res.status(400).send("query parameter 'from' is required");
Expand Down Expand Up @@ -32,6 +36,7 @@ export default async function route(req: Request, res: Response) {
}
res.json(commits);
} catch (error) {
res.set("Content-Type", "text/plain");
res.status(404).send(error.message);
}
}
5 changes: 4 additions & 1 deletion routes/github/contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const cache = new DiskCache<null | Contributors>({
path: "github/contributors",
});

export default async function route(req: Request, res: Response) {
type Params = { org: string; repo: string };
type IRequest = Request<Params>;

export default async function route(req: IRequest, res: Response) {
const { org, repo } = req.params;
const cacheKey = `${org}/${repo}`;

Expand Down
11 changes: 7 additions & 4 deletions routes/w3c/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const LEGACY_SHORTNAMES = new Map([
["i18n", "i18n-core"], // more than 10 instances
]);

export default async function route(req: Request, res: Response) {
type Params = { shortname?: string; type?: string };
type IRequest = Request<Params>;

export default async function route(req: IRequest, res: Response) {
const { shortname, type } = req.params;
if (!shortname) {
if (req.headers.accept?.includes("text/html")) {
Expand All @@ -57,7 +60,7 @@ export default async function route(req: Request, res: Response) {
}

try {
const requestedType = type as GroupType;
const requestedType = type as GroupType | undefined;
const groupInfo = await getGroupInfo(shortname, requestedType);
res.set("Cache-Control", `max-age=${seconds("24h")}`);
res.json(groupInfo);
Expand All @@ -70,7 +73,7 @@ export default async function route(req: Request, res: Response) {

async function getGroupInfo(
shortname: GroupMeta["name"],
requestedType: GroupType,
requestedType?: GroupType,
) {
const cacheKey = `${shortname}/${requestedType || ""}`;
if (cache.expires(cacheKey) > 1000) {
Expand Down Expand Up @@ -160,7 +163,7 @@ async function getPatentPolicy(
}
}

function getGroupMeta(shortname: string, requestedType: GroupType) {
function getGroupMeta(shortname: string, requestedType?: GroupType) {
const types = requestedType
? [requestedType]
: (Object.keys(groups) as GroupType[]);
Expand Down
2 changes: 1 addition & 1 deletion routes/w3c/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import cors from "cors";
import groupsRoute from "./group.js";

const w3c = Router();
w3c.get("/groups/:shortname?/:type?", cors(), groupsRoute);
w3c.get("/groups{/:shortname}{/:type}", cors(), groupsRoute);
Comment thread
sidvishnoi marked this conversation as resolved.

export default w3c;
2 changes: 1 addition & 1 deletion routes/xref/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ xref
.options("/search", cors({ methods: ["POST", "GET"], maxAge: ms("1day") }))
.get("/search", cors(), searchRouteGet)
.post("/search", express.json({ limit: "2mb" }), cors(), searchRoutePost);
xref.get("/meta/:field?", cors(), metaRoute);
xref.get("/meta{/:field}", cors(), metaRoute);
xref.post("/update", authGithubWebhook(env("W3C_WEBREF_SECRET")), updateRoute);
xref.use("/data", express.static(path.join(DATA_DIR, "xref")));

Expand Down
2 changes: 1 addition & 1 deletion scripts/update-w3c-groups-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default async function update() {
case "group":
return g;
case "tf":
return g.members;
return g.members || [];
default:
return [];
}
Expand Down
Loading