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
This commit is contained in:
@@ -249,8 +249,8 @@ async function getUserPasswordV2(username: string): Promise<string | null> {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user