3v324v23 commited on
Commit
990fe02
·
1 Parent(s): c6d33a6
Files changed (1) hide show
  1. whb.js +50 -0
whb.js ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const bodyParser = require('body-parser');
3
+ const fs = require('fs-extra')
4
+
5
+ const app = express();
6
+
7
+ app.use(express.json({ limit: '50mb' }));
8
+ app.use(express.urlencoded({ limit: '50mb', extended: true }));
9
+
10
+ // 处理 POST 请求
11
+ function getId(html) {
12
+ var x = 'class=link01><A href="search.exe?COMM_GRECNO=';
13
+ var y = html.split(x)[1];
14
+ return parseInt(y.substring(0, y.indexOf('&')));
15
+ }
16
+
17
+ function getNext() {
18
+ // return Math.floor(Math.random() * max) + 1;
19
+ for (let i = 1; ;++i) {
20
+ const dir = Math.floor(i/1000).toString();
21
+ if (!fs.existsSync('html/' + dir + '/' + i + '.html')) {
22
+ return i;
23
+ }
24
+ }
25
+ }
26
+
27
+ app.post('/upload', async (req, res) => {
28
+ const body = req.body;
29
+ const id = getId(body.document);
30
+ if (isNaN(id)) {
31
+ console.log('err', body.document);
32
+ process.exit();
33
+ return;
34
+ }
35
+ console.log(id)
36
+ const dir = Math.floor(id/1000).toString();
37
+ if (!await fs.exists('html/' + dir + '/' + id + '.html')) {
38
+ await fs.ensureDir('html/' + dir)
39
+ await fs.writeFile('html/' + dir + '/' + id + '.html', body.document)
40
+ res.send('goto:file:///C:/DTWXJS/WHB/html/cgi-bin/SEARCH.EXE?COMM_RECNO='+(id+1).toString()+'&COMM_RLTID=32');
41
+ } else {
42
+ console.log('exists', id);
43
+ const next = getNext();
44
+ res.send('goto:file:///C:/DTWXJS/WHB/html/cgi-bin/SEARCH.EXE?COMM_RECNO='+next+'&COMM_RLTID=32');
45
+ }
46
+ });
47
+
48
+ app.listen(3000, () => {
49
+ console.log('Server started on port 3000');
50
+ });