Download server/server.js from algorembrant/mt5-analyzer: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/algorembrant/mt5-analyzer/resolve/main/server/server.js
- Command line
-
hf download hf://algorembrant/mt5-analyzer/server/server.js
-
curl -L -o server.js https://huggingface.co/algorembrant/mt5-analyzer/resolve/main/server/server.js
1.78 kB
| const express = require('express'); | |
| const mongoose = require('mongoose'); | |
| const cors = require('cors'); | |
| const multer = require('multer'); | |
| const path = require('path'); | |
| const { parseMT5Report } = require('./utils/parser'); | |
| const Report = require('./models/Report'); | |
| const app = express(); | |
| app.use(cors()); | |
| app.use(express.json()); | |
| app.use('/uploads', express.static('uploads')); | |
| // MongoDB Connection | |
| mongoose.connect('mongodb://localhost:27017/mt5_analyzer'); | |
| // Multer Storage | |
| const storage = multer.diskStorage({ | |
| destination: (req, file, cb) => cb(null, 'uploads/'), | |
| filename: (req, file, cb) => cb(null, Date.now() + '-' + file.originalname), | |
| }); | |
| const upload = multer({ storage }); | |
| // API: Upload & Decode | |
| app.post('/api/upload', upload.fields([{ name: 'htmlFile' }, { name: 'images' }]), async (req, res) => { | |
| try { | |
| const htmlFile = req.files['htmlFile'][0]; | |
| const imageFiles = req.files['images'] || []; | |
| // Parse logic | |
| const parsedDeals = parseMT5Report(htmlFile.path); | |
| // Extract Account ID from filename (ReportTester-"_ID_".html) | |
| const filename = htmlFile.originalname; | |
| const accountId = filename.split('-')[1] || 'Unknown'; | |
| const newReport = new Report({ | |
| accountId, | |
| deals: parsedDeals, | |
| images: imageFiles.map(f => f.path) | |
| }); | |
| await newReport.save(); | |
| res.json({ success: true, report: newReport }); | |
| } catch (err) { | |
| console.error(err); | |
| res.status(500).json({ error: 'Failed to process report' }); | |
| } | |
| }); | |
| // API: Get All Reports | |
| app.get('/api/reports', async (req, res) => { | |
| const reports = await Report.find().sort({ uploadDate: -1 }); | |
| res.json(reports); | |
| }); | |
| app.listen(5000, () => console.log('Server running on port 5000')); |