Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
9cf1636a
Commit
9cf1636a
authored
Oct 20, 2020
by
Sxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 代码规范
parent
e9c9dddf
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
415 additions
and
437 deletions
+415
-437
icp-deliver/app/base/api/impl/meta/oss.js
+1
-1
icp-deliver/app/base/controller/impl/common/uploadCtl.js
+5
-3
icp-deliver/app/base/db/cache/CacheLocker.js
+0
-22
icp-deliver/app/base/db/cache/vcodeCache.js
+1
-3
icp-deliver/app/base/db/dao.base.js
+15
-6
icp-deliver/app/base/db/impl/auth/roleDao.js
+2
-2
icp-deliver/app/base/service/impl/auth/orgSve.js
+1
-1
icp-deliver/app/base/system.js
+356
-356
icp-deliver/app/base/utils/redisClient.js
+2
-1
icp-deliver/app/base/utils/restClient.js
+25
-31
icp-deliver/dochelp/imghandle.js
+6
-10
icp-deliver/main.js
+1
-1
No files found.
icp-deliver/app/base/api/impl/meta/oss.js
View file @
9cf1636a
...
@@ -42,7 +42,7 @@ class OSSAPI extends APIBase {
...
@@ -42,7 +42,7 @@ class OSSAPI extends APIBase {
}
}
async
downfile
(
srckey
)
{
async
downfile
(
srckey
)
{
const
oss
=
System
.
getObject
(
'util.ossClient'
);
const
oss
=
System
.
getObject
(
'util.ossClient'
);
le
t
downfile
=
await
oss
.
downfile
(
srckey
).
then
(()
=>
{
cons
t
downfile
=
await
oss
.
downfile
(
srckey
).
then
(()
=>
{
return
`/tmp/
${
srckey
}
`
;
return
`/tmp/
${
srckey
}
`
;
});
});
return
downfile
;
return
downfile
;
...
...
icp-deliver/app/base/controller/impl/common/uploadCtl.js
View file @
9cf1636a
...
@@ -46,7 +46,8 @@ class UploadCtl extends CtlBase {
...
@@ -46,7 +46,8 @@ class UploadCtl extends CtlBase {
}
}
async
downfile
(
srckey
)
{
async
downfile
(
srckey
)
{
const
oss
=
system
.
getObject
(
'util.ossClient'
);
const
oss
=
system
.
getObject
(
'util.ossClient'
);
var
downfile
=
await
oss
.
downfile
(
srckey
).
then
(()
=>
{
let
downfile
;
downfile
=
await
oss
.
downfile
(
srckey
).
then
(()
=>
{
downfile
=
`/tmp/
${
srckey
}
`
;
downfile
=
`/tmp/
${
srckey
}
`
;
return
downfile
;
return
downfile
;
});
});
...
@@ -64,8 +65,9 @@ class UploadCtl extends CtlBase {
...
@@ -64,8 +65,9 @@ class UploadCtl extends CtlBase {
return
result
.
url
;
return
result
.
url
;
}
}
async
insertToFile
(
path
)
{
async
insertToFile
(
path
)
{
const
cmd
=
`
${
this
.
cmdInsertToFilePattern
}
${
path
}
`
;
const
cmd
=
`
${
this
.
cmdInsertToFilePattern
}${
path
}
`
;
return
await
this
.
restS
.
exec
(
cmd
);
const
result
=
await
this
.
restS
.
exec
(
cmd
);
return
result
;
}
}
}
}
module
.
exports
=
UploadCtl
;
module
.
exports
=
UploadCtl
;
icp-deliver/app/base/db/cache/CacheLocker.js
deleted
100644 → 0
View file @
e9c9dddf
const
CacheBase
=
require
(
'../cache.base'
);
const
system
=
require
(
'../../system'
);
// 缓存首次登录的赠送的宝币数量
class
CacheLocker
extends
CacheBase
{
constructor
()
{
super
();
this
.
prefix
=
'locker_'
;
}
async
init
(
tradekey
)
{
const
key
=
this
.
prefix
+
tradekey
;
return
this
.
redisClient
.
rpushWithEx
(
key
,
'1'
,
1800
);
}
async
enter
(
tradekey
)
{
const
key
=
this
.
prefix
+
tradekey
;
return
this
.
redisClient
.
rpop
(
key
);
}
async
release
(
tradekey
)
{
const
key
=
this
.
prefix
+
tradekey
;
return
this
.
redisClient
.
rpushWithEx
(
key
,
'1'
,
1800
);
}
}
module
.
exports
=
CacheLocker
;
icp-deliver/app/base/db/cache/vcodeCache.js
View file @
9cf1636a
...
@@ -24,9 +24,7 @@ class VCodeCache extends CacheBase {
...
@@ -24,9 +24,7 @@ class VCodeCache extends CacheBase {
const
vcode
=
await
this
.
smsUtil
.
getUidStr
(
6
,
10
);
const
vcode
=
await
this
.
smsUtil
.
getUidStr
(
6
,
10
);
if
(
!
tmplCode
&&
!
signName
)
{
if
(
!
tmplCode
&&
!
signName
)
{
this
.
smsUtil
.
sendMsg
(
mobile
,
vcode
);
this
.
smsUtil
.
sendMsg
(
mobile
,
vcode
);
}
}
else
{
// tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码
else
{
this
.
smsUtil
.
aliSendMsg
(
mobile
,
tmplCode
,
signName
,
JSON
.
stringify
({
code
:
vcode
}));
this
.
smsUtil
.
aliSendMsg
(
mobile
,
tmplCode
,
signName
,
JSON
.
stringify
({
code
:
vcode
}));
}
}
return
JSON
.
stringify
({
vcode
});
return
JSON
.
stringify
({
vcode
});
...
...
icp-deliver/app/base/db/dao.base.js
View file @
9cf1636a
...
@@ -48,9 +48,13 @@ class Dao {
...
@@ -48,9 +48,13 @@ class Dao {
const
en
=
null
;
const
en
=
null
;
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
whereParam
.
transaction
=
t
;
whereParam
.
transaction
=
t
;
return
await
this
.
model
.
destroy
(
whereParam
);
const
result
=
await
this
.
model
.
destroy
(
whereParam
);
return
result
}
}
return
await
this
.
model
.
destroy
(
whereParam
);
const
result
=
await
this
.
model
.
destroy
(
whereParam
);
return
result
}
}
async
delete
(
qobj
,
t
)
{
async
delete
(
qobj
,
t
)
{
let
en
=
null
;
let
en
=
null
;
...
@@ -177,9 +181,12 @@ class Dao {
...
@@ -177,9 +181,12 @@ class Dao {
}
}
async
bulkCreate
(
ids
,
t
)
{
async
bulkCreate
(
ids
,
t
)
{
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
return
await
this
.
model
.
bulkCreate
(
ids
,
{
transaction
:
t
});
const
result
=
await
this
.
model
.
bulkCreate
(
ids
,
{
transaction
:
t
});
return
result
;
}
}
return
await
this
.
model
.
bulkCreate
(
ids
);
const
result
=
await
this
.
model
.
bulkCreate
(
ids
);
return
result
;
}
}
async
updateByWhere
(
setObj
,
whereObj
,
t
)
{
async
updateByWhere
(
setObj
,
whereObj
,
t
)
{
...
@@ -200,7 +207,7 @@ class Dao {
...
@@ -200,7 +207,7 @@ class Dao {
return
this
.
db
.
query
(
sql
,
paras
);
return
this
.
db
.
query
(
sql
,
paras
);
}
}
async
customQuery
(
sql
,
paras
,
t
)
{
async
customQuery
(
sql
,
paras
,
t
)
{
let
tmpParas
=
null
;
// ||paras=='undefined'?{type: this.db.QueryTypes.SELECT }:{ replacements: paras, type: this.db.QueryTypes.SELECT };
let
tmpParas
=
null
;
if
(
t
&&
t
!=
'undefined'
)
{
if
(
t
&&
t
!=
'undefined'
)
{
if
(
paras
==
null
||
paras
==
'undefined'
)
{
if
(
paras
==
null
||
paras
==
'undefined'
)
{
tmpParas
=
{
type
:
this
.
db
.
QueryTypes
.
SELECT
};
tmpParas
=
{
type
:
this
.
db
.
QueryTypes
.
SELECT
};
...
@@ -239,7 +246,9 @@ class Dao {
...
@@ -239,7 +246,9 @@ class Dao {
}
else
{
}
else
{
tmpWhere
.
raw
=
true
;
tmpWhere
.
raw
=
true
;
}
}
return
await
this
.
model
.
findAndCountAll
(
tmpWhere
);
const
result
=
await
this
.
model
.
findAndCountAll
(
tmpWhere
);
return
result
;
}
}
async
findOne
(
obj
,
attributes
=
[])
{
async
findOne
(
obj
,
attributes
=
[])
{
if
(
attributes
.
length
>
0
)
{
if
(
attributes
.
length
>
0
)
{
...
...
icp-deliver/app/base/db/impl/auth/roleDao.js
View file @
9cf1636a
...
@@ -38,10 +38,10 @@ class RoleDao extends Dao {
...
@@ -38,10 +38,10 @@ class RoleDao extends Dao {
const
self
=
this
;
const
self
=
this
;
const
u2
=
await
this
.
preCreate
(
u
);
const
u2
=
await
this
.
preCreate
(
u
);
if
(
t
)
{
if
(
t
)
{
le
t
role
=
await
this
.
model
.
create
(
u2
,
{
transaction
:
t
});
cons
t
role
=
await
this
.
model
.
create
(
u2
,
{
transaction
:
t
});
return
role
;
return
role
;
}
else
{
}
else
{
le
t
role
=
await
this
.
model
.
create
(
u2
);
cons
t
role
=
await
this
.
model
.
create
(
u2
);
return
role
;
return
role
;
}
}
}
}
...
...
icp-deliver/app/base/service/impl/auth/orgSve.js
View file @
9cf1636a
...
@@ -55,7 +55,7 @@ class OrgService extends ServiceBase {
...
@@ -55,7 +55,7 @@ class OrgService extends ServiceBase {
const
roles
=
await
self
.
db
.
models
.
role
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
p
.
Roles
}
}
});
const
roles
=
await
self
.
db
.
models
.
role
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
p
.
Roles
}
}
});
await
orgupdate
.
setRoles
(
roles
,
{
transaction
:
t
});
await
orgupdate
.
setRoles
(
roles
,
{
transaction
:
t
});
// 同时要给这个岗位下的user,更新角色 todo
// 同时要给这个岗位下的user,更新角色 todo
for
(
le
t
ud
of
usersupdate
)
{
for
(
cons
t
ud
of
usersupdate
)
{
await
ud
.
setRoles
(
roles
,
{
transaction
:
t
});
await
ud
.
setRoles
(
roles
,
{
transaction
:
t
});
}
}
}
}
...
...
icp-deliver/app/base/system.js
View file @
9cf1636a
...
@@ -5,346 +5,346 @@ const request = require('request');
...
@@ -5,346 +5,346 @@ const request = require('request');
const
cryptoJS
=
require
(
'crypto-js'
);
const
cryptoJS
=
require
(
'crypto-js'
);
class
System
{
class
System
{
static
declare
(
ns
)
{
static
declare
(
ns
)
{
const
ar
=
ns
.
split
(
'.'
);
const
ar
=
ns
.
split
(
'.'
);
let
root
=
System
;
let
root
=
System
;
for
(
let
i
=
0
,
len
=
ar
.
length
;
i
<
len
;
++
i
)
{
for
(
let
i
=
0
,
len
=
ar
.
length
;
i
<
len
;
++
i
)
{
const
n
=
ar
[
i
];
const
n
=
ar
[
i
];
if
(
!
root
[
n
])
{
if
(
!
root
[
n
])
{
root
[
n
]
=
{};
root
[
n
]
=
{};
root
=
root
[
n
];
root
=
root
[
n
];
}
else
{
}
else
{
root
=
root
[
n
];
root
=
root
[
n
];
}
}
}
}
}
}
static
async
delReq
(
url
,
qdata
)
{
static
async
delReq
(
url
,
qdata
)
{
const
rtn
=
{};
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
del
({
request
.
del
({
url
,
url
,
qs
:
qdata
,
qs
:
qdata
,
},
(
error
,
response
,
body
)
=>
{
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
!
error
)
{
if
(
body
)
{
if
(
body
)
{
const
data
=
JSON
.
parse
(
body
);
const
data
=
JSON
.
parse
(
body
);
rtn
.
data
=
data
;
rtn
.
data
=
data
;
}
else
{
}
else
{
rtn
.
data
=
null
;
rtn
.
data
=
null
;
}
}
resv
(
rtn
);
resv
(
rtn
);
}
else
{
}
else
{
rej
(
error
);
rej
(
error
);
}
}
});
});
}));
}));
return
promise
;
return
promise
;
}
}
static
async
getReq
(
url
,
qdata
)
{
static
async
getReq
(
url
,
qdata
)
{
const
rtn
=
{};
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
get
({
request
.
get
({
url
,
url
,
json
:
true
,
json
:
true
,
qs
:
qdata
,
qs
:
qdata
,
},
(
error
,
response
,
body
)
=>
{
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
!
error
)
{
if
(
body
)
{
if
(
body
)
{
rtn
.
data
=
body
;
rtn
.
data
=
body
;
}
else
{
}
else
{
rtn
.
data
=
null
;
rtn
.
data
=
null
;
}
}
resv
(
rtn
);
resv
(
rtn
);
}
else
{
}
else
{
rej
(
error
);
rej
(
error
);
}
}
});
});
}));
}));
return
promise
;
return
promise
;
}
}
static
async
postJsonTypeReq
(
url
,
data
,
md
=
'POST'
)
{
static
async
postJsonTypeReq
(
url
,
data
,
md
=
'POST'
)
{
const
rtn
=
{};
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
({
request
({
url
,
url
,
method
:
md
,
method
:
md
,
json
:
true
,
json
:
true
,
headers
:
{
headers
:
{
'Content-type'
:
'application/json'
,
'Content-type'
:
'application/json'
,
// 'Authorization': 'Basic YWRtaW5lczphZG1pbkdTQmVzLg=='
// 'Authorization': 'Basic YWRtaW5lczphZG1pbkdTQmVzLg=='
},
},
body
:
data
,
body
:
data
,
},
(
error
,
response
,
body
)
=>
{
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
!
error
)
{
if
(
body
)
{
if
(
body
)
{
rtn
.
data
=
body
;
rtn
.
data
=
body
;
}
else
{
}
else
{
rtn
.
data
=
null
;
rtn
.
data
=
null
;
}
}
resv
(
rtn
);
resv
(
rtn
);
}
else
{
}
else
{
rej
(
error
);
rej
(
error
);
}
}
});
});
}));
}));
return
promise
;
return
promise
;
}
}
static
async
post3wFormTypeReq
(
url
,
data
)
{
static
async
post3wFormTypeReq
(
url
,
data
)
{
const
rtn
=
{};
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
post
({
request
.
post
({
url
,
url
,
form
:
data
,
form
:
data
,
},
(
error
,
response
,
body
)
=>
{
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
!
error
)
{
const
data
=
JSON
.
parse
(
body
);
const
data
=
JSON
.
parse
(
body
);
rtn
.
data
=
data
;
rtn
.
data
=
data
;
resv
(
rtn
);
resv
(
rtn
);
}
else
{
}
else
{
rej
(
error
);
rej
(
error
);
}
}
});
});
}));
}));
return
promise
;
return
promise
;
}
}
static
async
postMpFormTypeReq
(
url
,
formdata
)
{
static
async
postMpFormTypeReq
(
url
,
formdata
)
{
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
post
({
request
.
post
({
url
,
url
,
formData
:
formdata
,
formData
:
formdata
,
},
(
error
,
response
,
body
)
=>
{
},
(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
resv
(
body
);
resv
(
body
);
}
else
{
}
else
{
rej
(
error
);
rej
(
error
);
}
}
});
});
}));
}));
return
promise
;
return
promise
;
}
}
/**
/**
* 请求返回成功
* 请求返回成功
* @param {*} data 操作成功返回的数据,有值为成功,无值为失败
* @param {*} data 操作成功返回的数据,有值为成功,无值为失败
* @param {*} okmsg 操作成功的描述
* @param {*} okmsg 操作成功的描述
* @param {*} req 请求头信息
* @param {*} req 请求头信息
*/
*/
static
getResult
(
data
,
opmsg
=
'操作成功'
,
req
)
{
static
getResult
(
data
,
opmsg
=
'操作成功'
,
req
)
{
return
{
return
{
status
:
!
data
?
-
1
:
0
,
status
:
!
data
?
-
1
:
0
,
msg
:
opmsg
,
msg
:
opmsg
,
data
,
data
,
bizmsg
:
req
&&
req
.
session
&&
req
.
session
.
bizmsg
?
req
.
session
.
bizmsg
:
'empty'
,
bizmsg
:
req
&&
req
.
session
&&
req
.
session
.
bizmsg
?
req
.
session
.
bizmsg
:
'empty'
,
};
};
}
}
/**
/**
* 请求返回成功
* 请求返回成功
* @param {*} data 操作成功返回的数据
* @param {*} data 操作成功返回的数据
* @param {*} okmsg 操作成功的描述
* @param {*} okmsg 操作成功的描述
*/
*/
static
getResultSuccess
(
data
,
okmsg
=
'success'
)
{
static
getResultSuccess
(
data
,
okmsg
=
'success'
)
{
return
{
return
{
status
:
0
,
status
:
0
,
msg
:
okmsg
,
msg
:
okmsg
,
data
,
data
,
};
};
}
}
/**
/**
* 请求返回失败
* 请求返回失败
* @param {*} status 操作失败状态,默认为-1
* @param {*} status 操作失败状态,默认为-1
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
* @param {*} data 操作失败返回的数据
*/
*/
static
getResultFail
(
status
=
-
1
,
errmsg
=
'fail'
,
data
=
null
)
{
static
getResultFail
(
status
=
-
1
,
errmsg
=
'fail'
,
data
=
null
)
{
return
{
return
{
status
,
status
,
msg
:
errmsg
,
msg
:
errmsg
,
data
,
data
,
};
};
}
}
/**
/**
* 请求处理异常
* 请求处理异常
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
* @param {*} data 操作失败返回的数据
*/
*/
static
getResultError
(
errmsg
=
'fail'
,
data
=
null
)
{
static
getResultError
(
errmsg
=
'fail'
,
data
=
null
)
{
return
{
return
{
status
:
-
200
,
status
:
-
200
,
msg
:
errmsg
,
msg
:
errmsg
,
data
,
data
,
};
};
}
}
static
register
(
key
,
ClassObj
,
groupName
,
filename
)
{
static
register
(
key
,
ClassObj
,
groupName
,
filename
)
{
if
(
System
.
objTable
[
key
]
!=
null
)
{
if
(
System
.
objTable
[
key
]
!=
null
)
{
throw
new
Error
(
'相同key的对象已经存在'
);
throw
new
Error
(
'相同key的对象已经存在'
);
}
else
{
}
else
{
let
obj
;
let
obj
;
if
(
ClassObj
.
name
===
'ServiceBase'
)
{
if
(
ClassObj
.
name
===
'ServiceBase'
)
{
obj
=
new
ClassObj
(
groupName
,
filename
.
replace
(
'Sve'
,
'Dao'
));
obj
=
new
ClassObj
(
groupName
,
filename
.
replace
(
'Sve'
,
'Dao'
));
}
else
{
}
else
{
obj
=
new
ClassObj
(
groupName
,
filename
);
obj
=
new
ClassObj
(
groupName
,
filename
);
}
}
System
.
objTable
[
key
]
=
obj
;
System
.
objTable
[
key
]
=
obj
;
}
}
return
System
.
objTable
[
key
];
return
System
.
objTable
[
key
];
}
}
static
getObject
(
objpath
)
{
static
getObject
(
objpath
)
{
const
pathArray
=
objpath
.
split
(
'.'
);
const
pathArray
=
objpath
.
split
(
'.'
);
const
packageName
=
pathArray
[
0
];
const
packageName
=
pathArray
[
0
];
const
groupName
=
pathArray
[
1
];
const
groupName
=
pathArray
[
1
];
let
filename
=
pathArray
[
2
];
let
filename
=
pathArray
[
2
];
let
classpath
=
''
;
let
classpath
=
''
;
if
(
filename
)
{
if
(
filename
)
{
classpath
=
`
${
objsettings
[
packageName
]}
/
${
groupName
}
`
;
classpath
=
`
${
objsettings
[
packageName
]}
/
${
groupName
}
`
;
}
else
{
}
else
{
classpath
=
objsettings
[
packageName
];
classpath
=
objsettings
[
packageName
];
filename
=
groupName
;
filename
=
groupName
;
}
}
const
objabspath
=
`
${
classpath
}
/
${
filename
}
.js`
;
const
objabspath
=
`
${
classpath
}
/
${
filename
}
.js`
;
// 判断文件的存在性
// 判断文件的存在性
// 如果不存在,需要查看packageName
// 如果不存在,需要查看packageName
// 如果packageName=web.service,dao
// 如果packageName=web.service,dao
if
(
System
.
objTable
[
objabspath
]
!=
null
)
{
if
(
System
.
objTable
[
objabspath
]
!=
null
)
{
return
System
.
objTable
[
objabspath
];
return
System
.
objTable
[
objabspath
];
}
}
let
ClassObj
=
null
;
let
ClassObj
=
null
;
try
{
try
{
ClassObj
=
require
(
objabspath
);
ClassObj
=
require
(
objabspath
);
}
catch
(
e
)
{
}
catch
(
e
)
{
// console.log(e)
// console.log(e)
const
fname
=
objsettings
[
`
${
packageName
}
base`
];
const
fname
=
objsettings
[
`
${
packageName
}
base`
];
ClassObj
=
require
(
fname
);
ClassObj
=
require
(
fname
);
}
}
if
(
ClassObj
.
name
==
'Dao'
)
{
if
(
ClassObj
.
name
==
'Dao'
)
{
const
modelname
=
filename
.
substring
(
0
,
filename
.
lastIndexOf
(
'Dao'
));
const
modelname
=
filename
.
substring
(
0
,
filename
.
lastIndexOf
(
'Dao'
));
return
System
.
register
(
objabspath
,
ClassObj
,
modelname
);
return
System
.
register
(
objabspath
,
ClassObj
,
modelname
);
}
}
if
(
ClassObj
.
name
.
indexOf
(
'Ctl'
)
>=
0
)
{
if
(
ClassObj
.
name
.
indexOf
(
'Ctl'
)
>=
0
)
{
console
.
log
(
ClassObj
.
name
);
console
.
log
(
ClassObj
.
name
);
}
}
return
System
.
register
(
objabspath
,
ClassObj
,
groupName
,
filename
);
return
System
.
register
(
objabspath
,
ClassObj
,
groupName
,
filename
);
}
}
static
getSysConfig
()
{
static
getSysConfig
()
{
const
configPath
=
`
${
settings
.
basepath
}
/app/base/db/metadata/index.js`
;
const
configPath
=
`
${
settings
.
basepath
}
/app/base/db/metadata/index.js`
;
// if(settings.env=="dev"){
// if(settings.env=="dev"){
// console.log("delete "+configPath+"cache config");
// console.log("delete "+configPath+"cache config");
// delete require.cache[configPath];
// delete require.cache[configPath];
// }
// }
delete
require
.
cache
[
configPath
];
delete
require
.
cache
[
configPath
];
const
configValue
=
require
(
configPath
);
const
configValue
=
require
(
configPath
);
return
configValue
.
config
;
return
configValue
.
config
;
}
}
static
getClientIp
(
req
)
{
static
getClientIp
(
req
)
{
const
ip
=
req
.
headers
[
'x-forwarded-for'
]
const
ip
=
req
.
headers
[
'x-forwarded-for'
]
||
req
.
ip
||
req
.
ip
||
req
.
connection
.
remoteAddress
||
req
.
connection
.
remoteAddress
||
req
.
socket
.
remoteAddress
||
req
.
socket
.
remoteAddress
||
(
req
.
connection
.
socket
&&
req
.
connection
.
socket
.
remoteAddress
)
||
''
;
||
(
req
.
connection
.
socket
&&
req
.
connection
.
socket
.
remoteAddress
)
||
''
;
const
x
=
ip
.
match
(
/
(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
])\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
]
|0
)\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
]
|0
)\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
0-9
])
$/
);
const
x
=
ip
.
match
(
/
(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
])\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
]
|0
)\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
]
|0
)\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
0-9
])
$/
);
if
(
x
)
{
if
(
x
)
{
return
x
[
0
];
return
x
[
0
];
}
}
return
'localhost'
;
return
'localhost'
;
};
}
/**
/**
* 记录日志信息
* 记录日志信息
* @param {*} opTitle 操作的标题
* @param {*} opTitle 操作的标题
* @param {*} params 参数
* @param {*} params 参数
* @param {*} identifyCode 业务标识
* @param {*} identifyCode 业务标识
* @param {*} resultInfo 返回结果
* @param {*} resultInfo 返回结果
* @param {*} errorInfo 错误信息
* @param {*} errorInfo 错误信息
*/
*/
static
execLogs
(
opTitle
,
params
,
identifyCode
,
resultInfo
,
errorInfo
)
{
static
execLogs
(
opTitle
,
params
,
identifyCode
,
resultInfo
,
errorInfo
)
{
const
reqUrl
=
settings
.
logUrl
();
const
reqUrl
=
settings
.
logUrl
();
let
isLogData
=
true
;
let
isLogData
=
true
;
if
(
params
.
method
&&
(
params
.
method
.
indexOf
(
'find'
)
>=
0
||
params
.
method
.
indexOf
(
'get'
)
>=
0
))
{
if
(
params
.
method
&&
(
params
.
method
.
indexOf
(
'find'
)
>=
0
||
params
.
method
.
indexOf
(
'get'
)
>=
0
))
{
isLogData
=
false
;
isLogData
=
false
;
}
}
const
param
=
{
const
param
=
{
actionType
:
'produceLogsData'
,
// Y 功能名称
actionType
:
'produceLogsData'
,
// Y 功能名称
actionBody
:
{
actionBody
:
{
opTitle
:
opTitle
||
''
,
// N 操作的业务标题
opTitle
:
opTitle
||
''
,
// N 操作的业务标题
identifyCode
:
identifyCode
||
'brg-center-manage'
,
// Y 操作的业务标识
identifyCode
:
identifyCode
||
'brg-center-manage'
,
// Y 操作的业务标识
indexName
:
settings
.
logindex
,
// Y es索引值,同一个项目用一个值
indexName
:
settings
.
logindex
,
// Y es索引值,同一个项目用一个值
messageBody
:
params
,
// 日志的描述信息
messageBody
:
params
,
// 日志的描述信息
resultInfo
:
isLogData
?
resultInfo
:
{
status
:
resultInfo
.
status
},
// 返回信息
resultInfo
:
isLogData
?
resultInfo
:
{
status
:
resultInfo
.
status
},
// 返回信息
errorInfo
,
// 错误信息
errorInfo
,
// 错误信息
requestId
:
resultInfo
.
requestId
||
''
,
requestId
:
resultInfo
.
requestId
||
''
,
},
},
};
};
console
.
log
(
JSON
.
stringify
(
param
));
console
.
log
(
JSON
.
stringify
(
param
));
const
P
=
new
Promise
((
resv
,
rej
)
=>
{
const
P
=
new
Promise
((
resv
,
rej
)
=>
{
this
.
postJsonTypeReq
(
reqUrl
,
param
).
then
((
res
)
=>
{
this
.
postJsonTypeReq
(
reqUrl
,
param
).
then
((
res
)
=>
{
if
(
res
.
statusCode
==
200
)
{
if
(
res
.
statusCode
==
200
)
{
resv
(
res
.
data
);
resv
(
res
.
data
);
}
else
{
}
else
{
rej
(
null
);
rej
(
null
);
}
}
});
});
});
});
return
P
;
return
P
;
}
}
/**
/**
* 加密信息
* 加密信息
* @param {*} opStr
* @param {*} opStr
*/
*/
static
encryptStr
(
opStr
)
{
static
encryptStr
(
opStr
)
{
if
(
!
opStr
)
{
if
(
!
opStr
)
{
return
opStr
;
return
opStr
;
}
}
const
keyHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_key
);
const
keyHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_key
);
const
ivHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_secret
.
substring
(
0
,
8
));
const
ivHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_secret
.
substring
(
0
,
8
));
const
cipherStr
=
cryptoJS
.
TripleDES
.
encrypt
(
opStr
,
keyHex
,
{
iv
:
ivHex
}).
toString
();
const
cipherStr
=
cryptoJS
.
TripleDES
.
encrypt
(
opStr
,
keyHex
,
{
iv
:
ivHex
}).
toString
();
return
cipherStr
;
return
cipherStr
;
}
}
/**
/**
* 解密信息
* 解密信息
* @param {*} opStr
* @param {*} opStr
*/
*/
static
decryptStr
(
opStr
)
{
static
decryptStr
(
opStr
)
{
if
(
!
opStr
)
{
if
(
!
opStr
)
{
return
opStr
;
return
opStr
;
}
}
try
{
try
{
const
keyHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_key
);
const
keyHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_key
);
const
ivHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_secret
.
substring
(
0
,
8
));
const
ivHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_secret
.
substring
(
0
,
8
));
const
bytes
=
cryptoJS
.
TripleDES
.
decrypt
(
opStr
,
keyHex
,
{
const
bytes
=
cryptoJS
.
TripleDES
.
decrypt
(
opStr
,
keyHex
,
{
iv
:
ivHex
,
iv
:
ivHex
,
});
});
const
plaintext
=
bytes
.
toString
(
cryptoJS
.
enc
.
Utf8
);
const
plaintext
=
bytes
.
toString
(
cryptoJS
.
enc
.
Utf8
);
return
plaintext
||
opStr
;
return
plaintext
||
opStr
;
}
catch
(
err
)
{
}
catch
(
err
)
{
return
opStr
;
return
opStr
;
}
}
}
}
}
}
Date
.
prototype
.
Format
=
function
(
fmt
)
{
// author: meizz
Date
.
prototype
.
Format
=
function
(
fmt
)
{
// author: meizz
const
o
=
{
const
o
=
{
'M+'
:
this
.
getMonth
()
+
1
,
// 月份
'M+'
:
this
.
getMonth
()
+
1
,
// 月份
'd+'
:
this
.
getDate
(),
// 日
'd+'
:
this
.
getDate
(),
// 日
'h+'
:
this
.
getHours
(),
// 小时
'h+'
:
this
.
getHours
(),
// 小时
'm+'
:
this
.
getMinutes
(),
// 分
'm+'
:
this
.
getMinutes
(),
// 分
's+'
:
this
.
getSeconds
(),
// 秒
's+'
:
this
.
getSeconds
(),
// 秒
'q+'
:
Math
.
floor
((
this
.
getMonth
()
+
3
)
/
3
),
// 季度
'q+'
:
Math
.
floor
((
this
.
getMonth
()
+
3
)
/
3
),
// 季度
S
:
this
.
getMilliseconds
(),
// 毫秒
S
:
this
.
getMilliseconds
(),
// 毫秒
};
};
if
(
/
(
y+
)
/
.
test
(
fmt
))
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
`
${
this
.
getFullYear
()}
`
).
substr
(
4
-
RegExp
.
$1
.
length
));
if
(
/
(
y+
)
/
.
test
(
fmt
))
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
`
${
this
.
getFullYear
()}
`
).
substr
(
4
-
RegExp
.
$1
.
length
));
for
(
const
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
)));
for
(
const
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
;
return
fmt
;
};
};
/**
/**
...
@@ -353,57 +353,57 @@ Date.prototype.Format = function (fmt) { // author: meizz
...
@@ -353,57 +353,57 @@ Date.prototype.Format = function (fmt) { // author: meizz
// 表分类
// 表分类
System
.
FLOWCODE
=
{
System
.
FLOWCODE
=
{
BIZ
:
'BIZ'
,
// 商机表
BIZ
:
'BIZ'
,
// 商机表
SCHEME
:
'SCHEME'
,
// 方案表
SCHEME
:
'SCHEME'
,
// 方案表
DELIVERY
:
'DELIVERY'
,
// 服务单表
DELIVERY
:
'DELIVERY'
,
// 服务单表
ANNUALREPORT
:
'ANNUALREPORT'
,
// 年报表
ANNUALREPORT
:
'ANNUALREPORT'
,
// 年报表
};
};
// 服务名称
// 服务名称
System
.
SERVICECODE
=
{
System
.
SERVICECODE
=
{
ICP
:
'ICP'
,
ICP
:
'ICP'
,
EDI
:
'EDI'
,
EDI
:
'EDI'
,
ICPANNUALREPORT
:
'ICPANNUALREPORT'
,
ICPANNUALREPORT
:
'ICPANNUALREPORT'
,
EDIANNUALREPORT
:
'EDIANNUALREPORT'
,
EDIANNUALREPORT
:
'EDIANNUALREPORT'
,
};
};
// 商机状态
// 商机状态
System
.
BUSSTATUS
=
{
System
.
BUSSTATUS
=
{
WAITINGSCHEME
:
'beforeSubmission'
,
// 待提交方案
WAITINGSCHEME
:
'beforeSubmission'
,
// 待提交方案
WAITINGCONFIRM
:
'beforeConfirmation'
,
// 待用户确认
WAITINGCONFIRM
:
'beforeConfirmation'
,
// 待用户确认
SUCCESS
:
'isFinished'
,
// 已成交
SUCCESS
:
'isFinished'
,
// 已成交
CLOSED
:
'isClosed'
,
// 需求关闭
CLOSED
:
'isClosed'
,
// 需求关闭
};
};
// 方案状态
// 方案状态
System
.
SCHEMESTATUS
=
{
System
.
SCHEMESTATUS
=
{
WAITINGCONFIRM
:
'beforeConfirmation'
,
// 待用户确认.
WAITINGCONFIRM
:
'beforeConfirmation'
,
// 待用户确认.
CLOSED
:
'isClosed'
,
// 方案关闭
CLOSED
:
'isClosed'
,
// 方案关闭
REJECT
:
'isReject'
,
// 方案被拒绝
REJECT
:
'isReject'
,
// 方案被拒绝
};
};
// 资质服务单状态
// 资质服务单状态
System
.
SERVERSESTATUS
=
{
System
.
SERVERSESTATUS
=
{
RECEIVED
:
'received'
,
// 已接单
RECEIVED
:
'received'
,
// 已接单
COLLECTING
:
'collecting'
,
// 收集材料中
COLLECTING
:
'collecting'
,
// 收集材料中
SUBMITING
:
'submiting'
,
// 递交材料中
SUBMITING
:
'submiting'
,
// 递交材料中
DISPOSEING
:
'disposeing'
,
// 工信部处理中
DISPOSEING
:
'disposeing'
,
// 工信部处理中
POSTING
:
'posting'
,
// 证书已邮寄
POSTING
:
'posting'
,
// 证书已邮寄
SUCCESS
:
'success'
,
// 服务已完成
SUCCESS
:
'success'
,
// 服务已完成
CLOSED
:
'closed'
,
// 已关闭
CLOSED
:
'closed'
,
// 已关闭
};
};
// 年报服务单状态
// 年报服务单状态
System
.
ANNUALREPORT
=
{
System
.
ANNUALREPORT
=
{
RECEIVED
:
'received'
,
// 已接单
RECEIVED
:
'received'
,
// 已接单
WAITDECLARE
:
'waitdeclare'
,
// 待申报
WAITDECLARE
:
'waitdeclare'
,
// 待申报
DECLARESUCCESS
:
'declaresuccess'
,
// 申报成功
DECLARESUCCESS
:
'declaresuccess'
,
// 申报成功
SUCCESS
:
'success'
,
// 服务已完成
SUCCESS
:
'success'
,
// 服务已完成
CLOSED
:
'closed'
,
// 已关闭
CLOSED
:
'closed'
,
// 已关闭
TAKEEFFECT
:
'takeeffect'
,
// 生效
TAKEEFFECT
:
'takeeffect'
,
// 生效
};
};
// 渠道名
// 渠道名
System
.
SOURCENAME
=
{
System
.
SOURCENAME
=
{
tencentCloud
:
'腾讯云'
,
tencentCloud
:
'腾讯云'
,
};
};
/*
/*
...
...
icp-deliver/app/base/utils/redisClient.js
View file @
9cf1636a
...
@@ -248,7 +248,8 @@ module.exports = RedisClient;
...
@@ -248,7 +248,8 @@ module.exports = RedisClient;
// client.sismember("h","ok").then(function(r){
// client.sismember("h","ok").then(function(r){
// console.log(r);
// console.log(r);
// });
// });
// console.dir(client);ti.exec( callback )回调函数参数err:返回null或者Array,出错则返回对应命令序列链中发生错误的错误信息,这个数组中最后一个元素是源自exec本身的一个EXECABORT类型的错误
// console.dir(client);ti.exec( callback )
//回调函数参数err:返回null或者Array,出错则返回对应命令序列链中发生错误的错误信息,这个数组中最后一个元素是源自exec本身的一个EXECABORT类型的错误
// r.set("hello","oooo").then(function(result){
// r.set("hello","oooo").then(function(result){
// console.log(result);
// console.log(result);
// });
// });
...
...
icp-deliver/app/base/utils/restClient.js
View file @
9cf1636a
...
@@ -10,52 +10,46 @@ class RestClient {
...
@@ -10,52 +10,46 @@ class RestClient {
this
.
cmdDownLoadFilePattern
=
'curl -G -o {fileName} {url}'
;
this
.
cmdDownLoadFilePattern
=
'curl -G -o {fileName} {url}'
;
this
.
cmdPostPattern2
=
'curl -k -H
\'
Content-type: application/x-www-form-urlencoded
\'
-d
\'
{data}
\'
{url}'
;
this
.
cmdPostPattern2
=
'curl -k -H
\'
Content-type: application/x-www-form-urlencoded
\'
-d
\'
{data}
\'
{url}'
;
this
.
cmdPostPatternWithAK
=
'curl -k -H
\'
Content-type: application/json
\'
-H
\'
AccessKey:{ak}
\'
-d
\'
{data}
\'
{url}'
;
this
.
cmdPostPatternWithAK
=
'curl -k -H
\'
Content-type: application/json
\'
-H
\'
AccessKey:{ak}
\'
-d
\'
{data}
\'
{url}'
;
// 云帐户
// this.cmdPostPattern3="curl -k -H 'Content-type: application/x-www-form-urlencoded' -H 'dealer-id:"+settings.apiconfig.yunzhanghuDealer_id()+"' -H 'request-id:"+parseInt(Date.now() / 1000)+"_gsb"+"' -d '{data}' {url}";
// this.cmdGetPattern3 = "curl {-G} -k {url} --header 'dealer-id:"+settings.apiconfig.yunzhanghuDealer_id()+"'";
// e签宝
// this.cmdPostPattern4="curl -k -H 'Content-type: application/json' -H 'X-Tsign-Open-App-Id:"+settings.apiconfig.eSignBaoAppId()+"' -H 'X-Tsign-Open-App-Secret:"+settings.apiconfig.eSignBaoAppKey()+"' -d '{data}' {url}";
// form-data形式post data参数类型 md5=2&data=1
// form-data形式post data参数类型 md5=2&data=1
this
.
cmdPostPattern5
=
'curl -k --data
\'
{data}
\'
{url}'
;
this
.
cmdPostPattern5
=
'curl -k --data
\'
{data}
\'
{url}'
;
}
}
FetchGetCmd
(
subData
,
url
)
{
FetchGetCmd
(
subData
,
url
)
{
const
cmd
=
this
.
cmdGetPattern
.
replace
(
/
\{\-
G
\}
/g
,
'-G'
).
replace
(
/
\{
data
\}
/g
,
subData
)
const
cmd
=
this
.
cmdGetPattern
.
replace
(
/
\{\-
G
\}
/g
,
'-G'
).
replace
(
/
\{
data
\}
/g
,
subData
)
.
replace
(
/
\{
url
\}
/g
,
url
);
.
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
return
cmd
;
}
}
FetchPostCmd
(
subData
,
url
)
{
FetchPostCmd
(
subData
,
url
)
{
const
data
=
JSON
.
stringify
(
subData
);
const
data
=
JSON
.
stringify
(
subData
);
const
cmd
=
this
.
cmdPostPattern
.
replace
(
const
cmd
=
this
.
cmdPostPattern
.
replace
(
/
\{
data
\}
/g
,
/
\{
data
\}
/g
,
data
,
data
,
).
replace
(
/
\{
url
\}
/g
,
url
);
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
return
cmd
;
}
}
FetchPostCmdWithAK
(
subData
,
url
,
acck
)
{
FetchPostCmdWithAK
(
subData
,
url
,
acck
)
{
const
data
=
JSON
.
stringify
(
subData
);
const
data
=
JSON
.
stringify
(
subData
);
const
cmd
=
this
.
cmdPostPatternWithAK
.
replace
(
const
cmd
=
this
.
cmdPostPatternWithAK
.
replace
(
/
\{
data
\}
/g
,
/
\{
data
\}
/g
,
data
,
data
,
).
replace
(
/
\{
url
\}
/g
,
url
)
).
replace
(
/
\{
url
\}
/g
,
url
)
.
replace
(
/
\{
ak
\}
/g
,
acck
);
.
replace
(
/
\{
ak
\}
/g
,
acck
);
return
cmd
;
return
cmd
;
}
}
FetchPostCmd2
(
subData
,
url
)
{
FetchPostCmd2
(
subData
,
url
)
{
const
data
=
subData
;
const
data
=
subData
;
const
cmd
=
this
.
cmdPostPattern2
.
replace
(
const
cmd
=
this
.
cmdPostPattern2
.
replace
(
/
\{
data
\}
/g
,
/
\{
data
\}
/g
,
data
,
data
,
).
replace
(
/
\{
url
\}
/g
,
url
);
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
return
cmd
;
}
}
FetchPostCmd3
(
subData
,
url
)
{
FetchPostCmd3
(
subData
,
url
)
{
const
data
=
subData
;
const
data
=
subData
;
const
cmd
=
this
.
cmdPostPattern3
.
replace
(
const
cmd
=
this
.
cmdPostPattern3
.
replace
(
/
\{
data
\}
/g
,
/
\{
data
\}
/g
,
data
,
data
,
).
replace
(
/
\{
url
\}
/g
,
url
);
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
return
cmd
;
}
}
FetchGetCmd3
(
url
)
{
FetchGetCmd3
(
url
)
{
const
cmd
=
this
.
cmdGetPattern3
.
replace
(
/
\{\-
G
\}
/g
,
'-G'
).
replace
(
/
\{
url
\}
/g
,
url
);
const
cmd
=
this
.
cmdGetPattern3
.
replace
(
/
\{\-
G
\}
/g
,
'-G'
).
replace
(
/
\{
url
\}
/g
,
url
);
...
@@ -78,10 +72,10 @@ class RestClient {
...
@@ -78,10 +72,10 @@ class RestClient {
return
cmd
;
return
cmd
;
}
}
FetchDownLoadCmd
(
outfname
,
url
)
{
FetchDownLoadCmd
(
outfname
,
url
)
{
// console.log(this.cmdPattern);
// console.log(this.cmdPattern);
const
cmd
=
this
.
cmdDownLoadFilePattern
.
replace
(
/
\{
fileName
\}
/g
,
outfname
).
replace
(
/
\{
url
\}
/g
,
url
);
const
cmd
=
this
.
cmdDownLoadFilePattern
.
replace
(
/
\{
fileName
\}
/g
,
outfname
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
return
cmd
;
}
}
async
exec
(
cmd
)
{
async
exec
(
cmd
)
{
// await后面表达式返回的promise对象,是then的语法糖,await返回then函数的返回值
// await后面表达式返回的promise对象,是then的语法糖,await返回then函数的返回值
// 异常需要try/catch自己捕获或外部catch捕获
// 异常需要try/catch自己捕获或外部catch捕获
...
...
icp-deliver/dochelp/imghandle.js
View file @
9cf1636a
const
fs
=
require
(
'fs'
);
const
fs
=
require
(
'fs'
);
// function to encode file data to base64 encoded string
// function to encode file data to base64 encoded string
function
base64
_e
ncode
(
file
)
{
function
base64
E
ncode
(
file
)
{
// read binary data
// read binary data
const
bitmap
=
fs
.
readFileSync
(
"./imgs/sp.png"
);
const
bitmap
=
fs
.
readFileSync
(
"./imgs/sp.png"
);
// convert binary data to base64 encoded string
// convert binary data to base64 encoded string
...
@@ -10,8 +10,7 @@ function base64_encode(file) {
...
@@ -10,8 +10,7 @@ function base64_encode(file) {
}
}
// function to create file from base64 encoded string
// function to create file from base64 encoded string
function
base64_decode
(
base64str
,
file
)
{
function
base64Decode
(
base64str
,
file
)
{
// create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded
const
bitmap
=
new
Buffer
(
base64str
,
'base64'
);
const
bitmap
=
new
Buffer
(
base64str
,
'base64'
);
// write buffer to file
// write buffer to file
fs
.
writeFileSync
(
file
,
bitmap
);
fs
.
writeFileSync
(
file
,
bitmap
);
...
@@ -19,7 +18,7 @@ function base64_decode(base64str, file) {
...
@@ -19,7 +18,7 @@ function base64_decode(base64str, file) {
}
}
function
getDataUrl
(
filepath
)
{
function
getDataUrl
(
filepath
)
{
const
str
=
base64
_e
ncode
(
filepath
);
const
str
=
base64
E
ncode
(
filepath
);
let
mime
=
""
;
let
mime
=
""
;
if
(
filepath
.
indexOf
(
"png"
)
>=
0
)
{
if
(
filepath
.
indexOf
(
"png"
)
>=
0
)
{
mime
=
"image/png"
;
mime
=
"image/png"
;
...
@@ -30,9 +29,6 @@ function getDataUrl(filepath) {
...
@@ -30,9 +29,6 @@ function getDataUrl(filepath) {
if
(
filepath
.
indexOf
(
"gif"
)
>=
0
)
{
if
(
filepath
.
indexOf
(
"gif"
)
>=
0
)
{
mime
=
"image/gif"
;
mime
=
"image/gif"
;
}
}
const
dataurl
=
`data:
${
mime
}
;base64,
`
+
str
;
const
dataurl
=
`data:
${
mime
}
;base64,
${
str
}
`
;
return
dataurl
;
return
dataurl
;
}
}
\ No newline at end of file
const
str
=
getDataUrl
(
"./imgs/sp.png"
);
console
.
log
(
str
);
\ No newline at end of file
icp-deliver/main.js
View file @
9cf1636a
...
@@ -29,6 +29,6 @@ environment(app);//初始化环境
...
@@ -29,6 +29,6 @@ environment(app);//初始化环境
const
server
=
http
.
createServer
(
app
);
const
server
=
http
.
createServer
(
app
);
//const socketServer = new SocketServer(server);
//const socketServer = new SocketServer(server);
server
.
listen
(
setttings
.
port
,
function
()
{
server
.
listen
(
setttings
.
port
,
function
()
{
console
.
log
(
'Express server listening on port '
+
app
.
get
(
'port'
)
);
console
.
log
(
`Express server listening on port
${
app
.
get
(
'port'
)}
`
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment