From 71bcbed46cf0de1700acfcebdced4ed03d11929c Mon Sep 17 00:00:00 2001 From: Lan Date: Wed, 7 Jan 2026 19:08:41 +0800 Subject: [PATCH] fix: https://github.com/vastsa/FileCodeBox/issues/415 --- src/services/index.ts | 71 ++++++++++++++++++++++++++++---------- src/views/SendFileView.vue | 4 ++- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/services/index.ts b/src/services/index.ts index 774f02a..8ed9e4d 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,8 +1,25 @@ // API 服务层 import api from '@/utils/api' import axios from 'axios' -import type { ApiResponse, FileInfo, ConfigState, AdminUser, FileUploadResponse, TextSendResponse, DashboardData, FileListResponse, FileEditForm } from '@/types' -import type { UploadProgress, PresignInitRequest, PresignInitResponse, PresignConfirmRequest, PresignUploadResult, PresignStatusResponse } from '@/types' +import type { + ApiResponse, + FileInfo, + ConfigState, + AdminUser, + FileUploadResponse, + TextSendResponse, + DashboardData, + FileListResponse, + FileEditForm +} from '@/types' +import type { + UploadProgress, + PresignInitRequest, + PresignInitResponse, + PresignConfirmRequest, + PresignUploadResult, + PresignStatusResponse +} from '@/types' // 系统配置服务 export class ConfigService { @@ -30,6 +47,7 @@ export class FileService { headers: { 'Content-Type': 'multipart/form-data' }, + timeout: 0, // 禁用超时限制 onUploadProgress: (progressEvent) => { if (onProgress && progressEvent.total) { const progress: UploadProgress = { @@ -62,19 +80,28 @@ export class FileService { return api.post('/admin/file/delete', { id: fileId }) } - static async getFileList(page = 1, limit = 10): Promise> { + static async getFileList( + page = 1, + limit = 10 + ): Promise< + ApiResponse<{ + files: FileInfo[] + total: number + page: number + limit: number + }> + > { return api.get('/admin/file/list', { params: { page, size: limit } }) } // 文件管理相关方法 - static async getAdminFileList(params: { page: number; size: number; keyword?: string }): Promise> { + static async getAdminFileList(params: { + page: number + size: number + keyword?: string + }): Promise> { return api.get('/admin/file/list', { params }) } @@ -88,7 +115,9 @@ export class FileService { }) } - static async downloadAdminFile(id: number): Promise<{ data: Blob; headers: Record }> { + static async downloadAdminFile( + id: number + ): Promise<{ data: Blob; headers: Record }> { return api.get('/admin/file/download', { params: { id }, responseType: 'blob' @@ -113,14 +142,16 @@ export class AuthService { // 统计服务 export class StatsService { - static async getDashboardStats(): Promise> { + static async getDashboardStats(): Promise< + ApiResponse<{ + totalFiles: number + totalDownloads: number + todayUploads: number + todayDownloads: number + storageUsed: number + recentFiles: FileInfo[] + }> + > { return api.get('/admin/dashboard') } @@ -153,6 +184,7 @@ export class PresignUploadService { headers: { 'Content-Type': 'multipart/form-data' }, + timeout: 0, onUploadProgress: (progressEvent) => { if (onProgress && progressEvent.total) { const progress: UploadProgress = { @@ -203,6 +235,7 @@ export class PresignUploadService { headers: { 'Content-Type': 'application/octet-stream' }, + timeout: 0, onUploadProgress: (progressEvent) => { if (onProgress && progressEvent.total) { const progress: UploadProgress = { @@ -230,4 +263,4 @@ export const services = { presignUpload: PresignUploadService } -export default services \ No newline at end of file +export default services diff --git a/src/views/SendFileView.vue b/src/views/SendFileView.vue index dcc9387..cd265d7 100644 --- a/src/views/SendFileView.vue +++ b/src/views/SendFileView.vue @@ -858,6 +858,7 @@ const handleChunkUpload = async (file: File) => { headers: { 'Content-Type': 'multipart/form-data' }, + timeout: 0, // 禁用超时限制 onUploadProgress: (progressEvent: { loaded: number; total?: number }) => { // 计算已上传块的大小 const uploadedSize = Array.from(uploadedChunks).reduce((acc, idx) => { @@ -912,6 +913,7 @@ const handleDefaultFileUpload = async (file: File) => { headers: { 'Content-Type': 'multipart/form-data' }, + timeout: 0, // 禁用超时限制 onUploadProgress: (progressEvent: { loaded: number; total?: number }) => { const percentCompleted = Math.round((progressEvent.loaded * 100) / (progressEvent.total || 1)) uploadProgress.value = percentCompleted @@ -937,7 +939,7 @@ const handlePresignedUpload = async (file: File) => { uploadProgress.value = progress.percentage } }) - + if (code) { return { code: 200,