-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch8.mjs
More file actions
32 lines (25 loc) · 1.68 KB
/
patch8.mjs
File metadata and controls
32 lines (25 loc) · 1.68 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
import fs from 'fs';
let content = fs.readFileSync('Cloudflare_Workers/worker.mjs', 'utf8');
// I need to add back the logic for GitHub API errors and DOS Protection which must have been there before but was removed when I replaced lines!
// 1. In DOS limit: repos.length > 50
// 2. The `response.ok` check after fetch inside `handleGitHubGraphQL`
content = content.replace(
` const { username, repos } = body;
if (!username || !repos || !Array.isArray(repos)) return jsonResponse({ error: "Invalid Request Body" }, 400, corsHeaders);
if (!env?.GITHUB_USERNAME || username !== env.GITHUB_USERNAME) return jsonResponse({ error: "Forbidden" }, 403, corsHeaders);`,
` const { username, repos } = body;
if (!username || !repos || !Array.isArray(repos)) return jsonResponse({ error: "Invalid Request Body" }, 400, corsHeaders);
if (repos.length > 50) return jsonResponse({ error: "Too Many Repositories Requested" }, 400, corsHeaders);
if (!env?.GITHUB_USERNAME || username !== env.GITHUB_USERNAME) return jsonResponse({ error: "Forbidden" }, 403, corsHeaders);`
);
content = content.replace(
` const data = await response.json();
if (!data.data) return jsonResponse({ error: "GraphQL Errors", details: data.errors }, 500, corsHeaders);`,
` if (!response.ok) {
const errorText = await response.text();
return jsonResponse({ error: \`GitHub API Error: \${response.statusText}\`, details: errorText }, response.status, corsHeaders);
}
const data = await response.json();
if (!data.data) return jsonResponse({ error: "GraphQL Errors", details: data.errors }, 500, corsHeaders);`
);
fs.writeFileSync('Cloudflare_Workers/worker.mjs', content, 'utf8');