From 2d6d88c43ca909ac74aae30aac8e223f71deaa4d Mon Sep 17 00:00:00 2001
From: snailuncle <1789500304@qq.com>
Date: Fri, 14 Dec 2018 13:02:53 +0800
Subject: [PATCH] =?UTF-8?q?daily-12-14-=E6=88=90=E5=8A=9F=E5=9C=A8?=
=?UTF-8?q?=E6=89=8B=E6=9C=BA=E4=B8=8A=E5=90=AF=E5=8A=A8helloworld?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app.js | 157 ++++++++----
autojsTest/1111111.js | 8 +
autojsTest/aaa.js | 10 +
autojsTest/bbb.js | 7 +
autojsTest/ccc.js | 9 +
autojsTest/downloadFile.js | 18 ++
...53\347\232\204\350\204\232\346\234\254.js" | 20 ++
...43\345\216\213\346\226\207\344\273\266.js" | 6 +
clientInfo.json | 1 +
config.js | 2 +-
downloadFileTest.html | 33 +++
downloadFileTest.js | 29 +++
...0\347\224\250\345\221\275\344\273\244.txt" | 10 +-
index.html | 11 +
.../client.js" | 122 +++++++++-
.../main.js" | 2 +-
.../match\346\217\220\345\217\226fileName.js" | 13 +
"npm\346\267\230\345\256\235.txt" | 2 +-
package-lock.json | 58 +++++
package.json | 1 +
.../index.js" | 2 +
public/index.html | 11 +
socketServer.js | 227 ++++++++++++++++++
...5\350\257\273\350\204\232\346\234\254.zip" | Bin 0 -> 1347 bytes
24 files changed, 697 insertions(+), 62 deletions(-)
create mode 100644 autojsTest/1111111.js
create mode 100644 autojsTest/aaa.js
create mode 100644 autojsTest/bbb.js
create mode 100644 autojsTest/ccc.js
create mode 100644 autojsTest/downloadFile.js
create mode 100644 "autojsTest/\345\201\234\346\255\242\351\231\244\344\272\206\350\207\252\350\272\253\347\232\204\350\204\232\346\234\254.js"
create mode 100644 "autojsTest/\350\247\243\345\216\213\346\226\207\344\273\266.js"
create mode 100644 clientInfo.json
create mode 100644 downloadFileTest.html
create mode 100644 downloadFileTest.js
create mode 100644 index.html
create mode 100644 "nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/match\346\217\220\345\217\226fileName.js"
create mode 100644 "projectList/\346\237\220\345\271\263\345\217\260\351\230\205\350\257\273\350\204\232\346\234\254/index.js"
create mode 100644 public/index.html
create mode 100644 socketServer.js
create mode 100644 "zipFolder/\346\237\220\345\271\263\345\217\260\351\230\205\350\257\273\350\204\232\346\234\254.zip"
diff --git a/app.js b/app.js
index f3ddd18..fab8671 100644
--- a/app.js
+++ b/app.js
@@ -1,9 +1,12 @@
const port = require("./config.json")
+const config = require("./config.js")
const Koa = require('koa');
const render = require('./src/index');
const path = require('path');
const bodyParser = require('koa-bodyparser')
const controller = require('./controller');
+const send = require('koa-send'); // "koa-send": "^4.1.0"
+
//引入子模块子路由
const router = require('koa-router')();
//websocket要导入的包
@@ -58,42 +61,7 @@ router.use('/user', user)
// 'GET /runIndex': fn_runIndex
-var net = require("net");
-var config = require('./config')
-/**
- * 创建server
- */
-var server = net.createServer(function (socket) {
- var t = config.getTime()
- socket.write(t + "hello,i'm nodejs!"+"\r\n");
- console.log(t + "client connected! %j:%j", socket.remoteAddress, socket.remotePort);
- socket.on("data", function (data) {
- var t = config.getTime()
- console.log(t + "recived from autojs:", data.toString());
- socket.write(t + "这是来自nodejs的数据->海贼王啥时候完结??"+"\r\n");
- })
- socket.on("close", function (had_error) {
- if (!had_error) {
- console.log("client closed success! %j:%j", socket.remoteAddress, socket.remotePort);
- } else {
- console.log("client close error! %j:%j", socket.remoteAddress, socket.remotePort);
- }
- })
- socket.on("error", function (err) {
- console.log("!!!err!!!", err);
- });
- //setTimeout(function(){
- // socket.end("我结束了","utf8");
- //},3000);
-});
-server.listen({
- port: config.port
-}, function () {
- var t = config.getTime()
- var address = server.address();
- console.log(t + " opened server on address %j ", address);
-});
@@ -107,9 +75,50 @@ router.get('/runIndex/:projectName',async (ctx,next) => {
var folder='./projectList/'+projectName
var zipFilePath=zipFolder(folder)
//告诉手机下载指定项目的压缩包
- tellMobileDownloadProjectZipFile(zipFilePath)
- //下载完毕手机自动运行该项目中的index.js
+ var 版本号=1
+ // 版本号读取所选项目的index.js文件,
+ // 查看scriptVersionNumber字段
+ var fs = require('fs');
+ var indexFilePath=folder+'/index.js'
+ if (!fs.existsSync(indexFilePath)) {
+ // Do something
+ console.log('请在项目中建立index.js文件');
+ console.log('文件中必须有一行内容来指定项目版本号,如下');
+ console.log('scriptVersionNumber=1');
+
+ process.exit(1)
+ }
+
+
+
+ console.log('--------读取index.js文件开始--------');
+
+ var fileContent = fs.readFileSync(indexFilePath, 'utf-8');
+
+ console.log('--------读取index.js文件结束--------');
+ //检查版本号
+ var reg=/scriptVersionNumber=(\d+)/
+ var 版本号=fileContent.match(reg)[1]
+
+
+
+
+
+
+
+
+
+ var 服务器下载端口=port.httpPort
+ project={
+ "projectName":projectName,
+ "scriptVersionNumber":版本号,
+ 'port':服务器下载端口
+ }
+ tellMobileDownloadProjectZipFile(project)
+ //下载完毕手机自动运行该项目中的index.js
+ //默认版本号为1 如果在index中发现版本号,以index中的版本号为准
+ //如果手机上的版本号小于当前版本号,那么就更新脚本.
@@ -123,12 +132,14 @@ function zipFolder(folder){
}
-function tellMobileDownloadProjectZipFile(zipFilePath){
+function tellMobileDownloadProjectZipFile(projectName){
var t = config.getTime()
+ console.log(t)
+ // console.log('6秒后通知手机更新脚本');
+
+ // setTimeout(childSendMsg,6000)
+ childSendMsg(projectName)
- socket.write(t + "hello,i'm nodejs!"+"\r\n");
- socket.write(t + "please download zipFile!"+"\r\n");
- socket.write(t + "zipFilePathIs"+zipFilePath+"\r\n");
}
@@ -153,6 +164,21 @@ function tellMobileDownloadProjectZipFile(zipFilePath){
// })
+//下载文件
+router.get('/download/:fileName', async function (ctx) {
+ // 为了方便演示,这里直接下载index页面
+
+
+ var fileName = ctx.params.fileName+'.zip';
+ console.log('要下载的文件的名字='+fileName)
+ // Set Content-Disposition to "attachment" to signal the client to prompt for download.
+ // Optionally specify the filename of the download.
+ // 设置实体头(表示消息体的附加信息的头字段),提示浏览器以文件下载的方式打开
+ // 也可以直接设置 ctx.set("Content-disposition", "attachment; filename=" + fileName);
+ ctx.attachment(fileName);
+ await send(ctx, fileName, { root: __dirname + '/zipFolder' });
+});
+
app.use(router.routes()).use(router.allowedMethods())
// app.use(async function (ctx) {
@@ -164,7 +190,54 @@ app.use(router.routes()).use(router.allowedMethods())
console.log('port=')
console.log(port)
app.listen(port.httpPort);
-console.log('open http://localhost:' + port.httpPort);
+console.log('open http://localhost:' + port.httpPort);
app.on('error', function (err) {
console.log(err.stack);
});
+
+
+
+//以下是socket部分,fork一个子进程,以便与手机通信===================================================================================
+
+
+const child = require('child_process').fork('./socketServer.js');
+
+
+child.on('message', (msg) => {
+ console.log('大头儿子说->'+msg)
+});
+
+function childSendMsg(projectName){
+ console.log('启动childSendMsg函数');
+ console.log('现在通知手机更新脚本')
+ child.send('小头爸爸说->大头儿子,让他们更新脚本吧');
+
+ // setTimeout(发送项目更新信息,6000)
+
+ 发送项目更新信息(projectName)
+}
+function 发送项目更新信息(project){
+ console.log("发送项目更新信息");
+
+ // var projectName=project.projectName
+ // var scriptVersionNumber=project.scriptVersionNumber
+ // var 项目更新信息={
+ // "projectName":projectName,
+ // "scriptVersionNumber":scriptVersionNumber
+ // }
+ 项目更新信息=JSON.stringify(project)
+ child.send('项目更新信息'+项目更新信息)
+}
+
+
+
+
+
+
+// function clock(){
+// var t = new Date();
+// console.log(t);
+
+// }
+// setInterval(clock, 5000);
+
diff --git a/autojsTest/1111111.js b/autojsTest/1111111.js
new file mode 100644
index 0000000..87d650a
--- /dev/null
+++ b/autojsTest/1111111.js
@@ -0,0 +1,8 @@
+enginesAll = engines.all()
+log(enginesAll)
+enginesAll.map((ScriptEngine) => {
+ if (engines.myEngine() == ScriptEngine) {} else {
+ console.log('即将停止的脚本引擎' + ScriptEngine)
+ ScriptEngine.forceStop()
+ }
+})
diff --git a/autojsTest/aaa.js b/autojsTest/aaa.js
new file mode 100644
index 0000000..9418277
--- /dev/null
+++ b/autojsTest/aaa.js
@@ -0,0 +1,10 @@
+
+fn=()=>{
+ // var s=ScriptEngine.cwd()
+ var s=engines.myEngine().getSource()
+ console.log(s)
+}
+
+setInterval(fn,2000)
+
+
diff --git a/autojsTest/bbb.js b/autojsTest/bbb.js
new file mode 100644
index 0000000..0595781
--- /dev/null
+++ b/autojsTest/bbb.js
@@ -0,0 +1,7 @@
+fn=()=>{
+ // var s=ScriptEngine.cwd()
+ var s=engines.myEngine().getSource()
+ console.log(s)
+}
+
+setInterval(fn,2000)
diff --git a/autojsTest/ccc.js b/autojsTest/ccc.js
new file mode 100644
index 0000000..3bf84b8
--- /dev/null
+++ b/autojsTest/ccc.js
@@ -0,0 +1,9 @@
+fn=()=>{
+ // var s=ScriptEngine.cwd()
+ var s=engines.myEngine().getSource()
+ console.log(s)
+ console.log('ccc的fn')
+}
+
+setInterval(fn,2000)
+console.log('ccc存在过')
diff --git a/autojsTest/downloadFile.js b/autojsTest/downloadFile.js
new file mode 100644
index 0000000..7e77b22
--- /dev/null
+++ b/autojsTest/downloadFile.js
@@ -0,0 +1,18 @@
+Response.body
+{Object}
+当前响应的内容。他有以下属性和函数:
+
+bytes() {Array} 以字节数组形式返回响应内容
+
+
+console.show();
+http.get("www.baidu.com", {}, function(res, err){
+ if(err){
+ console.error(err);
+ return;
+ }
+ log("code = " + res.statusCode);
+ var bodyBytes=res.body.bytes()
+ var path='./'
+ files.writeBytes(path, bytes)
+});
diff --git "a/autojsTest/\345\201\234\346\255\242\351\231\244\344\272\206\350\207\252\350\272\253\347\232\204\350\204\232\346\234\254.js" "b/autojsTest/\345\201\234\346\255\242\351\231\244\344\272\206\350\207\252\350\272\253\347\232\204\350\204\232\346\234\254.js"
new file mode 100644
index 0000000..c5c1c8a
--- /dev/null
+++ "b/autojsTest/\345\201\234\346\255\242\351\231\244\344\272\206\350\207\252\350\272\253\347\232\204\350\204\232\346\234\254.js"
@@ -0,0 +1,20 @@
+脚本数组 = ['aaa', 'bbb', 'ccc']
+脚本数组.map((file) => {
+ engines.execScriptFile(files.cwd() + "/" + file + ".js")
+})
+end = () => {
+ enginesAll = engines.all()
+ log(enginesAll)
+ enginesAll.map((ScriptEngine) => {
+ if (engines.myEngine().toString() != ScriptEngine.toString()) {
+ console.log('即将停止的脚本引擎' + ScriptEngine)
+ ScriptEngine.forceStop()
+ }
+ })
+ for (let i = 0; i < 10; i++) {
+ sleep(1000)
+ console.log(213);
+
+ }
+}
+setTimeout(end, 5000)
diff --git "a/autojsTest/\350\247\243\345\216\213\346\226\207\344\273\266.js" "b/autojsTest/\350\247\243\345\216\213\346\226\207\344\273\266.js"
new file mode 100644
index 0000000..d2efa40
--- /dev/null
+++ "b/autojsTest/\350\247\243\345\216\213\346\226\207\344\273\266.js"
@@ -0,0 +1,6 @@
+
+function 解压文件(fileName){
+ var fileName=files.path('./'+fileName)
+ var unzipFileName=fileName.replace('.zip','')
+ com.stardust.io.Zip.unzip(new java.io.File(fileName), new java.io.File(unzipFileName))
+}
diff --git a/clientInfo.json b/clientInfo.json
new file mode 100644
index 0000000..5552ebb
--- /dev/null
+++ b/clientInfo.json
@@ -0,0 +1 @@
+{"xiaomi/ugglite/ugglite:7.1.2/N2G47H/8.3.1:user/release-keys":{"屏幕宽度":720,"屏幕高度":1280,"buildId":"N2G47H","主板":"QC_Reference_Phone","制造商":"xiaomi","型号":"Redmi Note 5A","产品名称":"ugglite","硬件名称":"qcom","唯一标识码":"xiaomi/ugglite/ugglite:7.1.2/N2G47H/8.3.1:user/release-keys","AndroidId":"eff4c619a4f92b20","API":25,"ip":"::ffff:192.168.12.100","port":51615,"客户端登记时间":"2018-12-14 12:50:40"}}
\ No newline at end of file
diff --git a/config.js b/config.js
index cda20ca..88164ea 100644
--- a/config.js
+++ b/config.js
@@ -24,7 +24,7 @@ function getTime() {
// 2018-08-02 21:22:07
}
module.exports = {
- "serverIP": "192.168.12.104",
+ "serverIP": "192.168.12.101",
"port": "8811",
"getTime": getTime
}
diff --git a/downloadFileTest.html b/downloadFileTest.html
new file mode 100644
index 0000000..08619ed
--- /dev/null
+++ b/downloadFileTest.html
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+ __小简__下载测试
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/downloadFileTest.js b/downloadFileTest.js
new file mode 100644
index 0000000..f59aa47
--- /dev/null
+++ b/downloadFileTest.js
@@ -0,0 +1,29 @@
+const koa = require('koa'); // "koa": "^2.2.0"
+const app = new koa();
+const router = require('koa-router')(); // "koa-router": "^7.2.0"
+const send = require('koa-send'); // "koa-send": "^4.1.0"
+
+router.get('/', async function (ctx) {
+ var fileName = 'index.html';
+ await send(ctx, fileName, { root: __dirname + '/public' });
+});
+
+router.get('/download', async function (ctx) {
+ // 为了方便演示,这里直接下载index页面
+ var fileName = 'index.html';
+ // Set Content-Disposition to "attachment" to signal the client to prompt for download.
+ // Optionally specify the filename of the download.
+ // 设置实体头(表示消息体的附加信息的头字段),提示浏览器以文件下载的方式打开
+ // 也可以直接设置 ctx.set("Content-disposition", "attachment; filename=" + fileName);
+ ctx.attachment(fileName);
+ await send(ctx, fileName, { root: __dirname + '/public' });
+});
+
+app
+ .use(router.routes())
+ .use(router.allowedMethods());
+
+ port=3000
+app.listen(port);
+
+console.log('open http://localhost:' + port);
diff --git "a/git\345\270\270\347\224\250\345\221\275\344\273\244.txt" "b/git\345\270\270\347\224\250\345\221\275\344\273\244.txt"
index 6b58430..0a5ac99 100644
--- "a/git\345\270\270\347\224\250\345\221\275\344\273\244.txt"
+++ "b/git\345\270\270\347\224\250\345\221\275\344\273\244.txt"
@@ -10,26 +10,26 @@ git status -s
git branch
创建分支
-git checkout master -b daily-12-14-服务器和手机正常收发脚本更新信息
+git checkout master -b daily-12-14-成功在手机上启动helloworld
提交到暂存区
git add .
提交评论
-git commit -m 'daily-12-14-服务器和手机正常收发脚本更新信息'
+git commit -m 'daily-12-14-成功在手机上启动helloworld'
推送到分支
-git push origin daily-12-14-服务器和手机正常收发脚本更新信息
+git push origin daily-12-14-成功在手机上启动helloworld
切换主干||分支
git checkout master || git checkout daily-10-1
本地合并分支到主干
-git merge daily-12-14-服务器和手机正常收发脚本更新信息
+git merge daily-12-14-成功在手机上启动helloworld
远端合并分支到主干
-git merge origin/daily-12-14-服务器和手机正常收发脚本更新信息
+git merge origin/daily-12-14-成功在手机上启动helloworld
推送主干
git push origin master
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..a5a7e2b
--- /dev/null
+++ b/index.html
@@ -0,0 +1,11 @@
+
+
+
+
+
+ Document
+
+
+ this is index.html
+
+
diff --git "a/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/client.js" "b/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/client.js"
index b540faf..32ea922 100644
--- "a/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/client.js"
+++ "b/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/client.js"
@@ -1,3 +1,9 @@
+
+
+// log(files.getSdcardPath())
+// exit()
+
+
var config = require('./config')
importClass("java.io.DataInputStream");
importClass("java.io.DataOutputStream");
@@ -50,24 +56,28 @@ function 与服务器socket通信() {
bw.flush()
}
if (a.indexOf("runScript") != -1) {
- log('服务器发给客户端执行脚本的命令->'+a)
- var data=a.toString()
- data=data.replace('runScript','')
- log('正式脚本='+data)
+ log('服务器发给客户端执行脚本的命令->' + a)
+ var data = a.toString()
+ data = data.replace('runScript', '')
+ log('正式脚本=' + data)
eval(data)
bw.write('iHadRunScript' + "\r\n"); //加上分行符,以便服务器按行读取
bw.flush()
}
if (a.indexOf("项目更新信息") != -1) {
- log('服务器发给客户端脚本更新信息=->'+a)
- var data=a.toString()
- data=data.replace('项目更新信息','')
- data=data.replace(/(^\s*)|(\s*$)/g, "");
-
- log('脚本更新信息='+data)
-
- bw.write('手机'+device.model+'收到更新脚本的信息'+data + "\r\n"); //加上分行符,以便服务器按行读取
+ log('服务器发给客户端脚本更新信息=->' + a)
+ var data = a.toString()
+ data = data.replace('项目更新信息', '')
+ data = data.replace(/(^\s*)|(\s*$)/g, "");
+ log('脚本更新信息=' + data)
+ // 2018-12-14 09:10:22recived from autojs:
+ // 手机Redmi Note 5A 收到更新脚本的信息
+ // {"projectName":"某平台阅读脚本","scriptVersionNumber":"10"}
+ bw.write('手机' + device.model + '收到更新脚本的信息' + data + "\r\n"); //加上分行符,以便服务器按行读取
bw.flush()
+ //下载文件
+ var project = (JSON.parse(data))
+ downloadFile(project)
}
}
sleep(6000)
@@ -79,3 +89,91 @@ function 与服务器socket通信() {
events.emit('socketERROR');
}
}
+
+function downloadFile(project) {
+ console.log('进入downloadFile内部');
+ var ip = config.serverIP;
+ var port = project.port;
+ // router.get('/download/:fileName', async function (ctx) {
+ http: //localhost:3000/
+ var url = ip + ":" + port + "/download/" + project.projectName
+ console.log('手机请求的url=' + url);
+ http.get(url, {}, function (res, err) {
+ if (err) {
+ console.error(err);
+ return;
+ }
+ log("code = " + res.statusCode);
+ console.log("HTTP Headers:")
+ for (var headerName in res.headers) {
+ console.log("%s: %s", headerName, res.headers[headerName]);
+ }
+ var bodyBytes = res.body.bytes()
+ console.log('bodyBytes.length=')
+ console.log(bodyBytes.length)
+ var fileName = res.headers['Content-Disposition']
+ console.log('Content-Disposition=')
+ console.log(fileName);
+ // Content-Disposition: attachment; filename="???????.zip"; filename*=UTF-8''%E6%9F%90%E5%B9%B3%E5%8F%B0%E9%98%85%E8%AF%BB%E8%84%9A%E6%9C%AC.zip
+ var fileNameReg = /filename\*=UTF-8''(.+?\.zip)/
+ fileName = fileName.match(fileNameReg)[1]
+ fileName = decodeURI(fileName)
+ console.log('正则匹配fileName结果=');
+ console.log(fileName);
+ var path = './' + fileName
+ console.log('开始写入文件')
+ console.log(path)
+ console.log(bodyBytes.length)
+ files.writeBytes(path, bodyBytes)
+ console.log('下载并写入文件完毕,文件名字=');
+ console.log(fileName);
+ // 解压项目文件到/脚本文件夹中,并启动项目文件中的index.js
+ 解压文件(fileName)
+ 启动项目文件中的index文件(project.projectName)
+
+ });
+ console.log('函数运行完成downloadFile');
+}
+
+
+function 启动项目文件中的index文件(projectName){
+
+// log(files.getSdcardPath())
+// exit()
+ var indexPath=files.getSdcardPath()+"/脚本/"+projectName+"/index.js"
+ console.log('indexPath='+indexPath)
+ 停止除了自身的所有脚本()
+
+ engines.execScriptFile(indexPath);
+
+
+
+
+}
+
+
+function 解压文件(fileName){
+ console.log('开始解压文件')
+ var fileName=files.path('./'+fileName)
+ var unzipFileName=fileName.replace('.zip','')
+ com.stardust.io.Zip.unzip(new java.io.File(fileName), new java.io.File(unzipFileName))
+ console.log('结束解压文件')
+}
+
+
+function 停止除了自身的所有脚本(){
+
+ // 脚本数组 = ['aaa', 'bbb', 'ccc']
+ // 脚本数组.map((file) => {
+ // engines.execScriptFile(files.cwd() + "/" + file + ".js")
+ // })
+ var enginesAll = engines.all()
+ log(enginesAll)
+ enginesAll.map((ScriptEngine) => {
+ if (engines.myEngine().toString() == ScriptEngine.toString()) {} else {
+ console.log('即将停止的脚本引擎' + ScriptEngine)
+ ScriptEngine.forceStop()
+ }
+ })
+
+}
diff --git "a/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/main.js" "b/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/main.js"
index fe27f31..6e76891 100644
--- "a/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/main.js"
+++ "b/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/main.js"
@@ -15,7 +15,7 @@ function childSendMsg(){
}
function 发送项目更新信息(){
console.log("发送项目更新信息");
-
+
var projectName='项目名称'
var scriptVersionNumber='项目脚本版本号'
var 项目更新信息={
diff --git "a/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/match\346\217\220\345\217\226fileName.js" "b/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/match\346\217\220\345\217\226fileName.js"
new file mode 100644
index 0000000..6c7c5b9
--- /dev/null
+++ "b/nodejs\344\270\216autojs\347\232\204socket\351\200\232\344\277\241/match\346\217\220\345\217\226fileName.js"
@@ -0,0 +1,13 @@
+fileContent="attachment; filename=\"???????.zip\"; filename*=UTF-8''%E6%9F%90%E5%B9%B3%E5%8F%B0%E9%98%85%E8%AF%BB%E8%84%9A%E6%9C%AC.zip"
+
+log(fileContent)
+
+
+// var fileNameReg=/filename\*=UTF-8/
+var fileNameReg=/filename\*=UTF-8''(.+?\.zip)/
+fileName=fileContent.match(fileNameReg)[1]
+fileName=decodeURI(fileName)
+
+console.log('正则匹配fileName结果=');
+
+console.log(fileName);
diff --git "a/npm\346\267\230\345\256\235.txt" "b/npm\346\267\230\345\256\235.txt"
index 87bd3ef..9f10846 100644
--- "a/npm\346\267\230\345\256\235.txt"
+++ "b/npm\346\267\230\345\256\235.txt"
@@ -5,7 +5,7 @@ npm install koa-route --registry=https://registry.npm.taobao.org
npm install art-template --save --registry=https://registry.npm.taobao.org
-npm install socket.io --save --registry=https://registry.npm.taobao.org
+npm install koa-send --save --registry=https://registry.npm.taobao.org
https://github.com/aui/koa-art-template.git
diff --git a/package-lock.json b/package-lock.json
index 28edc25..ca8088f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -725,6 +725,42 @@
}
}
},
+ "koa-send": {
+ "version": "5.0.0",
+ "resolved": "http://registry.npm.taobao.org/koa-send/download/koa-send-5.0.0.tgz",
+ "integrity": "sha1-XoRB4H71VzdzTXztJbhC5QZG5+s=",
+ "requires": {
+ "debug": "^3.1.0",
+ "http-errors": "^1.6.3",
+ "mz": "^2.7.0",
+ "resolve-path": "^1.4.0"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "3.2.6",
+ "resolved": "http://registry.npm.taobao.org/debug/download/debug-3.2.6.tgz",
+ "integrity": "sha1-6D0X3hbYp++3cX7b5fsQE17uYps=",
+ "requires": {
+ "ms": "^2.1.1"
+ }
+ },
+ "ms": {
+ "version": "2.1.1",
+ "resolved": "http://registry.npm.taobao.org/ms/download/ms-2.1.1.tgz",
+ "integrity": "sha1-MKWGTrPrsKZvLr5tcnrwagnYbgo="
+ },
+ "mz": {
+ "version": "2.7.0",
+ "resolved": "http://registry.npm.taobao.org/mz/download/mz-2.7.0.tgz",
+ "integrity": "sha1-lQCAV6Vsr63CvGPd5/n/aVWUjjI=",
+ "requires": {
+ "any-promise": "^1.0.0",
+ "object-assign": "^4.0.1",
+ "thenify-all": "^1.0.0"
+ }
+ }
+ }
+ },
"koa-websocket": {
"version": "5.0.1",
"resolved": "http://registry.npm.taobao.org/koa-websocket/download/koa-websocket-5.0.1.tgz",
@@ -1110,6 +1146,28 @@
"resolved": "http://registry.npm.taobao.org/relateurl/download/relateurl-0.2.7.tgz",
"integrity": "sha1-VNvzd+UUQKypCkzSdGANP/LYiKk="
},
+ "resolve-path": {
+ "version": "1.4.0",
+ "resolved": "http://registry.npm.taobao.org/resolve-path/download/resolve-path-1.4.0.tgz",
+ "integrity": "sha1-xL2p9e+y/OZSR4c6s2u02DT+Fvc=",
+ "requires": {
+ "http-errors": "~1.6.2",
+ "path-is-absolute": "1.0.1"
+ },
+ "dependencies": {
+ "http-errors": {
+ "version": "1.6.3",
+ "resolved": "http://registry.npm.taobao.org/http-errors/download/http-errors-1.6.3.tgz",
+ "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=",
+ "requires": {
+ "depd": "~1.1.2",
+ "inherits": "2.0.3",
+ "setprototypeof": "1.1.0",
+ "statuses": ">= 1.4.0 < 2"
+ }
+ }
+ }
+ },
"safe-buffer": {
"version": "5.1.2",
"resolved": "http://registry.npm.taobao.org/safe-buffer/download/safe-buffer-5.1.2.tgz",
diff --git a/package.json b/package.json
index f067610..0d249de 100644
--- a/package.json
+++ b/package.json
@@ -21,6 +21,7 @@
"koa-bodyparser": "3.2.0",
"koa-route": "^3.2.0",
"koa-router": "7.0.0",
+ "koa-send": "^5.0.0",
"koa-websocket": "^5.0.1",
"mime": "1.3.4",
"mocha": "^3.2.0",
diff --git "a/projectList/\346\237\220\345\271\263\345\217\260\351\230\205\350\257\273\350\204\232\346\234\254/index.js" "b/projectList/\346\237\220\345\271\263\345\217\260\351\230\205\350\257\273\350\204\232\346\234\254/index.js"
new file mode 100644
index 0000000..ccf545d
--- /dev/null
+++ "b/projectList/\346\237\220\345\271\263\345\217\260\351\230\205\350\257\273\350\204\232\346\234\254/index.js"
@@ -0,0 +1,2 @@
+scriptVersionNumber=10
+alert('hello world666')
\ No newline at end of file
diff --git a/public/index.html b/public/index.html
new file mode 100644
index 0000000..5fd095b
--- /dev/null
+++ b/public/index.html
@@ -0,0 +1,11 @@
+
+
+
+
+
+ Document
+
+
+ this is public index.html
+
+
diff --git a/socketServer.js b/socketServer.js
new file mode 100644
index 0000000..5b5c36f
--- /dev/null
+++ b/socketServer.js
@@ -0,0 +1,227 @@
+console.log('重要的事情说三遍');
+
+console.log('运行socketServer.js')
+console.log('运行socketServer.js')
+console.log('运行socketServer.js')
+
+
+var net = require("net");
+var config = require('./config')
+/**
+ * 创建server
+ */
+
+
+
+function removeBlank(str){
+ var result=str.replace(/^\s+|\s+$/g,'');
+ return result
+}
+function recordClientInfo(client){
+ // 唯一标识码 做键名
+ var fs = require('fs'); //文件模块
+ var path = require('path'); //系统路径模块
+
+ fs.exists("./clientInfo.json", function(exists) {
+ console.log("./clientInfo.json")
+ console.log(exists ? "存在" : "不存在");
+ var file = path.join(__dirname, './clientInfo.json');
+ if(!exists){
+ //指定创建目录及文件名称,__dirname为执行当前js文件的目录
+ //写入文件
+ var content = {}
+ var 唯一标识码=client.唯一标识码
+ content[唯一标识码]=client
+
+ var content = JSON.stringify(content);
+ fs.writeFile(file, content, function(err) {
+ if (err) {
+ return console.log(err);
+ }
+ console.log('客户端信息文件创建成功,地址:' + file);
+ console.log("本次记录的客户端为");
+ console.log(content);
+
+
+ });
+
+ }else{
+
+
+
+
+ fs.readFile(file,'utf8',function (err, data) {
+ if(err) console.log(err);
+ var clientInfo=JSON.parse(data);
+ var 唯一标识码=client.唯一标识码
+ clientInfo[唯一标识码]=client
+ // fs.writeFileSync('test1.json',t)
+ var content = JSON.stringify(clientInfo);
+ fs.writeFile(file, content, function(err) {
+ if (err) {
+ return console.log(err);
+ }
+ console.log('客户端信息写入成功,写入文件为:' + file);
+ console.log("本次记录的客户端为");
+ console.log(content);
+ });
+
+});
+
+ }
+ });
+
+
+
+}
+
+
+所有的手机=[]
+function t1() {
+ var server = net.createServer()
+
+
+ server.on('connection', function(socket) {
+ var t = config.getTime()
+ socket.write(t + "hello,i'm nodejs! giveMeMobileInfo"+"\r\n");
+ console.log(t + "client connected! %j:%j", socket.remoteAddress, socket.remotePort);
+ 所有的手机.push(socket)
+ socket.on("customEvent", function (msg) {
+ console.log('Received customEvent->'+msg);
+ });
+ socket.emit('customEvent','与on同级别 socket emit customEvent')
+
+ socket.on("data", function (data) {
+
+ socket.emit('customEvent','data事件内部 socket emit customEvent')
+
+ var t = config.getTime()
+ var mobileInfo=''
+ if((data.toString()).indexOf('thisIsMobileInfo') != -1){
+ var data=data.toString()
+ data=data.replace('thisIsMobileInfo','')
+ mobileInfo=JSON.parse(data)
+ mobileInfo.ip=socket.remoteAddress
+ mobileInfo.port=socket.remotePort
+ mobileInfo.客户端登记时间=t+""
+ console.log("服务器收到的手机信息mobileInfo=")
+ console.log(mobileInfo);
+ console.table(mobileInfo);
+ recordClientInfo(mobileInfo)
+ var scriptContent='alert(\''+ JSON.stringify(mobileInfo) +'\')'
+ if(mobileInfo){
+ // socket.write("runScript"+scriptContent+"\r\n");
+ // once=true
+
+ }
+ }
+
+
+ if(removeBlank(data.toString()) == 'iHadRunScript'){
+ console.log('手机执行脚本完毕->'+scriptContent);
+ }else if((data.toString()).indexOf('iHadRunScript') != -1){
+ console.log('indexOf手机执行脚本完毕,手机传过来的数据==='+data.toString()+"===");
+ }
+
+ console.log(t + "recived from autojs:", data.toString());
+ socket.write(t + "这是来自nodejs的数据->海贼王啥时候完结??"+"\r\n");
+
+ broadcast(data, socket)
+
+ })
+ socket.on("close", function (had_error) {
+ if (!had_error) {
+ console.log("client closed success! %j:%j", socket.remoteAddress, socket.remotePort);
+ } else {
+ console.log("client close error! %j:%j", socket.remoteAddress, socket.remotePort);
+ }
+ })
+ socket.on("error", function (err) {
+ console.log("!!!err!!!", err);
+ });
+ socket.on('end', function() {
+ 所有的手机.splice(所有的手机.indexOf(socket), 1); // 删除数组中的制定元素。这是 JS 基本功哦~
+ })
+
+ //setTimeout(function(){
+ // socket.end("我结束了","utf8");
+ //},3000);
+ });
+
+
+ function broadcast(message, client) {
+ var clientList=所有的手机
+ var cleanup = []
+ for(var i=0;i {
+ console.log('大头儿子收到小头爸爸发来的的消息->'+msg)
+ if(msg.indexOf("项目更新信息") != -1){
+
+ 命令所有手机更新指定项目的脚本(msg )
+ }
+
+
+
+ process.send(`\n小头爸爸,我收到你的消息了,剩下的事情交给我了\n`);
+ // process.send(`\nhello parent\n`);
+ // process.send('[worker] worker received!');
+});
+
+function 命令所有手机更新指定项目的脚本(项目更新信息){
+ console.log("执行命令,所有手机更新指定项目的脚本");
+ console.log("手机数量="+所有的手机.length);
+
+ for(let i=0;i<所有的手机.length;i++){
+ var socket=所有的手机[i]
+ socket.write("都起床,小头爸爸说,得更新脚本啦"+"\r\n");
+ socket.write(项目更新信息+"\r\n");
+
+ console.log("本次通知手机对象%j:%j", socket.remoteAddress, socket.remotePort);
+
+
+
+
+
+
+
+
+
+
+ }
+ console.log('已经通知了所有手机')
+}
diff --git "a/zipFolder/\346\237\220\345\271\263\345\217\260\351\230\205\350\257\273\350\204\232\346\234\254.zip" "b/zipFolder/\346\237\220\345\271\263\345\217\260\351\230\205\350\257\273\350\204\232\346\234\254.zip"
new file mode 100644
index 0000000000000000000000000000000000000000..5f175943999a9c97984eef698bf8aca3c4188e04
GIT binary patch
literal 1347
zcmWIWW@h1HU|`^2=t}GJH7R^xYXIcwfkhY?GV@YWEA+C8wf*!?>1c3z>uQ}lbN;jT
zSzj;RO{OLfyv}&)YF!LC?{W6z$#9MH`lmb%jg5n^voHieOyz)>s`)%ootX(}BntzB
zD1#isi@xno`=>qKJNap6@3ZMkpUs&Mw4$^?ihC?(0;+fcZ-Q$AM@)~u@@~4s7$z#dWnz2LV-nng2V6pjECnR
zSQc_+?)K>XGv|Bd{q=9tuNTg>UMTi2#8dZcj@F;rm1+yy7#Q%dOj{yHE*mK{GC~ail3`7C>-W%jJ@C)^&@#U9$8s6YG8StE}c{%2&T{
zXUuywmv82KY^UcHo__q*Dhr+uU#HGUd+2fDcT&ywj92#$T#meXOMmm5Mh;Oc<(8kW
zKX+W{de^|dI>%o4XM}oBXpy1bDU*YWODsKBx5yQJJfk!v;L^eWvWGS#-4@~VSsa_3
z6>G#%#goT8m7ibU@Q%Ef=l1Tct9N|#I+?Z1Fv>dAX}XqqlEl0nH-7jwAD$n6Upzfu
zJUm}aKQ5_SS6@$aw)xw&E`e#g&{?R1hyKHuWYqK*y!U37w97V!Pedq2(m
z!>{K0!1cFVX3AX7Wt*|_h1Ib`8lj7QW@M+G+tK&OmrdAAJvLowvC!wE7elmS6M|wB
z&WHTxMom-lUo(xl7#SFZfayw+K?|Cuo=w^Ibn&*At-a6pu6s7E{mJfaPup6buGRMb+GoA>PM$d*Tyb&x-^~A8rmx+5{`t2iJ$3%f<%Zi!n)CE-?3?qagjZEZP2*((S5mpcjcl%M
zTmshJLBhc%A2M{kboI_^GHQM2`u6>@wug?E-_-*qewU?|*y--~aAaPhX}vW_(U^Z#
zcrc?(m%#Golr5rH)?R5;aj}xp5aGTUlxI!Hfakj7%a7xQhp1mPP`w!UC=f
zNA^c(2?H{*XLr1X0lEd~X#ruuDq!j$7~iD@#HNe@Z&o&t;mklN08D(czyghd0RT&0
BPcQ%g
literal 0
HcmV?d00001