twikoo-func 1.5.9 → 1.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +7 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -357,6 +357,7 @@ function toCommentDto (comment, uid, replies = [], comments = []) {
|
|
|
357
357
|
console.log('bowser 错误:', e)
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
|
+
const showRegion = !!config.SHOW_REGION && config.SHOW_REGION !== 'false'
|
|
360
361
|
return {
|
|
361
362
|
id: comment._id,
|
|
362
363
|
nick: comment.nick,
|
|
@@ -366,7 +367,7 @@ function toCommentDto (comment, uid, replies = [], comments = []) {
|
|
|
366
367
|
comment: comment.comment,
|
|
367
368
|
os: displayOs,
|
|
368
369
|
browser: displayBrowser,
|
|
369
|
-
ipRegion:
|
|
370
|
+
ipRegion: showRegion ? getIpRegion({ ip: comment.ip }) : '',
|
|
370
371
|
master: comment.master,
|
|
371
372
|
like: comment.like ? comment.like.length : 0,
|
|
372
373
|
liked: comment.like ? comment.like.findIndex((item) => item === uid) > -1 : false,
|
|
@@ -1668,11 +1669,13 @@ function getIpRegion ({ ip, detail = false }) {
|
|
|
1668
1669
|
if (!ip) return ''
|
|
1669
1670
|
try {
|
|
1670
1671
|
const { region } = ipRegionSearcher.btreeSearchSync(ip)
|
|
1671
|
-
const [,, province, city, isp] = region.split('|')
|
|
1672
|
+
const [country,, province, city, isp] = region.split('|')
|
|
1673
|
+
// 有省显示省,没有省显示国家
|
|
1674
|
+
const area = province.trim() ? province : country
|
|
1672
1675
|
if (detail) {
|
|
1673
|
-
return
|
|
1676
|
+
return area === city ? [city, isp].join(' ') : [area, city, isp].join(' ')
|
|
1674
1677
|
} else {
|
|
1675
|
-
return
|
|
1678
|
+
return area
|
|
1676
1679
|
}
|
|
1677
1680
|
} catch (e) {
|
|
1678
1681
|
console.error('IP 属地查询失败:', e)
|
package/package.json
CHANGED