From 32b4e639e460de7b08e40803e96953907fe8af70 Mon Sep 17 00:00:00 2001 From: Staninna <26458805+Staninna@users.noreply.github.com> Date: Wed, 27 Aug 2025 23:30:49 +0200 Subject: [PATCH] remove server.js artafact of me 'fooling' around earlier --- server.js | 182 ------------------------------------------------------ 1 file changed, 182 deletions(-) delete mode 100644 server.js diff --git a/server.js b/server.js deleted file mode 100644 index 5c330cb..0000000 --- a/server.js +++ /dev/null @@ -1,182 +0,0 @@ -const express = require('express'); -const { exec } = require('child_process'); -const fs = require('fs'); -const path = require('path'); - -const app = express(); -const port = 3000; - -// Cache for branch files -const branchCache = new Map(); - -// Get all branches and their files -function getBranchFiles(callback) { - exec('git branch -r | cut -c 3- | sed "s/origin\\///g"', (error, stdout, stderr) => { - if (error) { - console.error('Error getting branches:', error); - callback([]); - return; - } - - const branches = stdout.trim().split('\n').filter(branch => branch && branch !== 'HEAD'); - const branchData = []; - - let completed = 0; - branches.forEach(branch => { - exec(`git show ${branch.includes('origin/') ? branch : 'origin/' + branch}:Auto-Farm.js 2>/dev/null`, (err, farmJs) => { - exec(`git show ${branch.includes('origin/') ? branch : 'origin/' + branch}:Auto-Image.js 2>/dev/null`, (err2, imageJs) => { - exec(`git ls-tree -r --name-only ${branch.includes('origin/') ? branch : 'origin/' + branch} | grep -E "\\.(js|css|html|json)$" 2>/dev/null`, (err3, files) => { - const branchFiles = {}; - - if (!err && farmJs) branchFiles['Auto-Farm.js'] = farmJs; - if (!err2 && imageJs) branchFiles['Auto-Image.js'] = imageJs; - - // Get other files - if (!err3 && files) { - const fileList = files.trim().split('\n').filter(f => f); - let fileCount = fileList.length; - - if (fileCount === 0) { - branchData.push({ branch, files: branchFiles }); - completed++; - if (completed === branches.length) callback(branchData); - return; - } - - fileList.forEach(filename => { - if (!branchFiles[path.basename(filename)]) { - exec(`git show ${branch.includes('origin/') ? branch : 'origin/' + branch}:${filename} 2>/dev/null`, (err4, content) => { - if (!err4 && content) { - branchFiles[path.basename(filename)] = content; - } - fileCount--; - if (fileCount === 0) { - branchData.push({ branch, files: branchFiles }); - completed++; - if (completed === branches.length) callback(branchData); - } - }); - } else { - fileCount--; - if (fileCount === 0) { - branchData.push({ branch, files: branchFiles }); - completed++; - if (completed === branches.length) callback(branchData); - } - } - }); - } else { - branchData.push({ branch, files: branchFiles }); - completed++; - if (completed === branches.length) callback(branchData); - } - }); - }); - }); - }); - }); -} - -// Serve files per branch -app.get('/:branch/:filename', (req, res) => { - const { branch, filename } = req.params; - - getBranchFiles((branches) => { - const branchData = branches.find(b => b.branch === branch || b.branch === `origin/${branch}`); - - if (!branchData || !branchData.files[filename]) { - return res.status(404).send('File not found'); - } - - // Set appropriate content type - if (filename.endsWith('.js')) { - res.setHeader('Content-Type', 'application/javascript'); - } else if (filename.endsWith('.css')) { - res.setHeader('Content-Type', 'text/css'); - } else if (filename.endsWith('.html')) { - res.setHeader('Content-Type', 'text/html'); - } else if (filename.endsWith('.json')) { - res.setHeader('Content-Type', 'application/json'); - } - - // Enable CORS for browser scripts - res.setHeader('Access-Control-Allow-Origin', '*'); - - res.send(branchData.files[filename]); - }); -}); - -// Serve index page -app.get('/', (req, res) => { - getBranchFiles((branches) => { - let html = ` - - - - WPlace AutoBOT - Local Server - - - -
-

🚀 WPlace AutoBOT - Local Server

-

Server URL: ${req.protocol}://${req.get('host')}

-

Use ngrok to expose this server: ngrok http 3000

-`; - - branches.forEach(branchData => { - const branch = branchData.branch.replace('origin/', ''); - html += ` -
-

📁 Branch: ${branch}

-
-`; - Object.keys(branchData.files).forEach(filename => { - const url = `${req.protocol}://${req.get('host')}/${branch}/${filename}`; - html += `${filename}`; - - if (filename.endsWith('.js')) { - html += ` -
-
- Bookmarklet for ${filename}:
- javascript:fetch("${url}").then(t=>t.text()).then(eval); - -
-
`; - } - }); - html += `
`; - }); - - html += ` -
- - - -`; - - res.send(html); - }); -}); - -app.listen(port, () => { - console.log(`🚀 WPlace AutoBOT server running at http://localhost:${port}`); - console.log(`📡 Run 'ngrok http ${port}' to expose this server publicly`); - console.log(`🔗 Then use URLs like: https://abc123.ngrok.io/main/Auto-Farm.js`); -}); \ No newline at end of file