const express = require('express'); const path = require('path'); const fs = require('fs'); const QRCode = require('qrcode'); const app = express(); const PORT = process.env.PORT || 4012; // Function to read current version from main.h function getCurrentVersion() { try { const mainHPath = path.join(__dirname, '../include/main.h'); const content = fs.readFileSync(mainHPath, 'utf8'); const versionMatch = content.match(/#define\s+MICE_VERSION\s+"([^"]+)"/); return versionMatch ? versionMatch[1] : 'unknown'; } catch (error) { console.log('Could not read version:', error.message); return 'unknown'; } } // Function to get build timestamp function getBuildTimestamp() { try { const outputDir = path.join(__dirname, '../output'); if (fs.existsSync(outputDir)) { const stats = fs.statSync(outputDir); return stats.mtime.toLocaleString(); } } catch (error) { console.log('Could not read build timestamp:', error.message); } return 'unknown'; } // Serve static files from the output directory app.use('/downloads', express.static(path.join(__dirname, '../output'))); // Basic styling for the web interface with dark mode support const CSS = ` `; // Main page app.get('/', async (req, res) => { const outputDir = path.join(__dirname, '../output'); // Use the client's actual request URL const protocol = req.get('x-forwarded-proto') || req.protocol || 'http'; const host = req.get('x-forwarded-host') || req.get('host'); const baseUrl = `${protocol}://${host}`; // Check if build files exist const files = []; const fileExtensions = ['.3dsx', '.cia', '.3ds', '.elf']; try { const items = fs.readdirSync(outputDir, { recursive: true }); for (const item of items) { const itemPath = path.join(outputDir, item); const stats = fs.statSync(itemPath); if (stats.isFile()) { const ext = path.extname(item).toLowerCase(); if (fileExtensions.includes(ext)) { const filePath = `/downloads/${item}`; const fileUrl = `${baseUrl}${filePath}`; files.push({ name: item, path: filePath, url: fileUrl, size: (stats.size / 1024).toFixed(1), // KB type: ext.substring(1).toUpperCase() }); } } } } catch (err) { console.error('Error reading output directory:', err); } let html = `
For .3dsx files (Homebrew Launcher):
/3ds/ folder on your SD cardFor .cia files (installed to HOME menu):
Please run make in the mice directory to build the project first.
š± Scan QR Code for 3DS Browser:
Server running at: ${baseUrl}
${baseUrl.includes('github.dev') ? 'ā GitHub Codespaces detected - URL is ready for 3DS browser!
' : 'š” For 3DS access, use your local network IP address
' }