This repository was archived by the owner on Feb 6, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathservers.js
More file actions
290 lines (273 loc) · 7.9 KB
/
Copy pathservers.js
File metadata and controls
290 lines (273 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
var express = require("express");
var app = express();
var multer = require("multer");
var util = require("util");
var handFile = require("./handFile");
var path = require("path");
var sqlBusiness = require("./sqlBusiness");
var fs = require("fs");
var https = require("https");
var http = require("http");
// multer 初始化
let upload = multer({
dest: "tmp"
});
//time
Date.prototype.format = function(fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
S: this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
(this.getFullYear() + "").substr(4 - RegExp.$1.length)
);
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
);
}
}
return fmt;
};
//获取本机ip地址
function getIPAdress() {
let interfaces = require("os").networkInterfaces();
for (let devName in interfaces) {
let iface = interfaces[devName];
for (let i = 0; i < iface.length; i++) {
let alias = iface[i];
if (
alias.family === "IPv4" &&
alias.address !== "127.0.0.1" &&
!alias.internal
) {
return alias.address;
}
}
}
}
// express
app.use(express.static(__dirname + "/source/certificate"));
app.use("/store", express.static(__dirname + "/store"));
app.use("/node_modules", express.static(__dirname + "/node_modules"));
// app.use("/projectConfig", express.static(__dirname + "/source/projectJSON"));
app.use(express.static(__dirname + "/Fornt"));
let options = {
key: fs.readFileSync("./source/certificate/privateCA.pem", "utf8"),
cert: fs.readFileSync("./source/certificate/myCA.cer", "utf8")
};
var httpServer = http.createServer(app);
var httpsServer = https.createServer(options, app);
var host = getIPAdress(); // 自己的 ip
var httpsPort = 8886;
var httpPort = 8888;
var baseURL = "";
// https
httpsServer.listen(httpsPort, host, function() {
console.log("应用实例,访问地址为 https://%s:%s", host, httpsPort);
});
// http
httpServer.listen(httpPort, host, function() {
console.log("应用实例,访问地址为 http://%s:%s", host, httpPort);
baseURL = `https://${host}:${httpsPort}`;
});
app.get("/", function(req, res) {
res.sendFile(__dirname + "/" + "Fornt/projectManager/HTML/projectManager.html");
});
app.get("/upload.html", function(req, res) {
res.sendFile(__dirname + "/" + "upload.html");
});
app.get("/ipaList.html", function(req, res) {
res.sendFile(__dirname + "/" + "Fornt/download/HTML/ipaList.html");
});
app.get("/secretRoot.html", function(req, res) {
res.sendFile(__dirname + "/" + "secretRoot.html");
});
/**
* 读取列表
* pageNum:num
* pageSize:num
*/
app.get("/list", function(req, res) {
var resData = {
code: -1,
msg: "参数错误"
};
res.writeHead(200, {
"Content-Type": "text/html;charset=utf-8"
});
let pageNum = req.query.pageNum;
let pageSize = req.query.pageSize;
let project = req.query.project;
let os = req.query.os;
if (!(os && os.length > 0) ||
!(project && project.length > 0) ||
!(pageNum && pageNum > 0) ||
!(pageSize && pageSize > 0)
) {
res.end(JSON.stringify(resData));
return;
}
sqlBusiness.readListOfIpaInfo(project, os, pageNum, pageSize, function(
result
) {
if (!result) {
res.end(JSON.stringify(resData));
return;
}
// 动态处理下载列表中的域名地址-防止 ip 地址被更换
result.forEach(element => {
element.resourceURL = util.format(element.resourceURL, baseURL);
});
var resData = {
code: 0,
msg: "查询成功",
data: result
};
res.end(JSON.stringify(resData));
});
});
/**
* 上传
* */
app.post("/upload", upload.any(), function(req, res) {
var resData = {
code: -1,
msg: "上传失败"
};
res.writeHead(200, {
"Content-Type": "text/html;charset=utf-8"
});
if (req.files[0] == undefined) {
resData = {
code: -1,
msg: "上传的文件为空,请检查"
};
res.end(JSON.stringify(resData));
return;
}
let projectName = req.query.project;
let os = req.query.os;
let identifier = req.query.identifier;
let currentDate = new Date().format("yyyy-MM-dd-hh-mm-ss");
var destDir = path.join("store", currentDate); // 本地存储路径
let body = req.body;
let version = body.version;
let buildVersion = body.versionBuild;
let des = body.des || "啥也没写";
// 移动安装包
handFile.handleInstallationPackage(destDir, req.files[0], function(filePath) {
if (!filePath) {
resData = {
code: -1,
msg: "服务器,ipa 文件处理失败"
};
res.end(JSON.stringify(resData));
return;
}
// 数据库存储的 plist 地址
let fileURLPath = baseURL + "/" + filePath;
// infoPlist
if (os == "iOS") {
let plistPath = handFile.handlePlist(
destDir,
fileURLPath,
projectName,
version,
identifier
);
fileURLPath = "%s/" + plistPath;
console.log(fileURLPath)
console.log(plistPath)
}
sqlBusiness.saveIpaInfo(
identifier,
os,
projectName,
version,
buildVersion,
des,
fileURLPath,
currentDate,
function(isSuccess) {
if (isSuccess) {
console.log("上传成功");
resData = {
code: 0000,
msg: "上传成功"
};
res.end(JSON.stringify(resData));
} else {
resData = {
code: -1,
msg: "存储错误"
};
res.end(JSON.stringify(resData));
}
}
);
});
});
app.get("/uploadInfoPlist", function(req, res) {
var resData = {
code: -1,
msg: "参数错误"
};
res.writeHead(200, {
"Content-Type": "text/html;charset=utf-8"
});
let newHost = req.query.newHost;
if (newHost === undefined) {
res.end(JSON.stringify(resData));
return;
}
handFile.updatedInfoPlistUrl(newHost);
resData = {
code: 0000,
msg: "处理成功"
};
res.end(JSON.stringify(resData));
});
app.get("/projectConfig", function(req, res) {
var resData = {
code: -1,
msg: "参数错误"
};
// 同步读取
let data = JSON.parse(fs.readFileSync(__dirname + "/source/projectJSON/projectConfig.json"));
if (data === undefined) {
res.end(JSON.stringify(data));
return;
}
res.writeHead(200, {
"Content-Type": "text/html;charset=utf-8"
});
resData = {
code: 0000,
msg: "处理成功",
data: data
};
res.end(JSON.stringify(resData));
});
/*
{
fieldname: 'image',
originalname: 'MAMTest.ipa',
encoding: '7bit',
mimetype: 'application/octet-stream',
destination: 'dest',
filename: '82bfecb7b3140bf51397890ca04326bb',
path: 'dest/82bfecb7b3140bf51397890ca04326bb',
size: 13355288
}
*/