Skip to content

Commit c303aac

Browse files
committed
fix more styles
1 parent 6218560 commit c303aac

File tree

1 file changed

+30
-35
lines changed
  • plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow

1 file changed

+30
-35
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQPanel.kt

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -151,42 +151,12 @@ class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Di
151151
val maxDimension = 8000
152152

153153
for (file in fileList as List<File>) {
154-
val fileName = file.name
155-
val ext = fileName.substringAfterLast('.', "").lowercase()
156-
157-
// File type restriction
158-
if (ext !in allowedTypes) {
159-
errorMessages.add("$fileName: File must be an image in JPEG, PNG, GIF, or WebP format.")
160-
continue
161-
}
162-
163-
// Size restriction
164-
if (file.length() > maxFileSize) {
165-
errorMessages.add("$fileName: Image must be no more than 3.75MB in size.")
166-
continue
167-
}
168-
169-
// Width/Height restriction (only for image types)
170-
try {
171-
val img = read(file)
172-
if (img == null) {
173-
errorMessages.add("$fileName: File could not be read as an image.")
174-
continue
175-
}
176-
if (img.width > maxDimension) {
177-
errorMessages.add("$fileName: Image must be no more than 8,000px in width.")
178-
continue
179-
}
180-
if (img.height > maxDimension) {
181-
errorMessages.add("$fileName: Image must be no more than 8,000px in height.")
182-
continue
183-
}
184-
} catch (e: Exception) {
185-
errorMessages.add("$fileName: File could not be read as an image.")
186-
continue
154+
val validationResult = validateImageFile(file, allowedTypes, maxFileSize, maxDimension)
155+
if (validationResult != null) {
156+
errorMessages.add(validationResult)
157+
} else {
158+
validImages.add(file)
187159
}
188-
189-
validImages.add(file)
190160
}
191161

192162
// File count restriction
@@ -312,6 +282,31 @@ class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Di
312282
}
313283
}
314284

285+
private fun validateImageFile(file: File, allowedTypes: Set<String>, maxFileSize: Double, maxDimension: Int): String? {
286+
val fileName = file.name
287+
val ext = fileName.substringAfterLast('.', "").lowercase()
288+
289+
if (ext !in allowedTypes) {
290+
return "$fileName: File must be an image in JPEG, PNG, GIF, or WebP format."
291+
}
292+
293+
if (file.length() > maxFileSize) {
294+
return "$fileName: Image must be no more than 3.75MB in size."
295+
}
296+
297+
return try {
298+
val img = read(file)
299+
when {
300+
img == null -> "$fileName: File could not be read as an image."
301+
img.width > maxDimension -> "$fileName: Image must be no more than 8,000px in width."
302+
img.height > maxDimension -> "$fileName: Image must be no more than 8,000px in height."
303+
else -> null
304+
}
305+
} catch (e: Exception) {
306+
"$fileName: File could not be read as an image."
307+
}
308+
}
309+
315310
companion object {
316311
private val LOG = getLogger<AmazonQPanel>()
317312
}

0 commit comments

Comments
 (0)