瀏覽代碼

Add pre-condition check

Him188 6 年之前
父節點
當前提交
04b0287738
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/message/SendImageUtilsJvm.kt

+ 1 - 1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/message/SendImageUtilsJvm.kt

@@ -116,7 +116,7 @@ suspend fun InputStream.uploadAsImage(contact: Contact): OfflineImage =
  */
 @Throws(OverFileSizeMaxException::class)
 suspend fun File.uploadAsImage(contact: Contact): OfflineImage {
-    require(this.exists() && this.canRead())
+    require(this.isFile && this.exists() && this.canRead()) { "file ${this.path} is not readable" }
     return withContext(Dispatchers.IO) { toExternalImage() }.upload(contact)
 }