wenhuibao_disk / whb.js
3v324v23's picture
1
4794678
raw
history blame contribute delete
No virus
1.54 kB
const express = require('express');
const bodyParser = require('body-parser');
const fs = require('fs-extra')
const app = express();
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));
// 处理 POST 请求
function getId(html) {
var x = 'class=link01><A href="search.exe?COMM_GRECNO=';
var y = html.split(x)[1];
return parseInt(y.substring(0, y.indexOf('&')));
}
function getNext() {
// return Math.floor(Math.random() * max) + 1;
for (let i = 1; ;++i) {
const dir = Math.floor(i/1000).toString();
if (!fs.existsSync('html/' + dir + '/' + i + '.html')) {
return i;
}
}
}
const max = 1231692;
app.post('/upload', async (req, res) => {
const body = req.body;
const id = getId(body.document);
if (isNaN(id)) {
console.log('err', body.document);
process.exit();
return;
}
if (id > max) {
process.exit();
return;
}
console.log(id)
const dir = Math.floor(id/1000).toString();
if (!await fs.exists('html/' + dir + '/' + id + '.html')) {
await fs.ensureDir('html/' + dir)
await fs.writeFile('html/' + dir + '/' + id + '.html', body.document)
res.send('goto:file:///C:/DTWXJS/WHB/html/cgi-bin/SEARCH.EXE?COMM_RECNO='+(id+1).toString()+'&COMM_RLTID=32');
} else {
console.log('exists', id);
const next = getNext();
res.send('goto:file:///C:/DTWXJS/WHB/html/cgi-bin/SEARCH.EXE?COMM_RECNO='+next+'&COMM_RLTID=32');
}
});
app.listen(3000, () => {
console.log('Server started on port 3000');
});