First Commit
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7941;
|
||||
exports.ids = [7941];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5603:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": () => (/* binding */ handler)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1017);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
|
||||
const http = __webpack_require__(3685);
|
||||
const fs = __webpack_require__(7147);
|
||||
const { createHmac } = __webpack_require__(6113);
|
||||
const key = process.env.DSQL_GITHUB_WEBHOOK_SECRET || "";
|
||||
/**
|
||||
* @param {import("next").NextApiRequest} req
|
||||
* @returns {boolean}
|
||||
*/ const verify_signature = (req)=>{
|
||||
console.log(req.headers);
|
||||
const signature = createHmac("sha256", key).update(JSON.stringify(req.body)).digest("hex");
|
||||
console.log(signature);
|
||||
return `sha256=${signature}` === req.headers["x-hub-signature-256"];
|
||||
};
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @type {import("next").NextApiHandler} */ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
if (!verify_signature(req)) {
|
||||
console.log("Authorization failed");
|
||||
res.status(401).send("Unauthorized");
|
||||
return;
|
||||
}
|
||||
/** ********************* Initialize data */ const data = req.body;
|
||||
try {
|
||||
/** ********************************************** */ /** ********************************************** */ /** ********************************************** */ console.log("Request Recieved");
|
||||
const ref = data.ref;
|
||||
if (!ref?.match(/main/)) {
|
||||
console.log("Not Main Branch");
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
fs.writeFileSync(path__WEBPACK_IMPORTED_MODULE_0___default().resolve(process.cwd(), "./.dist", "REDEPLOY_FLAG"), String(Date.now()), "utf-8");
|
||||
console.log("Deploy Flag Triggered. Now Redeploying ...");
|
||||
/** ********************************************** */ /** ********************************************** */ /** ********************************************** */ res.json({
|
||||
success: true
|
||||
});
|
||||
/** ********************************************** */ /** ********************************************** */ /** ********************************************** */ } catch (error) {
|
||||
console.log(error);
|
||||
res.json({
|
||||
msg: "Not Handled Yet"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// load runtime
|
||||
var __webpack_require__ = require("../../../webpack-api-runtime.js");
|
||||
__webpack_require__.C(exports);
|
||||
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
|
||||
var __webpack_exports__ = (__webpack_exec__(5603));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../../package.json","../../../../../package.json","../../../../../.dist/REDEPLOY_FLAG"]}
|
||||
Reference in New Issue
Block a user