fix: bot avatar generation - decrypt credentials before passing to S3

This commit is contained in:
Christomatt
2026-02-01 04:16:42 +01:00
parent 3bf56cca82
commit 13b38f0a7b
2 changed files with 13 additions and 7 deletions
+12 -6
View File
@@ -17,7 +17,7 @@ import {
BotHandleTakenError, BotHandleTakenError,
BotValidationError, BotValidationError,
} from '@/lib/bots/botManager'; } from '@/lib/bots/botManager';
import { generateAndUploadAvatarToUserStorage } from '@/lib/storage/s3'; import { generateAndUploadAvatarToUserStorage, decryptS3Credentials } from '@/lib/storage/s3';
// Schema for creating a bot // Schema for creating a bot
const createBotSchema = z.object({ const createBotSchema = z.object({
@@ -68,15 +68,21 @@ export async function POST(request: Request) {
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000'; const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
const botHandle = `${data.handle.toLowerCase()}@${nodeDomain}`; const botHandle = `${data.handle.toLowerCase()}@${nodeDomain}`;
botAvatarUrl = await generateAndUploadAvatarToUserStorage( // Decrypt the storage credentials
botHandle, const { accessKeyId, secretAccessKey } = decryptS3Credentials(
user.storageEndpoint ?? undefined,
user.storageRegion || 'auto',
user.storageBucket,
user.storageAccessKeyEncrypted, user.storageAccessKeyEncrypted,
user.storageSecretKeyEncrypted, user.storageSecretKeyEncrypted,
data.ownerPassword data.ownerPassword
); );
botAvatarUrl = await generateAndUploadAvatarToUserStorage(
botHandle,
user.storageEndpoint,
user.storageRegion || 'auto',
user.storageBucket,
accessKeyId,
secretAccessKey
);
} catch (err) { } catch (err) {
console.error('[Bot API] Failed to generate bot avatar:', err); console.error('[Bot API] Failed to generate bot avatar:', err);
// Continue without avatar - user can set it later // Continue without avatar - user can set it later
+1 -1
View File
@@ -25,7 +25,7 @@ interface StorageUploadResult {
/** /**
* Decrypt S3 credentials from encrypted storage * Decrypt S3 credentials from encrypted storage
*/ */
function decryptS3Credentials( export function decryptS3Credentials(
encryptedAccessKey: string, encryptedAccessKey: string,
encryptedSecretKey: string, encryptedSecretKey: string,
password: string password: string