From e624ffb08791e22c78ec1e95efc68212c7957495 Mon Sep 17 00:00:00 2001 From: mtvpls-turso Date: Sat, 11 Jul 2026 18:15:46 +0000 Subject: [PATCH] fix: add turso storage type to data migration import/export The data migration import/export API was missing 'turso' as a storage type check. Without this, Turso storage fell into the Redis 'else' branch, which tries to use hSet/withRetry methods that don't exist on the D1Storage adapter (used by Turso), causing user data import to fail silently. - Import route: added 'turso' alongside 'd1' to use createUserWithHashedPassword method - Export route: added 'turso' alongside 'd1' to use getUserPasswordHash method --- src/app/api/admin/data_migration/export/route.ts | 4 ++-- src/app/api/admin/data_migration/import/route.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/api/admin/data_migration/export/route.ts b/src/app/api/admin/data_migration/export/route.ts index 7ce6b5b..dd3bc48 100644 --- a/src/app/api/admin/data_migration/export/route.ts +++ b/src/app/api/admin/data_migration/export/route.ts @@ -249,8 +249,8 @@ async function getUserPasswordV2(username: string): Promise { return null; } - // D1 存储:使用 getUserPasswordHash 方法 - if (storageType === 'd1') { + // D1/Turso 存储:使用 getUserPasswordHash 方法 + if (storageType === 'd1' || storageType === 'turso') { if (typeof storage.getUserPasswordHash === 'function') { return await storage.getUserPasswordHash(username); } diff --git a/src/app/api/admin/data_migration/import/route.ts b/src/app/api/admin/data_migration/import/route.ts index d368e63..34ca9e1 100644 --- a/src/app/api/admin/data_migration/import/route.ts +++ b/src/app/api/admin/data_migration/import/route.ts @@ -180,8 +180,8 @@ export async function POST(req: NextRequest) { const createdAt = userV2?.created_at || Date.now(); // 根据存储类型使用不同的导入方法 - if (storageType === 'd1') { - // D1 存储:使用 createUserWithHashedPassword 方法 + if (storageType === 'd1' || storageType === 'turso') { + // D1/Turso 存储:使用 createUserWithHashedPassword 方法 if (typeof storage.createUserWithHashedPassword === 'function') { await storage.createUserWithHashedPassword( username, @@ -193,9 +193,9 @@ export async function POST(req: NextRequest) { userV2?.enabledApis, userV2?.banned ); - console.log(`用户 ${username} 导入成功 (D1)`); + console.log(`用户 ${username} 导入成功 (${storageType})`); } else { - console.error(`D1 storage 缺少 createUserWithHashedPassword 方法`); + console.error(`${storageType} storage 缺少 createUserWithHashedPassword 方法`); return false; } } else if (storageType === 'postgres') {