mirror of
https://github.com/PCSX2/web-api.git
synced 2026-01-31 01:15:16 +01:00
some small bug fixes, add compression middleware
This commit is contained in:
@@ -24,9 +24,10 @@ export class GithubController {
|
||||
// for the foreseeable future though, this is fine
|
||||
webhookHandler(req: Request, resp: Response) {
|
||||
const cid = uuidv4();
|
||||
this.log.info("Received request", req.headers);
|
||||
this.log.info("Received webhook request");
|
||||
const ghDigestRaw = req.header("x-hub-signature-256");
|
||||
if (ghDigestRaw == undefined) {
|
||||
this.log.warn("Webhook lacked digest signature, ignoring");
|
||||
resp.send(403);
|
||||
return;
|
||||
}
|
||||
@@ -41,34 +42,23 @@ export class GithubController {
|
||||
if (crypto.timingSafeEqual(digest, ghDigest)) {
|
||||
// Valid webhook from github, proceed
|
||||
const body = req.body;
|
||||
if (
|
||||
"action" in body &&
|
||||
body.action == "published" &&
|
||||
"release" in body &&
|
||||
body.release.draft == true
|
||||
) {
|
||||
if (body?.action === "published" && body?.release?.draft == false) {
|
||||
// Release event
|
||||
if (
|
||||
"repository" in body &&
|
||||
body.repository.full_name == "PCSX2/pcsx2"
|
||||
) {
|
||||
if (body?.repository?.full_name == "PCSX2/pcsx2") {
|
||||
this.log.info("Webhook was a release event from PCSX2!");
|
||||
this.releaseCache.refreshReleaseCache(cid);
|
||||
} else if (
|
||||
"repository" in body &&
|
||||
body.repository.full_name == "PCSX2/archive"
|
||||
) {
|
||||
} else if (body?.repository?.full_name == "PCSX2/archive") {
|
||||
this.releaseCache.refreshLegacyReleaseCache(cid);
|
||||
}
|
||||
} else if (
|
||||
"action" in body &&
|
||||
body.action == "completed" &&
|
||||
"check_suite" in body &&
|
||||
body.check_suite.status == "completed" &&
|
||||
body.check_suite.conclusion == "success"
|
||||
body?.action == "completed" &&
|
||||
body?.check_suite?.status == "completed" &&
|
||||
body?.check_suite?.conclusion == "success"
|
||||
) {
|
||||
this.releaseCache.refreshPullRequestBuildCache(cid);
|
||||
}
|
||||
} else {
|
||||
this.log.warn("Webhook digest signature was invalid, ignoring");
|
||||
resp.send(403);
|
||||
return;
|
||||
}
|
||||
|
||||
2
index.ts
2
index.ts
@@ -1,6 +1,7 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import compression from "compression";
|
||||
import { ReleaseCache } from "./models/ReleaseCache";
|
||||
import { exit } from "process";
|
||||
import { LogFactory } from "./utils/LogFactory";
|
||||
@@ -28,6 +29,7 @@ const rateLimit = require("express-rate-limit");
|
||||
const app = express();
|
||||
app.use(cors(corsOptions));
|
||||
app.use(express.json());
|
||||
app.use(compression());
|
||||
|
||||
// Enable if you're behind a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx, etc)
|
||||
// see https://expressjs.com/en/guide/behind-proxies.html
|
||||
|
||||
@@ -388,7 +388,7 @@ export class ReleaseCache {
|
||||
}
|
||||
|
||||
public async refreshPullRequestBuildCache(cid: string): Promise<void> {
|
||||
log.info("refreshing main release cache", {
|
||||
log.info("refreshing pull request cache", {
|
||||
cid: cid,
|
||||
cacheType: "pullRequests",
|
||||
});
|
||||
|
||||
98
package-lock.json
generated
98
package-lock.json
generated
@@ -14,6 +14,7 @@
|
||||
"@octokit/plugin-throttling": "^3.5.2",
|
||||
"@octokit/rest": "^18.12.0",
|
||||
"@octokit/types": "^6.31.3",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.17.1",
|
||||
@@ -24,6 +25,7 @@
|
||||
"winston-loki": "^6.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/compression": "^1.7.2",
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/node": "^16.11.7",
|
||||
@@ -426,6 +428,15 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/compression": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/compression/-/compression-1.7.2.tgz",
|
||||
"integrity": "sha512-lwEL4M/uAGWngWFLSG87ZDr2kLrbuR8p7X+QZB1OQlT+qkHsCPDVFnHPyXf4Vyl4yDDorNY+mAhosxkCvppatg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/express": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/connect": {
|
||||
"version": "3.4.35",
|
||||
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz",
|
||||
@@ -1219,6 +1230,42 @@
|
||||
"text-hex": "1.0.x"
|
||||
}
|
||||
},
|
||||
"node_modules/compressible": {
|
||||
"version": "2.0.18",
|
||||
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
|
||||
"integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
|
||||
"dependencies": {
|
||||
"mime-db": ">= 1.43.0 < 2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/compression": {
|
||||
"version": "1.7.4",
|
||||
"resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz",
|
||||
"integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==",
|
||||
"dependencies": {
|
||||
"accepts": "~1.3.5",
|
||||
"bytes": "3.0.0",
|
||||
"compressible": "~2.0.16",
|
||||
"debug": "2.6.9",
|
||||
"on-headers": "~1.0.2",
|
||||
"safe-buffer": "5.1.2",
|
||||
"vary": "~1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/compression/node_modules/bytes": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
|
||||
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@@ -2502,6 +2549,14 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/on-headers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
||||
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
@@ -3919,6 +3974,15 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/compression": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/compression/-/compression-1.7.2.tgz",
|
||||
"integrity": "sha512-lwEL4M/uAGWngWFLSG87ZDr2kLrbuR8p7X+QZB1OQlT+qkHsCPDVFnHPyXf4Vyl4yDDorNY+mAhosxkCvppatg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/express": "*"
|
||||
}
|
||||
},
|
||||
"@types/connect": {
|
||||
"version": "3.4.35",
|
||||
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz",
|
||||
@@ -4538,6 +4602,35 @@
|
||||
"text-hex": "1.0.x"
|
||||
}
|
||||
},
|
||||
"compressible": {
|
||||
"version": "2.0.18",
|
||||
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
|
||||
"integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
|
||||
"requires": {
|
||||
"mime-db": ">= 1.43.0 < 2"
|
||||
}
|
||||
},
|
||||
"compression": {
|
||||
"version": "1.7.4",
|
||||
"resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz",
|
||||
"integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==",
|
||||
"requires": {
|
||||
"accepts": "~1.3.5",
|
||||
"bytes": "3.0.0",
|
||||
"compressible": "~2.0.16",
|
||||
"debug": "2.6.9",
|
||||
"on-headers": "~1.0.2",
|
||||
"safe-buffer": "5.1.2",
|
||||
"vary": "~1.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"bytes": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
|
||||
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
|
||||
}
|
||||
}
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@@ -5550,6 +5643,11 @@
|
||||
"ee-first": "1.1.1"
|
||||
}
|
||||
},
|
||||
"on-headers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
||||
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA=="
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
"@octokit/plugin-throttling": "^3.5.2",
|
||||
"@octokit/rest": "^18.12.0",
|
||||
"@octokit/types": "^6.31.3",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.17.1",
|
||||
@@ -32,6 +33,7 @@
|
||||
"winston-loki": "^6.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/compression": "^1.7.2",
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/node": "^16.11.7",
|
||||
|
||||
Reference in New Issue
Block a user