From 0a8f69871671c0ac3281a4e2fa8b67e706f0d0ab Mon Sep 17 00:00:00 2001 From: David Goss Date: Sat, 8 Jul 2023 11:54:46 +0100 Subject: [PATCH] refactor a bit --- src/runtime/attachment_manager/index.ts | 30 ++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/runtime/attachment_manager/index.ts b/src/runtime/attachment_manager/index.ts index 7e2d91e0d..d2e9de8e5 100644 --- a/src/runtime/attachment_manager/index.ts +++ b/src/runtime/attachment_manager/index.ts @@ -59,39 +59,43 @@ export default class AttachmentManager { mediaTypeOrOptions?: string | ICreateAttachmentOptions, callback?: () => void ): void | Promise { - // eslint-disable-next-line prefer-const - let { mediaType, fileName } = normaliseOptions(mediaTypeOrOptions) + const options = normaliseOptions(mediaTypeOrOptions) if (Buffer.isBuffer(data)) { - if (doesNotHaveValue(mediaType)) { + if (doesNotHaveValue(options.mediaType)) { throw Error('Buffer attachments must specify a media type') } - this.createBufferAttachment(data, mediaType, fileName) + this.createBufferAttachment(data, options.mediaType, options.fileName) } else if (isStream.readable(data)) { - if (doesNotHaveValue(mediaType)) { + if (doesNotHaveValue(options.mediaType)) { throw Error('Stream attachments must specify a media type') } - return this.createStreamAttachment(data, mediaType, fileName, callback) + return this.createStreamAttachment( + data, + options.mediaType, + options.fileName, + callback + ) } else if (typeof data === 'string') { - if (doesNotHaveValue(mediaType)) { - mediaType = 'text/plain' + if (doesNotHaveValue(options.mediaType)) { + options.mediaType = 'text/plain' } - if (mediaType.startsWith('base64:')) { + if (options.mediaType.startsWith('base64:')) { this.createStringAttachment( data, { encoding: messages.AttachmentContentEncoding.BASE64, - contentType: mediaType.replace('base64:', ''), + contentType: options.mediaType.replace('base64:', ''), }, - fileName + options.fileName ) } else { this.createStringAttachment( data, { encoding: messages.AttachmentContentEncoding.IDENTITY, - contentType: mediaType, + contentType: options.mediaType, }, - fileName + options.fileName ) } } else {