-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrest-routes.ts
More file actions
80 lines (76 loc) · 2.36 KB
/
rest-routes.ts
File metadata and controls
80 lines (76 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { createApp } from "@aklinker1/zeta";
import { z } from "zod";
import { contextPlugin } from "../plugins/context-plugin";
import { NotFoundHttpError } from "@aklinker1/zeta";
import { HttpStatus } from "@aklinker1/zeta";
export const restRoutes = createApp()
.use(contextPlugin)
.get(
"/api/rest/chrome-extensions/:id/screenshots/:index",
{
operationId: "chromeScreenshotRedirect",
tags: ["Chrome Extensions"],
description:
"Redirect to a screenshot's URL from the Chrome Web Store listing",
params: z.object({
id: z.string(),
index: z.coerce.number().int().min(0),
}),
},
async ({ params, chrome, set }) => {
const screenshotUrl = await chrome.getScreenshotUrl(
params.id,
params.index,
);
if (!screenshotUrl)
throw new NotFoundHttpError("Extension or screenshot not found");
set.status = HttpStatus.Found;
set.headers["Location"] = screenshotUrl;
},
)
.get(
"/api/rest/firefox-addons/:addonId/screenshots/:index",
{
operationId: "firefoxScreenshotRedirect",
tags: ["Firefox Addons"],
description:
"Redirect to a screenshot's URL from the Firefox Addons listing.",
params: z.object({
addonId: z.string(),
index: z.coerce.number().int().min(0),
}),
},
async ({ params, firefox, set }) => {
const screenshotUrl = await firefox.getScreenshotUrl(
params.addonId,
params.index,
);
if (!screenshotUrl)
throw new NotFoundHttpError("Extension or screenshot not found");
set.status = HttpStatus.Found;
set.headers["Location"] = screenshotUrl;
},
)
.get(
"/api/rest/edge-addons/:addonId/screenshots/:index",
{
operationId: "edgeScreenshotRedirect",
tags: ["Firefox Addons"],
description:
"Redirect to a screenshot's URL from the Edge Addons listing.",
params: z.object({
addonId: z.string(),
index: z.coerce.number().int().min(0),
}),
},
async ({ params, edge, set }) => {
const screenshotUrl = await edge.getScreenshotUrl(
params.addonId,
params.index,
);
if (!screenshotUrl)
throw new NotFoundHttpError("Extension or screenshot not found");
set.status = HttpStatus.Found;
set.headers["Location"] = screenshotUrl;
},
);