代码优化

This commit is contained in:
MarSeventh
2025-12-09 15:15:20 +08:00
parent 934a9d0cfa
commit f6ce8342ab
2 changed files with 7 additions and 15 deletions

View File

@@ -78,11 +78,10 @@ export async function handleChunkMerge(context) {
// 开始合并处理 // 开始合并处理
async function startMerge(context, uploadId, totalChunks, originalFileName, originalFileType, uploadChannel) { async function startMerge(context, uploadId, totalChunks, originalFileName, originalFileType, uploadChannel) {
const { env, url, waitUntil } = context; const { env } = context;
const db = getDatabase(env);
try { try {
// 创建合并任务状态记录 // 合并任务状态输出
const mergeStatus = { const mergeStatus = {
uploadId, uploadId,
status: 'processing', status: 'processing',
@@ -94,15 +93,10 @@ async function startMerge(context, uploadId, totalChunks, originalFileName, orig
createdAt: Date.now(), createdAt: Date.now(),
message: 'Starting merge process...' message: 'Starting merge process...'
}; };
console.log(`Merge status: ${JSON.stringify(mergeStatus)}`);
// 存储合并状态
const statusKey = `merge_status_${uploadId}`;
await db.put(statusKey, JSON.stringify(mergeStatus), {
expirationTtl: 3600 // 1小时过期
});
// 同步执行合并 // 同步执行合并
const result = await handleChannelBasedMerge(context, uploadId, totalChunks, originalFileName, originalFileType, uploadChannel, statusKey); const result = await handleChannelBasedMerge(context, uploadId, totalChunks, originalFileName, originalFileType, uploadChannel);
if (result.success) { if (result.success) {
// 清理临时分块数据 // 清理临时分块数据
@@ -136,9 +130,8 @@ async function startMerge(context, uploadId, totalChunks, originalFileName, orig
} }
// 基于渠道的合并处理 // 基于渠道的合并处理
async function handleChannelBasedMerge(context, uploadId, totalChunks, originalFileName, originalFileType, uploadChannel, statusKey = null) { async function handleChannelBasedMerge(context, uploadId, totalChunks, originalFileName, originalFileType, uploadChannel) {
const { request, env, url, waitUntil } = context; const { request, env, url } = context;
const db = getDatabase(env);
try { try {
// 获得上传IP // 获得上传IP

View File

@@ -997,8 +997,7 @@ export async function forceCleanupUpload(context, uploadId, totalChunks) {
// 清理相关的键 // 清理相关的键
const keysToCleanup = [ const keysToCleanup = [
`upload_session_${uploadId}`, `upload_session_${uploadId}`,
`multipart_${uploadId}`, `multipart_${uploadId}`
`merge_status_${uploadId}`
]; ];
keysToCleanup.forEach(key => { keysToCleanup.forEach(key => {