|
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 })); |
|
|
|
|
|
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() { |
|
|
|
for (let i = 1; ;++i) { |
|
const dir = Math.floor(i/1000).toString(); |
|
if (!fs.existsSync('html/' + dir + '/' + i + '.html')) { |
|
return i; |
|
} |
|
} |
|
} |
|
|
|
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; |
|
} |
|
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'); |
|
}); |
|
|