feat: 配额优化
This commit is contained in:
@@ -6,6 +6,10 @@
|
||||
import { ref, reactive } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { MaterialService } from '@/api/material'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
// GB转字节常量
|
||||
const GB_TO_BYTES = 1073741824
|
||||
|
||||
/**
|
||||
* 获取视频时长(秒)
|
||||
@@ -140,6 +144,20 @@ export function useUpload() {
|
||||
state.error = null
|
||||
state.progress = 0
|
||||
|
||||
// 存储空间校验
|
||||
const userStore = useUserStore()
|
||||
const fileSizeGB = file.size / GB_TO_BYTES
|
||||
const remainingStorage = userStore.remainingStorage || 0
|
||||
|
||||
if (fileSizeGB > remainingStorage) {
|
||||
const error = new Error(`存储空间不足!需要 ${fileSizeGB.toFixed(2)} GB,剩余 ${remainingStorage.toFixed(2)} GB`)
|
||||
state.uploading = false
|
||||
state.status = 'error'
|
||||
state.error = error.message
|
||||
onError?.(error)
|
||||
throw error
|
||||
}
|
||||
|
||||
// 通知开始
|
||||
onStart?.()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user