bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

commit d7077b0cc8d501488908ab4da523813df8bcc698
parent 2a3e59e3bba96307ddaaf990b753f3228d5ad84f
Author: Amit Dutta <amitdutta4255@gmail.com>
Date:   Wed,  3 Sep 2025 21:02:41 +0530

Update server.js
Diffstat:
Mserver.js | 42++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/server.js b/server.js @@ -1,14 +1,16 @@ const express = require('express'); const cors = require('cors'); +const fetch = require('node-fetch'); + const app = express(); const port = process.env.PORT || 3000; -// Access the GitHub Personal Access Token from Render's environment variables. -// The variable name is set in the Render dashboard. +// Use an environment variable for the GitHub token const GITHUB_TOKEN = process.env.GITHUB_TOKEN; const REPO_OWNER = 'notamitgamer'; const REPO_NAME = 'bsc'; const GITHUB_API_URL = `https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}`; +const GITHUB_RAW_URL = `https://raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}/main`; app.use(cors()); @@ -61,6 +63,42 @@ app.get('/api/programs', async (req, res) => { } }); +// New endpoint to fetch raw file content +app.get('/api/raw', async (req, res) => { + const { fileName, type } = req.query; + if (!fileName || !type) { + return res.status(400).json({ error: 'fileName and type are required query parameters.' }); + } + + try { + let fileUrl; + if (type === 'code') { + fileUrl = `${GITHUB_RAW_URL}/c/${fileName}`; + } else if (type === 'snapshot') { + fileUrl = `${GITHUB_RAW_URL}/c/snapshot/${fileName}`; + } else { + return res.status(400).json({ error: 'Invalid type parameter.' }); + } + + const response = await fetch(fileUrl); + if (!response.ok) { + throw new Error(`Failed to fetch raw file: ${response.statusText}`); + } + + if (type === 'code') { + const code = await response.text(); + res.set('Content-Type', 'text/plain'); + res.send(code); + } else if (type === 'snapshot') { + res.json(fileUrl); + } + + } catch (error) { + console.error('Error fetching raw content:', error); + res.status(500).json({ error: 'Failed to fetch raw content.' }); + } +}); + app.listen(port, () => { console.log(`Server listening at http://localhost:${port}`); });
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror