Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Plain Diff
Browse Files
Authored by
周少峰
8 years ago
Commit
f1514e4c14ec708af1c1faafdd61bdb72fbc79b9
2 parents
8ec461da
27a9a744
Merge branch 'gray'
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
10 deletions
apps/3party/models/robot-check-service.js
apps/help/models/help-service.js
apps/product/controllers/search.js
apps/product/models/search.js
doraemon/middleware/limiter/index.js
doraemon/middleware/limiter/rules/asynchronous.js
apps/3party/models/robot-check-service.js
View file @
f1514e4
...
...
@@ -16,11 +16,19 @@ const index = co(function* (channel) {
const
removeBlack
=
(
remoteIp
)
=>
{
let
key
=
`
pc
:
limiter
:
$
{
remoteIp
}
`
,
key10m
=
`
pc
:
limiter
:
10
m
:
$
{
remoteIp
}
`
;
key10m
=
`
pc
:
limiter
:
10
m
:
$
{
remoteIp
}
`
,
keyMax
=
`
pc
:
limiter
:
max
:
$
{
remoteIp
}
`
,
key10mMax
=
`
pc
:
limiter
:
10
m
:
max
:
$
{
remoteIp
}
`
,
synchronizeKey
=
`
pc
:
limiter
:
synchronize
:
$
{
remoteIp
}
`
,
spiderKey
=
`
pc
:
limiter
:
spider
:
$
{
remoteIp
}
`
;
return
Promise
.
all
([
cache
.
delAsync
(
key
),
cache
.
delAsync
(
key10m
)
cache
.
delAsync
(
key10m
),
cache
.
delAsync
(
keyMax
),
cache
.
delAsync
(
key10mMax
),
cache
.
delAsync
(
synchronizeKey
),
cache
.
delAsync
(
spiderKey
)
]);
};
...
...
apps/help/models/help-service.js
View file @
f1514e4
...
...
@@ -295,7 +295,7 @@ module.exports = class extends global.yoho.BaseModel {
ht
=
`
$
{
params
.
keywords
}
`
;
}
else
{
nav
=
_this
.
_getNav
(
params
.
id
,
menuData
,
params
.
url
);
ht
=
_
.
last
(
nav
).
name
;
ht
=
_
.
get
(
_
.
last
(
nav
),
'name'
,
''
)
;
}
return
{
...
...
apps/product/controllers/search.js
View file @
f1514e4
...
...
@@ -42,11 +42,14 @@ const index = (req, res, next) => {
return
res
.
render
(
'search/no-result'
,
resData
);
}
Object
.
assign
(
resData
,
{
title
:
`
$
{
queryKey
}
价格
_
图片
_
品牌
_
怎么样
-
YOHO
!
BUY
有货`
,
keywords
:
`
$
{
queryKey
},
$
{
queryKey
}
价格
,
$
{
queryKey
}
图片
,
$
{
queryKey
}
怎么样
,
$
{
queryKey
}
品牌
,
YOHO
!
BUY
有货`
,
description
:
`
YOHO
!
BUY
有货网
yohobuy
.
com
是国内专业的
$
{
queryKey
}
网上潮流购物商城
,
为您找到
$
{
_
.
get
(
resData
,
'search.totalCount'
,
0
)}
条
$
{
queryKey
}
、产品的详细参数
,
实时报价
,
价格行情
,
图片、评价、品牌等信息。买
$
{
queryKey
},
就上
YOHO
!
BUY
有货`
// eslint-disable-line
});
if
(
queryKey
)
{
Object
.
assign
(
resData
,
{
title
:
`
$
{
queryKey
}
价格
_
图片
_
品牌
_
怎么样
-
YOHO
!
BUY
有货`
,
keywords
:
`
$
{
queryKey
},
$
{
queryKey
}
价格
,
$
{
queryKey
}
图片
,
$
{
queryKey
}
怎么样
,
$
{
queryKey
}
品牌
,
YOHO
!
BUY
有货`
,
description
:
`
YOHO
!
BUY
有货网
yohobuy
.
com
是国内专业的
$
{
queryKey
}
网上潮流购物商城
,
为您找到
$
{
_
.
get
(
resData
,
'search.totalCount'
,
0
)}
条
$
{
queryKey
}
、产品的详细参数
,
实时报价
,
价格行情
,
图片、评价、品牌等信息。买
$
{
queryKey
},
就上
YOHO
!
BUY
有货`
// eslint-disable-line
});
}
res
.
render
(
'search/index'
,
resData
);
});
...
...
apps/product/models/search.js
View file @
f1514e4
...
...
@@ -64,7 +64,7 @@ const setSearchData = (result, params, channel) => {
_
.
get
(
finalResult
,
'search.leftContent.sort'
,
{}));
filters
.
checkedConditions
.
conditions
=
_
.
concat
(
filters
.
checkedConditions
.
conditions
,
finalResult
.
search
.
leftContent
.
checked
);
_
.
get
(
finalResult
,
'search.leftContent.checked'
,
[])
);
Object
.
assign
(
finalResult
.
search
,
searchHandler
.
handlePathNavData
({
total
:
result
[
2
].
data
.
total
},
params
,
'search'
,
channel
),
...
...
doraemon/middleware/limiter/index.js
View file @
f1514e4
...
...
@@ -5,6 +5,7 @@ const logger = global.yoho.logger;
const
ip
=
require
(
'./rules/ip-list'
);
const
userAgent
=
require
(
'./rules/useragent'
);
const
qpsLimiter
=
require
(
'./rules/qps-limit'
);
const
asynchronous
=
require
(
'./rules/asynchronous'
);
// const fakerLimiter = require('./rules/faker-limit');
const
captchaPolicy
=
require
(
'./policies/captcha'
);
...
...
@@ -53,7 +54,8 @@ module.exports = (req, res, next) => {
Promise
.
all
([
limiter
(
userAgent
,
captchaPolicy
,
context
),
limiter
(
ip
,
captchaPolicy
,
context
),
limiter
(
qpsLimiter
,
captchaPolicy
,
context
)
limiter
(
qpsLimiter
,
captchaPolicy
,
context
),
limiter
(
asynchronous
,
captchaPolicy
,
context
)
// limiter(fakerLimiter, reporterPolicy, context)
]).
then
((
results
)
=>
{
...
...
doraemon/middleware/limiter/rules/asynchronous.js
0 → 100644
View file @
f1514e4
'use strict'
;
const
cache
=
global
.
yoho
.
cache
.
master
;
const
_
=
require
(
'lodash'
);
const
logger
=
global
.
yoho
.
logger
;
const
ASYNCHRONOUSPAGES
=
{
'/product/index/isFavoriteShop'
:
1
,
'/common/suggestfeedback'
:
1
,
'/product/detail/hotarea'
:
1
,
'/common/getbanner'
:
1
,
'/passport/cert/headerTip'
:
1
};
function
isNormalSpider
(
userAgent
)
{
let
normalReg
=
/
(
spider
)
|
(
bot.html
)
/i
;
if
(
normalReg
.
test
(
userAgent
))
{
return
true
;
}
else
{
return
false
;
}
}
module
.
exports
=
(
limiter
,
policy
)
=>
{
const
ua
=
limiter
.
req
.
header
(
'User-Agent'
);
const
synchronizeKey
=
`
pc
:
limiter
:
synchronize
:
$
{
limiter
.
remoteIp
}
`
;
// 同步
const
asynchronousKey
=
`
pc
:
limiter
:
asynchronous
:
$
{
limiter
.
remoteIp
}
`
;
// 异步
const
spiderKey
=
`
pc
:
limiter
:
spider
:
$
{
limiter
.
remoteIp
}
`
;
// 异步
// 正常蜘蛛直接过
if
(
isNormalSpider
(
ua
))
{
return
Promise
.
resolve
(
true
);
}
const
req
=
limiter
.
req
,
res
=
limiter
.
res
;
res
.
on
(
'render'
,
function
()
{
cache
.
incrAsync
(
synchronizeKey
,
1
).
catch
(
e
=>
console
.
log
(
e
));
// eslint-disable-line
});
return
cache
.
getMultiAsync
([
synchronizeKey
,
asynchronousKey
,
spiderKey
]).
then
((
results
)
=>
{
logger
.
debug
(
results
);
if
(
results
[
spiderKey
])
{
return
Promise
.
resolve
(
policy
);
}
// 默认数据设置
if
(
!
results
[
synchronizeKey
]
&&
!
_
.
isNumber
(
results
[
synchronizeKey
]))
{
cache
.
setAsync
(
synchronizeKey
,
1
,
600
);
}
// 默认数据设置
if
(
ASYNCHRONOUSPAGES
[
req
.
path
]
>
0
)
{
cache
.
setAsync
(
asynchronousKey
,
1
,
600
);
cache
.
setAsync
(
synchronizeKey
,
1
,
600
);
}
if
(
results
[
synchronizeKey
]
>
10
&&
!
results
[
asynchronousKey
])
{
cache
.
setAsync
(
spiderKey
,
1
,
60
*
60
*
24
);
return
Promise
.
resolve
(
policy
);
}
return
Promise
.
resolve
(
true
);
});
};
...
...
Please
register
or
login
to post a comment