add:上传前进行检测
This commit is contained in:
@@ -41,8 +41,8 @@ index_html = open('templates/index.html', 'r', encoding='utf-8').read() \
|
|||||||
.replace('{{title}}', settings.TITLE) \
|
.replace('{{title}}', settings.TITLE) \
|
||||||
.replace('{{description}}', settings.DESCRIPTION) \
|
.replace('{{description}}', settings.DESCRIPTION) \
|
||||||
.replace('{{keywords}}', settings.KEYWORDS) \
|
.replace('{{keywords}}', settings.KEYWORDS) \
|
||||||
.replace("'{{fileSizeLimit}}'", str(settings.FILE_SIZE_LIMIT))
|
.replace("'{{fileSizeLimit}}'", str(settings.FILE_SIZE_LIMIT)) \
|
||||||
# 管理页面
|
# 管理页面
|
||||||
admin_html = open('templates/admin.html', 'r', encoding='utf-8').read() \
|
admin_html = open('templates/admin.html', 'r', encoding='utf-8').read() \
|
||||||
.replace('{{title}}', settings.TITLE) \
|
.replace('{{title}}', settings.TITLE) \
|
||||||
.replace('{{description}}', settings.DESCRIPTION) \
|
.replace('{{description}}', settings.DESCRIPTION) \
|
||||||
@@ -107,7 +107,7 @@ async def index():
|
|||||||
|
|
||||||
|
|
||||||
@app.get('/banner')
|
@app.get('/banner')
|
||||||
async def banner(s: AsyncSession = Depends(get_session)):
|
async def banner(request: Request, s: AsyncSession = Depends(get_session)):
|
||||||
# 数据库查询config
|
# 数据库查询config
|
||||||
config = (await s.execute(select(Values).filter(Values.key == 'config'))).scalar_one_or_none()
|
config = (await s.execute(select(Values).filter(Values.key == 'config'))).scalar_one_or_none()
|
||||||
# 如果存在config,就返回config的value
|
# 如果存在config,就返回config的value
|
||||||
@@ -119,6 +119,7 @@ async def banner(s: AsyncSession = Depends(get_session)):
|
|||||||
# 如果不存在config,就返回默认的banner
|
# 如果不存在config,就返回默认的banner
|
||||||
return {
|
return {
|
||||||
'detail': 'banner',
|
'detail': 'banner',
|
||||||
|
'enable': request.headers.get('pwd', '') == settings.ADMIN_PASSWORD,
|
||||||
'data': [{
|
'data': [{
|
||||||
'text': 'FileCodeBox',
|
'text': 'FileCodeBox',
|
||||||
'url': 'https://github.com/vastsa/FileCodeBox',
|
'url': 'https://github.com/vastsa/FileCodeBox',
|
||||||
|
|||||||
+37
-19
@@ -271,6 +271,7 @@
|
|||||||
fileSizeLimit: '{{fileSizeLimit}}',
|
fileSizeLimit: '{{fileSizeLimit}}',
|
||||||
pwd: localStorage.getItem('pwd') || '',
|
pwd: localStorage.getItem('pwd') || '',
|
||||||
banners: [],
|
banners: [],
|
||||||
|
enableUpload: false,
|
||||||
uploadData: {
|
uploadData: {
|
||||||
style: '2',
|
style: '2',
|
||||||
type: '1',
|
type: '1',
|
||||||
@@ -313,7 +314,12 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 获取Banner
|
// 获取Banner
|
||||||
axios.get('/banner').then(res => {
|
axios.get('/banner', {
|
||||||
|
headers: {
|
||||||
|
pwd: localStorage.getItem('pwd')
|
||||||
|
}
|
||||||
|
}).then(res => {
|
||||||
|
this.enableUpload = res.data.enable
|
||||||
this.banners = res.data.data
|
this.banners = res.data.data
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -385,6 +391,22 @@
|
|||||||
changeInput: function (value) {
|
changeInput: function (value) {
|
||||||
this.code = value;
|
this.code = value;
|
||||||
},
|
},
|
||||||
|
checkFile: function (file) {
|
||||||
|
if (!this.enable) {
|
||||||
|
this.$message({
|
||||||
|
message: '上传功能已关闭',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (file.size > this.fileSizeLimit) {
|
||||||
|
this.$message({
|
||||||
|
message: `文件大小不能超过${this.fileSizeLimit/1024/1024}MB`,
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
toUploadData: function () {
|
toUploadData: function () {
|
||||||
if (this.uploadData.text === '' && this.uploadData.file === null) {
|
if (this.uploadData.text === '' && this.uploadData.file === null) {
|
||||||
this.$message({
|
this.$message({
|
||||||
@@ -392,17 +414,19 @@
|
|||||||
type: 'error'
|
type: 'error'
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.http('post', '/share', this.uploadData, {
|
if (this.checkFile(this.uploadData.file)) {
|
||||||
headers: {
|
this.http('post', '/share', this.uploadData, {
|
||||||
'Content-Type': 'multipart/form-data',
|
headers: {
|
||||||
'pwd': this.pwd
|
'Content-Type': 'multipart/form-data',
|
||||||
}
|
'pwd': this.pwd
|
||||||
}).then(res => {
|
}
|
||||||
this.jiFiles.unshift(res.data);
|
}).then(res => {
|
||||||
this.jiDrawer = true;
|
this.jiFiles.unshift(res.data);
|
||||||
this.uploadData.text = '';
|
this.jiDrawer = true;
|
||||||
this.uploadData.file = null;
|
this.uploadData.text = '';
|
||||||
});
|
this.uploadData.file = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
successUpload(response, file, fileList) {
|
successUpload(response, file, fileList) {
|
||||||
@@ -420,13 +444,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
beforeUpload: function (file) {
|
beforeUpload: function (file) {
|
||||||
if (file.size > this.fileSizeLimit) {
|
return this.checkFile(file);
|
||||||
this.$message({
|
|
||||||
message: `文件大小不能超过${this.fileSizeLimit/1024/1024}MB`,
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user