Skip to content

Commit 6875550

Browse files
committed
chore: adjust impl.
1 parent aa2edf6 commit 6875550

4 files changed

Lines changed: 16 additions & 9 deletions

File tree

packages/amplify-graphql-conversation-transformer/src/graphql-types/message-model.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ export const createAssistantResponseStreamingMutationInput = (messageModelName:
146146
};
147147

148148
export const createAttachmentUploadUrlQueryInput = (messageModelName: string): InputObjectTypeDefinitionNode => {
149-
const inputName = `Get${messageModelName}AttachmentUploadUrlInput`;
149+
const inputName = `Get${messageModelName}AttachmentUrlsInput`;
150150
return {
151151
kind: 'InputObjectTypeDefinition',
152152
name: { kind: 'Name', value: inputName },
153153
fields: [
154154
makeInputValueDefinition('conversationId', makeNonNullType(makeNamedType('ID'))),
155+
makeInputValueDefinition('attachmentKey', makeNonNullType(makeNamedType('String'))),
155156
],
156157
};
157158
};
@@ -312,7 +313,7 @@ const constructConversationMessageModel = (
312313
};
313314

314315
const STREAM_RESPONSE_TYPE_NAME = 'AmplifyAIConversationMessageStreamPart';
315-
const ATTACHMENT_URL_RESPONSE_TYPE_NAME = 'AmplifyAIAttachmentUrl';
316+
const ATTACHMENT_URL_RESPONSE_TYPE_NAME = 'AmplifyAIAttachmentUrls';
316317

317318
export const constructStreamResponseType = (): ObjectTypeDefinitionNode => {
318319
return {

packages/amplify-graphql-conversation-transformer/src/resolvers/get-attachment-url-pipeline-definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ function fieldName(config: ConversationDirectiveConfiguration): string {
8383
* Creates a template generator specific to the send message pipeline for a given slot name.
8484
*/
8585
function templateGenerator(slotName: string) {
86-
return createS3AssetMappingTemplateGenerator('Mutation', slotName, fieldName);
86+
return createS3AssetMappingTemplateGenerator('Query', slotName, fieldName);
8787
}

packages/amplify-graphql-conversation-transformer/src/resolvers/templates/invoke-attachment-lambda-resolver-fn.template.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export function request(ctx) {
55

66
const payload = {
77
conversationId: args.input.conversationId,
8+
attachmentKey: args.input.attachmentKey,
89
};
910

1011
return {
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
1+
import { S3Client, GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
22
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
33

44
/**
55
* TODO
66
*/
77
export const handler = async (event: {
88
conversationId: string;
9+
attachmentKey: string;
910
}): Promise<{
10-
url: string;
11+
uploadUrl: string;
12+
downloadUrl: string;
1113
}> => {
1214
console.log(JSON.stringify(event, null, 2));
1315
console.log(process.env);
@@ -19,11 +21,14 @@ export const handler = async (event: {
1921
const bucketName = process.env.S3_BUCKET_NAME;
2022

2123
const client = new S3Client();
22-
const attachmentKey = crypto.randomUUID();
23-
const command = new PutObjectCommand({ Bucket: bucketName, Key: `${event.conversationId}/${attachmentKey}` });
24-
const url = await getSignedUrl(client, command, { expiresIn: 3600 });
24+
const putCommand = new PutObjectCommand({ Bucket: bucketName, Key: `${event.conversationId}/${event.attachmentKey}` });
25+
const uploadUrl = await getSignedUrl(client, putCommand, { expiresIn: 3600 });
26+
27+
const getCommand = new GetObjectCommand({ Bucket: bucketName, Key: `${event.conversationId}/${event.attachmentKey}` });
28+
const downloadUrl = await getSignedUrl(client, getCommand, { expiresIn: 3600 });
2529

2630
return {
27-
url,
31+
uploadUrl,
32+
downloadUrl,
2833
};
2934
};

0 commit comments

Comments
 (0)