test/custom-admin-ui #3
@@ -10,6 +10,10 @@ from core.settings import settings
|
||||
|
||||
|
||||
async def admin_required(authorization: Union[str, None] = Header(default=None), request: Request = None):
|
||||
if authorization != settings.admin_token:
|
||||
raise HTTPException(status_code=401, detail='未授权或授权校验失败')
|
||||
return True
|
||||
is_admin = authorization == settings.admin_token
|
||||
if request.url.path.startswith('/share/'):
|
||||
if not settings.openUpload and not is_admin:
|
||||
raise HTTPException(status_code=403, detail='本站未开启游客上传,如需上传请先登录后台')
|
||||
else:
|
||||
if not is_admin:
|
||||
raise HTTPException(status_code=401, detail='未授权或授权校验失败')
|
||||
|
||||
+7
-3
@@ -2,13 +2,15 @@
|
||||
# @Author : Lan
|
||||
# @File : views.py
|
||||
# @Software: PyCharm
|
||||
from fastapi import APIRouter, Form, UploadFile, File, Depends
|
||||
from fastapi import APIRouter, Form, UploadFile, File, Depends, HTTPException
|
||||
from starlette.responses import FileResponse
|
||||
|
||||
from apps.admin.depends import admin_required
|
||||
from apps.base.models import FileCodes
|
||||
from apps.base.pydantics import SelectFileModel
|
||||
from apps.base.utils import get_expire_info, get_file_path_name, error_ip_limit
|
||||
from core.response import APIResponse
|
||||
from core.settings import settings
|
||||
from core.storage import file_storage
|
||||
|
||||
share_api = APIRouter(
|
||||
@@ -17,7 +19,7 @@ share_api = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
@share_api.post('/text/')
|
||||
@share_api.post('/text/', dependencies=[Depends(admin_required)])
|
||||
async def share_text(text: str = Form(...), expire_value: int = Form(default=1, gt=0), expire_style: str = Form(default='day')):
|
||||
expired_at, expired_count, used_count, code = await get_expire_info(expire_value, expire_style)
|
||||
await FileCodes.create(
|
||||
@@ -34,8 +36,10 @@ async def share_text(text: str = Form(...), expire_value: int = Form(default=1,
|
||||
})
|
||||
|
||||
|
||||
@share_api.post('/file/')
|
||||
@share_api.post('/file/', dependencies=[Depends(admin_required)])
|
||||
async def share_file(expire_value: int = Form(default=1, gt=0), expire_style: str = Form(default='day'), file: UploadFile = File(...)):
|
||||
if file.size > settings.uploadSize:
|
||||
raise HTTPException(status_code=403, detail=f'文件大小超过限制,最大为{settings.uploadSize}字节')
|
||||
expired_at, expired_count, used_count, code = await get_expire_info(expire_value, expire_style)
|
||||
path, suffix, prefix, uuid_file_name, save_path = await get_file_path_name(file)
|
||||
await file_storage.save_file(file, save_path)
|
||||
|
||||
@@ -90,7 +90,7 @@ const showTextDetailVisible = ref(false);
|
||||
</div>
|
||||
</template>
|
||||
<div style="width: 200px;">
|
||||
<el-progress v-if="value.status!='success'" striped :percentage="value.percentage" :text-inside="true"
|
||||
<el-progress v-if="value.status!='success' && value.status!='fail'" striped :percentage="value.percentage" :text-inside="true"
|
||||
:stroke-width="20"></el-progress>
|
||||
<div style="display: flex;justify-content: space-between">
|
||||
<qrcode-vue :value="value.text" :size="100"></qrcode-vue>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { request } from "@/utils/request";
|
||||
import { useFileDataStore } from "@/stores/fileData";
|
||||
import { useFileBoxStore } from "@/stores/fileBox";
|
||||
import { ElMessage } from "element-plus";
|
||||
const fileBoxStore = useFileBoxStore();
|
||||
const fileStore = useFileDataStore();
|
||||
const props = defineProps({
|
||||
@@ -63,11 +64,11 @@ const handleHttpRequest = (options: any) => {
|
||||
fileStore.save();
|
||||
}
|
||||
});
|
||||
}).catch((err: any) => {
|
||||
}).catch(() => {
|
||||
fileStore.shareData.forEach((file: any) => {
|
||||
if (file.uid === options.file.uid) {
|
||||
file.status = 'fail';
|
||||
file.text = err.message;
|
||||
file.code = '上传失败';
|
||||
fileStore.save();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -106,7 +106,6 @@ const refreshData = ()=>{
|
||||
}
|
||||
refreshData();
|
||||
const submitSave = () => {
|
||||
|
||||
request({
|
||||
url: '/admin/config/update',
|
||||
method: 'patch',
|
||||
|
||||
Reference in New Issue
Block a user