From 0b94d831293ccd9aff0a9994cf56cce25db641fe Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Wed, 22 Mar 2023 13:44:24 -0400 Subject: [PATCH] Add basic file-size check. --- .../textbox-question/textbox-question.vue | 17 +++++++++++++++-- src/layouts/vin-lookup/vin-lookup.vue | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/common-components/textbox-question/textbox-question.vue b/src/common-components/textbox-question/textbox-question.vue index 3eeef5a05..70b96aa1c 100644 --- a/src/common-components/textbox-question/textbox-question.vue +++ b/src/common-components/textbox-question/textbox-question.vue @@ -95,7 +95,7 @@ export default { cornerStyle: String, // Rounded or square. Square is default. includeSearchIcon: Boolean, includeImageQuestion: Boolean, - onImageQuestionSubmit: Function, + imageQuestionSubmitHandler: Function, }, setup(props) { const propsClone = Object.assign({}, props); @@ -136,9 +136,16 @@ export default { }, methods: { async imageChanged(e) { + let file = e.target.files[0]; + + if (!this.isImageValid(file)) { + this.$emit("imageLookupError"); + return; + } + this.isImageProcessing = true; - await this.onImageQuestionSubmit(e.target.files[0]) + await this.imageQuestionSubmitHandler(file) .then(async (response) => { this.value = response; @@ -152,6 +159,12 @@ export default { this.isImageProcessing = false; }, + + isImageValid(imageFile) { + let maxSize = 0.5 * 1028 * 1028; + + return imageFile && imageFile.size < maxSize; + }, }, computed: { questionText() { diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 1b61af93b..d0cf6c3cf 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -21,7 +21,7 @@ maxLength="17" :mask="vinMask" includeImageQuestion - :onImageQuestionSubmit="getVinFromImage" + :imageQuestionSubmitHandler="getVinFromImage" @image-lookup-error="displayVinScanAlert" data-test="vin-lookup-field" ref="vinLookupQuestion" />