-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathindex.ts
More file actions
75 lines (71 loc) · 2.01 KB
/
index.ts
File metadata and controls
75 lines (71 loc) · 2.01 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
export default {
async fetch(request: Request, env: Env) {
const url = new URL(request.url);
const configValues = {
WORKBENCH_WEB_CONFIGURATION: JSON.stringify({
configurationDefaults: {
"workbench.colorTheme":
url.searchParams.get("theme") === "dark"
? "Solarflare Dark"
: "Solarflare Light",
"workbench.startupEditor": "none",
"editor.minimap.autohide": true,
"files.exclude": {
"*.d.ts": true,
"jsconfig.json": true,
"package.json": true,
"wrangler.toml": true,
},
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 200,
"telemetry.telemetryLevel": "off",
"window.menuBarVisibility": "hidden",
},
productConfiguration: {
nameShort: "Quick Edit",
nameLong: "Cloudflare Workers Quick Edit",
applicationName: "workers-quick-edit",
dataFolderName: ".quick-edit",
version: "1.76.0",
extensionEnabledApiProposals: {
"cloudflare.@cloudflare/quick-edit-extension": [
"fileSearchProvider",
"textSearchProvider",
"ipc",
],
},
},
additionalBuiltinExtensions: [
{
scheme: url.protocol === "https:" ? "https" : "http",
path: "/quick-edit-extension",
authority: url.host,
},
{
scheme: url.protocol === "https:" ? "https" : "http",
path: "/solarflare-theme",
authority: url.host,
},
],
}).replace(/"/g, """),
WORKBENCH_AUTH_SESSION: "",
WORKBENCH_WEB_BASE_URL: "/assets",
};
if (url.pathname !== "/") {
return new Response(null, { status: 404 });
}
const workbench = await env.ASSETS.fetch(
`http://fake.host${configValues.WORKBENCH_WEB_BASE_URL}/workbench.html`
);
// Replace configuration values
const replacedWorkbenchText = (await workbench.text()).replaceAll(
/\{\{([^}]+)\}\}/g,
(_, key) => configValues[key as keyof typeof configValues] ?? "undefined"
);
return new Response(replacedWorkbenchText, {
headers: {
"Content-Type": "text/html",
},
});
},
};