Skip to content

Commit

Permalink
oss配置校验
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyuanwei committed Feb 27, 2020
1 parent 667f817 commit 825e874
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controller/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ module.exports = app => {

* getTocken () {
console.log('访问ip:', this.ctx.ip)
const valid = this.ctx.helper.tools.ossConfigValid(app.config.oss)
if (!valid) throw this.ctx.getError({ msg: '您未正确配置 oss 服务的相关字段,无法使用对象存储服务' })
var expire_syncpoint = new Date().getTime() + 60 * 1000
var policyToken = {
accessKeyId: app.config.oss.accessKeyId,
Expand Down
4 changes: 4 additions & 0 deletions app/extend/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,8 @@ uBAU3akQpGYd7wLMMY+ND7/Hn8GjDk5qyjwlBKUsG6/bJ4hlzej9xORE5wIDAQAB
}
return format
},
ossConfigValid (config = {}) {
const isInvalid = op => typeof op !== 'string' || op.trim() === '' || /<[^<>]+>/.test(op)
return !(isInvalid(config.accessKeyId) || isInvalid(config.accessKeySecret) || isInvalid(config.host) || isInvalid(config.bucket) || isInvalid(config.region))
}
}
2 changes: 2 additions & 0 deletions app/service/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ module.exports = app => {
}

async import ({id, token}, userId) {
const valid = this.ctx.helper.tools.ossConfigValid(app.config.oss)
if (!valid) throw this.ctx.getError({ msg: '您未正确配置 oss 服务的相关字段,无法使用对象存储服务' })
const that = this
const zipBuffer = await downloadZip(id, token).catch(e => (console.error(e), null))
if (!zipBuffer) return
Expand Down

0 comments on commit 825e874

Please sign in to comment.