mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-04-26 15:15:06 +00:00
代码优化
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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 => {
|
||||||
|
|||||||
Reference in New Issue
Block a user