改进:文件访问添加鉴权

This commit is contained in:
jmal 2021-02-18 18:05:34 +08:00
parent 85df20b775
commit 782b1d6bcb
8 changed files with 17 additions and 18 deletions

View File

@ -93,7 +93,7 @@
if(selectImg.id){ if(selectImg.id){
this.loading = true this.loading = true
this.cropper.reset() this.cropper.reset()
let url = fileConfig.previewUrl(this.$store.state.user.name, selectImg) + '?o=crop&w=1024' let url = fileConfig.previewUrl(this.$store.state.user.name, selectImg, this.$store.getters.token) + '&o=crop&w=1024'
this.sourceImg = url this.sourceImg = url
this.cropper.replace(url) this.cropper.replace(url)
this.loading = false this.loading = false

View File

@ -2755,7 +2755,7 @@ export default {
fileConfig.packageDownload(fileIds, this.$store.state.user.token) fileConfig.packageDownload(fileIds, this.$store.state.user.token)
return return
} }
fileConfig.download(this.$store.state.user.name, this.rowContextData) fileConfig.download(this.$store.state.user.name, this.rowContextData, this.$store.getters.token)
} else { } else {
this.$message({ this.$message({
message: '所选文件为空', message: '所选文件为空',
@ -2980,7 +2980,7 @@ export default {
if (window.location.port.length > 0) { if (window.location.port.length > 0) {
host = window.location.host.substring(0, window.location.host.length - window.location.port.length - 1) host = window.location.host.substring(0, window.location.host.length - window.location.port.length - 1)
} }
fileConfig.preview(this.$store.state.user.name, row) fileConfig.preview(this.$store.state.user.name, row, this.$store.getters.token)
return return
} }
if (suffix.compressedFile.includes(row.suffix)) { if (suffix.compressedFile.includes(row.suffix)) {
@ -3007,7 +3007,7 @@ export default {
this.notPreviewDialogVisible = false this.notPreviewDialogVisible = false
}, },
downLaod(file) { downLaod(file) {
fileConfig.download(this.$store.state.user.name, file) fileConfig.download(this.$store.state.user.name, file, this.$store.getters.token)
}, },
} }
} }

View File

@ -124,7 +124,7 @@ export default {
input(value) { input(value) {
}, },
selectedFile(row) { selectedFile(row) {
this.currentValue = window.location.origin + fileConfig.previewUrl(this.$store.state.user.name, row) this.currentValue = window.location.origin + fileConfig.previewUrl(this.$store.state.user.name, row, this.$store.getters.token)
this.change(this.currentValue) this.change(this.currentValue)
}, },
handleBeforeUpload(){ handleBeforeUpload(){

View File

@ -49,7 +49,7 @@ export default {
pic.addEventListener('click', this.onPicClick); pic.addEventListener('click', this.onPicClick);
Bus.$on('onAddAudio',(newFile, audioCoverUrl) => { Bus.$on('onAddAudio',(newFile, audioCoverUrl) => {
this.show = true this.show = true
let url = fileConfig.previewUrl(this.$store.state.user.name, newFile) let url = fileConfig.previewUrl(this.$store.state.user.name, newFile, this.$store.getters.token)
console.log(url) console.log(url)
if(!this.$store.state.user.token){ if(!this.$store.state.user.token){
url = fileConfig.publicPreviewUrl(newFile.id); url = fileConfig.publicPreviewUrl(newFile.id);

View File

@ -89,7 +89,7 @@
this.fileList.forEach((element,index) => { this.fileList.forEach((element,index) => {
if(index < findIndex + 5 && index > findIndex - 5 ) { if(index < findIndex + 5 && index > findIndex - 5 ) {
if(!element.isFolder && element.contentType.startsWith('image')){ if(!element.isFolder && element.contentType.startsWith('image')){
let url = fileConfig.previewUrl(this.$store.state.user.name, element) let url = fileConfig.previewUrl(this.$store.state.user.name, element, this.$store.getters.token)
if(this.shareId){ if(this.shareId){
url = fileConfig.publicPreviewUrl(element.id); url = fileConfig.publicPreviewUrl(element.id);
} }

View File

@ -99,7 +99,7 @@ export default {
watch: { watch: {
status: function(visible){ status: function(visible){
if(visible){ if(visible){
let url = fileConfig.previewUrl(this.$store.state.user.name, this.file) let url = fileConfig.previewUrl(this.$store.state.user.name, this.file, this.$store.getters.token)
if(this.shareId){ if(this.shareId){
url = fileConfig.publicPreviewUrl(this.file.id); url = fileConfig.publicPreviewUrl(this.file.id);
} }

View File

@ -6,27 +6,26 @@ export default {
webDAVUrl: function(username) { webDAVUrl: function(username) {
return window.location.origin + `${this.baseUrl}/webDAV/${username}` return window.location.origin + `${this.baseUrl}/webDAV/${username}`
}, },
previewUrl: function(username, file) { previewUrl: function(username, file, token) {
return `${this.baseUrl}/file/${username}${file.path}${file.name}` return `${this.baseUrl}/file/${username}${file.path}${file.name}?jmal-token=${token}`
}, },
mardownPreviewUrl: function (path){ mardownPreviewUrl: function (path){
return window.location.origin + `${this.baseUrl}${path}` return window.location.origin + `${this.baseUrl}${path}`
}, },
publicPreviewUrl: function(fileIds) { publicPreviewUrl: function(fileId) {
return `${this.baseUrl}/public/preview/${fileIds}` return `${this.baseUrl}/public/preview/${fileId}`
}, },
preview: function(username, file) { preview: function(username, file, token) {
const url = this.previewUrl(username, file) const url = this.previewUrl(username, file, token)
console.log(url)
window.open(url, '_blank') window.open(url, '_blank')
}, },
publicPreview: function(fileIds) { publicPreview: function(fileIds) {
const url = this.publicPreviewUrl(fileIds) const url = this.publicPreviewUrl(fileIds)
window.open(url, '_blank') window.open(url, '_blank')
}, },
download: function(username, file) { download: function(username, file, token) {
fileApi.isAllowDownload().then(() => { fileApi.isAllowDownload().then(() => {
let url = `${this.baseUrl}/file/${username}${file.path}${file.name}?o=download` let url = `${this.baseUrl}/file/${username}${file.path}${file.name}?jmal-token=${token}&o=download`
window.open(url, '_self') window.open(url, '_self')
}) })
}, },

View File

@ -986,7 +986,7 @@
this.$router.push(`/public/articles/article?mark=${row.id}`) this.$router.push(`/public/articles/article?mark=${row.id}`)
}else{ }else{
// 打开文件 // 打开文件
fileConfig.preview(this.$store.state.user.token, row) fileConfig.preview(this.$store.state.user.token, row, this.$store.getters.token)
} }
} }
} }