mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-01-31 09:03:19 +08:00
Opt:优化大文件上传稳定性
This commit is contained in:
@@ -7,6 +7,7 @@ import { getDatabase } from '../utils/databaseAdapter.js';
|
||||
// 初始化分块上传
|
||||
export async function initializeChunkedUpload(context) {
|
||||
const { request, env, url } = context;
|
||||
const db = getDatabase(env);
|
||||
|
||||
try {
|
||||
// 解析表单数据
|
||||
@@ -47,7 +48,6 @@ export async function initializeChunkedUpload(context) {
|
||||
};
|
||||
|
||||
// 保存会话信息
|
||||
const db = getDatabase(env);
|
||||
const sessionKey = `upload_session_${uploadId}`;
|
||||
await db.put(sessionKey, JSON.stringify(sessionInfo), {
|
||||
expirationTtl: 3600 // 1小时过期
|
||||
@@ -76,6 +76,7 @@ export async function initializeChunkedUpload(context) {
|
||||
// 处理客户端分块上传
|
||||
export async function handleChunkUpload(context) {
|
||||
const { env, request, url, waitUntil } = context;
|
||||
const db = getDatabase(env);
|
||||
|
||||
// 解析表单数据
|
||||
const formdata = await request.formData();
|
||||
@@ -93,7 +94,6 @@ export async function handleChunkUpload(context) {
|
||||
return createResponse('Error: Missing chunk upload parameters', { status: 400 });
|
||||
}
|
||||
|
||||
const db = getDatabase(env);
|
||||
// 验证上传会话
|
||||
const sessionKey = `upload_session_${uploadId}`;
|
||||
const sessionData = await db.get(sessionKey);
|
||||
|
||||
@@ -39,16 +39,19 @@ class KVAdapter {
|
||||
return await this.kv.put(key, value, options);
|
||||
}
|
||||
|
||||
async get(key) {
|
||||
return await this.kv.get(key);
|
||||
async get(key, options) {
|
||||
options = options || {};
|
||||
return await this.kv.get(key, options);
|
||||
}
|
||||
|
||||
async getWithMetadata(key) {
|
||||
return await this.kv.getWithMetadata(key);
|
||||
async getWithMetadata(key, options) {
|
||||
options = options || {};
|
||||
return await this.kv.getWithMetadata(key, options);
|
||||
}
|
||||
|
||||
async delete(key) {
|
||||
return await this.kv.delete(key);
|
||||
async delete(key, options) {
|
||||
options = options || {};
|
||||
return await this.kv.delete(key, options);
|
||||
}
|
||||
|
||||
async list(options) {
|
||||
@@ -61,53 +64,53 @@ class KVAdapter {
|
||||
return await this.put(fileId, value, options);
|
||||
}
|
||||
|
||||
async getFile(fileId) {
|
||||
const result = await this.getWithMetadata(fileId);
|
||||
async getFile(fileId, options) {
|
||||
const result = await this.getWithMetadata(fileId, options);
|
||||
return result;
|
||||
}
|
||||
|
||||
async getFileWithMetadata(fileId) {
|
||||
return await this.getWithMetadata(fileId);
|
||||
async getFileWithMetadata(fileId, options) {
|
||||
return await this.getWithMetadata(fileId, options);
|
||||
}
|
||||
|
||||
async deleteFile(fileId) {
|
||||
return await this.delete(fileId);
|
||||
async deleteFile(fileId, options) {
|
||||
return await this.delete(fileId, options);
|
||||
}
|
||||
|
||||
async listFiles(options) {
|
||||
return await this.list(options);
|
||||
}
|
||||
|
||||
async putSetting(key, value) {
|
||||
return await this.put(key, value);
|
||||
async putSetting(key, value, options) {
|
||||
return await this.put(key, value, options);
|
||||
}
|
||||
|
||||
async getSetting(key) {
|
||||
return await this.get(key);
|
||||
async getSetting(key, options) {
|
||||
return await this.get(key, options);
|
||||
}
|
||||
|
||||
async deleteSetting(key) {
|
||||
return await this.delete(key);
|
||||
async deleteSetting(key, options) {
|
||||
return await this.delete(key, options);
|
||||
}
|
||||
|
||||
async listSettings(options) {
|
||||
return await this.list(options);
|
||||
}
|
||||
|
||||
async putIndexOperation(operationId, operation) {
|
||||
async putIndexOperation(operationId, operation, options) {
|
||||
const key = 'manage@index@operation_' + operationId;
|
||||
return await this.put(key, JSON.stringify(operation));
|
||||
return await this.put(key, JSON.stringify(operation), options);
|
||||
}
|
||||
|
||||
async getIndexOperation(operationId) {
|
||||
async getIndexOperation(operationId, options) {
|
||||
const key = 'manage@index@operation_' + operationId;
|
||||
const result = await this.get(key);
|
||||
const result = await this.get(key, options);
|
||||
return result ? JSON.parse(result) : null;
|
||||
}
|
||||
|
||||
async deleteIndexOperation(operationId) {
|
||||
async deleteIndexOperation(operationId, options) {
|
||||
const key = 'manage@index@operation_' + operationId;
|
||||
return await this.delete(key);
|
||||
return await this.delete(key, options);
|
||||
}
|
||||
|
||||
async listIndexOperations(options) {
|
||||
|
||||
Reference in New Issue
Block a user