feat: reorder key assignment logic in handleSetKeys for improved readability

This commit is contained in:
shuaiplus
2026-03-05 01:18:23 +08:00
parent a2654dcde3
commit 12024203be
+4 -3
View File
@@ -308,15 +308,16 @@ export async function handleSetKeys(request: Request, env: Env, userId: string):
return errorResponse('Invalid password', 400); return errorResponse('Invalid password', 400);
} }
if (body.key) user.key = body.key;
if (body.encryptedPrivateKey) user.privateKey = body.encryptedPrivateKey;
if (body.publicKey) user.publicKey = body.publicKey;
if (body.key && !looksLikeEncString(body.key)) { if (body.key && !looksLikeEncString(body.key)) {
return errorResponse('key is not a valid encrypted string', 400); return errorResponse('key is not a valid encrypted string', 400);
} }
if (body.encryptedPrivateKey && !looksLikeEncString(body.encryptedPrivateKey)) { if (body.encryptedPrivateKey && !looksLikeEncString(body.encryptedPrivateKey)) {
return errorResponse('encryptedPrivateKey is not a valid encrypted string', 400); return errorResponse('encryptedPrivateKey is not a valid encrypted string', 400);
} }
if (body.key) user.key = body.key;
if (body.encryptedPrivateKey) user.privateKey = body.encryptedPrivateKey;
if (body.publicKey) user.publicKey = body.publicKey;
user.updatedAt = new Date().toISOString(); user.updatedAt = new Date().toISOString();
await storage.saveUser(user); await storage.saveUser(user);