Files
Elite-Gaming-FiveM/autofetch-script/fetch-script.js
T
Jacob 25ea292757 Bump artifacts & environment tweaks
- Adjusted database creds.
- Updated server artifacts to latest.
2025-08-24 20:31:27 +01:00

36 lines
1.1 KiB
JavaScript

require("dotenv").config();
const { exec } = require('child_process');
const crypto = require('crypto');
const express = require('express');
const cookieParser = require('cookie-parser');
const cors = require('cors');
// Express Setup & Config
const app = express();
app.use(cookieParser());
app.use(cors());
app.use(express.json({limit: '50mb'}));
app.listen(5069);
// POST listener from GitHub
console.log("Started fetch listener successfully...")
app.post('/fetch-gh', (req, res) => {
console.log("Received webhook POST request...")
var hmac, calculatedSignature, payload = req.body;
hmac = crypto.createHmac('sha1', process.env.GH_WEBHOOK_SECRET);
hmac.update(JSON.stringify(payload));
calculatedSignature = 'sha1=' + hmac.digest('hex');
// Ensure that the secret is valid
if (req.headers['x-hub-signature'] === calculatedSignature) {
console.log("Authenticated webhook, secret matches, fetching and pulling git...")
exec(`cd ${process.env.WORK_DIR} && git fetch && git pull`)
}
else {
console.log("Authentication failed... secret not matching")
}
res.sendStatus(201)
})