✨ feat(upload): 支持后台配置上传分片大小
This commit is contained in:
1 parent
5b78ec6fbc
commit
272741ee49
11 files changed
+64
-5
No files matched your search
@@ -8,6 +8,9 @@
|
||||
:id="inputId"
|
||||
type="number"
|
||||
:value="modelValue"
|
||||
:min="min"
|
||||
:max="max"
|
||||
:step="step"
|
||||
class="min-h-11 w-28 rounded-md border px-4 py-2.5 shadow-sm outline-none transition-all duration-200 focus:border-indigo-500 focus:ring-2 focus:ring-indigo-500"
|
||||
:class="[
|
||||
isDarkMode
|
||||
@@ -24,7 +27,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject } from 'vue'
|
||||
|
||||
const props = defineProps<{ label: string; modelValue: number; suffix: string }>()
|
||||
const props = defineProps<{ label: string; modelValue: number; suffix: string; min?: number; max?: number; step?: number }>()
|
||||
const inputId = computed(() => `setting-number-${props.label.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/gi, '-')}`)
|
||||
const isDarkMode = inject('isDarkMode')
|
||||
const emit = defineEmits<{ 'update:modelValue': [value: number] }>()
|
||||
|
||||
@@ -64,6 +64,7 @@ export function useSendFlow() {
|
||||
const sentRecordActions = createSentRecordActions(notifyCopyResult)
|
||||
const { requestCancel, needsCleanup, retryCleanup, isUploadInterrupted, resetPresignUpload, submitFile, submitText } = useSendSubmit({
|
||||
getMaxFileSize: () => configStore.uploadSizeLimit,
|
||||
getChunkSizeMB: () => config.value.chunkSizeMB,
|
||||
notify: (message, type) => alertStore.showAlert(message, type),
|
||||
translate: t,
|
||||
onProgress: (progress) => {
|
||||
|
||||
@@ -10,6 +10,7 @@ type Translate = (
|
||||
|
||||
type UseSendSubmitOptions = {
|
||||
getMaxFileSize: () => number
|
||||
getChunkSizeMB: () => number
|
||||
notify: (message: string, type: AlertType) => void
|
||||
translate: Translate
|
||||
onProgress: (progress: UploadProgress) => void
|
||||
@@ -51,6 +52,7 @@ export function useSendSubmit(options: UseSendSubmitOptions) {
|
||||
expireValue,
|
||||
expireStyle,
|
||||
cancellation: active,
|
||||
chunkSizeMB: options.getChunkSizeMB(),
|
||||
onHashCalculated: options.onHashCalculated,
|
||||
onFinalizing: options.onFinalizing,
|
||||
onProgress: (progress: UploadProgress) => {
|
||||
|
||||
@@ -161,6 +161,11 @@ export function useSystemConfig() {
|
||||
return Promise.resolve(false)
|
||||
}
|
||||
|
||||
const size = config.value.chunkSizeMB
|
||||
if (!Number.isInteger(size) || size < 1 || size > 100) {
|
||||
alertStore.showAlert('分片大小必须是 1–100 MB 的整数', 'error')
|
||||
return Promise.resolve(false)
|
||||
}
|
||||
return updateConfig(buildSubmitPayload())
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ export const CHUNK_SIZE = 90 * 1024 * 1024
|
||||
|
||||
type ChunkedUploadOptions = {
|
||||
cancellation?: UploadCancellation
|
||||
chunkSizeMB?: number
|
||||
expireValue: number
|
||||
expireStyle: string
|
||||
onFinalizing?: () => void
|
||||
@@ -68,7 +69,7 @@ const runChunkedFile = async (
|
||||
const initResponse = await FileService.initChunkUpload({
|
||||
file_name: file.name,
|
||||
file_size: file.size,
|
||||
chunk_size: Math.min(CHUNK_SIZE, file.size),
|
||||
chunk_size: Math.min((Number.isInteger(options.chunkSizeMB) && options.chunkSizeMB! >= 1 && options.chunkSizeMB! <= 100 ? options.chunkSizeMB! * 1024 * 1024 : CHUNK_SIZE), file.size),
|
||||
file_hash: fileHash
|
||||
})
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ export interface ConfigState {
|
||||
trashRetentionDays: number
|
||||
opacity: number
|
||||
enableChunk: number
|
||||
chunkSizeMB: number
|
||||
s3_access_key_id: string
|
||||
background: string
|
||||
showAdminAddr: number
|
||||
|
||||
@@ -7,6 +7,7 @@ export type PublicConfig = SystemConfig & {
|
||||
openUpload: number
|
||||
max_save_seconds: number
|
||||
enableChunk: number
|
||||
chunkSizeMB: number
|
||||
notify_title?: string
|
||||
notify_content?: string
|
||||
page_explain?: string
|
||||
@@ -22,7 +23,8 @@ export const DEFAULT_PUBLIC_CONFIG: PublicConfig = {
|
||||
expireStyle: ['day'],
|
||||
openUpload: 1,
|
||||
max_save_seconds: 0,
|
||||
enableChunk: 0
|
||||
enableChunk: 0,
|
||||
chunkSizeMB: 90
|
||||
}
|
||||
|
||||
export const DEFAULT_CONFIG_STATE: ConfigState = {
|
||||
@@ -44,6 +46,7 @@ export const DEFAULT_CONFIG_STATE: ConfigState = {
|
||||
trashRetentionDays: 30,
|
||||
opacity: 0.9,
|
||||
enableChunk: DEFAULT_PUBLIC_CONFIG.enableChunk,
|
||||
chunkSizeMB: DEFAULT_PUBLIC_CONFIG.chunkSizeMB,
|
||||
s3_access_key_id: '',
|
||||
background: '',
|
||||
showAdminAddr: 0,
|
||||
@@ -85,6 +88,7 @@ export function toPublicConfig(config: Partial<ConfigState> | null | undefined):
|
||||
openUpload: config.openUpload,
|
||||
max_save_seconds: config.max_save_seconds,
|
||||
enableChunk: config.enableChunk,
|
||||
chunkSizeMB: config.chunkSizeMB ?? DEFAULT_PUBLIC_CONFIG.chunkSizeMB,
|
||||
notify_title: config.notify_title,
|
||||
notify_content: config.notify_content,
|
||||
page_explain: config.page_explain,
|
||||
|
||||
@@ -378,7 +378,7 @@ onMounted(() => {
|
||||
</select>
|
||||
</div>
|
||||
<SettingSwitch
|
||||
v-if="config.file_storage === 'local'"
|
||||
v-if="config.file_storage === 'local' || config.file_storage === 'webdav'"
|
||||
:label="t('manage.settings.chunkUploadNote')"
|
||||
:model-value="config.enableChunk"
|
||||
:enabled-text="t('common.enabled')"
|
||||
@@ -627,6 +627,11 @@ onMounted(() => {
|
||||
</h3>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div class="space-y-2">
|
||||
<SettingNumberInput v-model="config.chunkSizeMB" label="上传分片大小" suffix="MB" :min="1" :max="100" :step="1" />
|
||||
<p class="text-xs leading-5" :class="isDarkMode ? 'text-gray-400' : 'text-gray-500'">1–100 MB,默认 90 MB。保存后用于新上传,已开始的上传保留原分片大小。仅启用分片上传时生效。</p>
|
||||
</div>
|
||||
|
||||
<SettingNumberInput
|
||||
v-model="config.uploadMinute"
|
||||
:label="t('manage.settings.uploadPerMinute')"
|
||||
|
||||
Reference in new issue
Block a user