Skip to content

Commit

Permalink
Doc debian (#44)
Browse files Browse the repository at this point in the history
* update function: domain whitelist and url push
  • Loading branch information
weearc authored Sep 26, 2023
1 parent 2f069d5 commit d0fc7e8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion components/Mirrorlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default {
})
})
this.listData = JSON.parse(JSON.stringify(listData))
console.log(listData)
// console.log(listData)
},
timeConvert(timeStr) {
const splitStr = timeStr.split(" ")
Expand Down
1 change: 1 addition & 0 deletions components/SideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:show-icon="item.showIcon"
:theme="item.theme"
:callback="item.callback"
:action="item.action"
class="site-notice"
/>
</template>
Expand Down
40 changes: 37 additions & 3 deletions components/scroll-notice/warpNotice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,47 @@ export default {
center: { type: Boolean, default: false },
showIcon: { type: Boolean, default: true },
effect: { type: String, default: 'light' },
callback: { type: String, default: undefined }
callback: { type: String, default: undefined },
action: { type: String, default: 'news'}
},
methods: {
isDomainInWhitelist(url, whitelist) {
// 提取URL中的域名部分
const domainRegex = /^https?:\/\/([^/]+)\//;
const matches = url.match(domainRegex);
if (matches && matches.length > 1) {
const domain = matches[1];
// 检查域名是否在白名单中
return whitelist.includes(domain);
}
// 如果无法提取域名,默认为不在白名单中
return false;
},
handleCallback() {
if (this.$props.callback) {
console.log(this.$props.callback)
this.$router.push({name: 'news-page', params: { page: this.$props.callback }});
// console.log(this.$props)
let that = this
const prop = that.$props
if (prop.action) {
let action = prop.action
const whiteList = process.env.whiteListDomain
if (action === 'url') {
// 必须进行校验
if (this.isDomainInWhitelist(prop.callback, whiteList)) {
window.open(prop.callback, '_blank')
} else {
return
}
} else if (action === 'news') {
this.$router.push({name: 'news-page', params: { page: this.$props.callback }})
} else if (action === 'wiki') {
this.$router.push({name: 'wiki', params: { page: prop.callback }})
} else {
this.$router.push({name: 'news-page', params: { page: this.$props.callback }})
}
}
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ export default {
goto: '/hugo-wiki'
}
]
}
},
whiteListDomain: [
'mirrors.cqu.edu.cn'
]
},

// Build Configuration: https://go.nuxtjs.dev/config-build
Expand Down

0 comments on commit d0fc7e8

Please sign in to comment.