From 73f2ea333edb336caa4bcf1d1b158771e5ac6092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Harnes?= Date: Mon, 11 Mar 2024 12:05:42 +0100 Subject: [PATCH] fix: add warning message when base64 string is too large --- lua/img-clip/paste.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/img-clip/paste.lua b/lua/img-clip/paste.lua index 21e4863..d66449c 100644 --- a/lua/img-clip/paste.lua +++ b/lua/img-clip/paste.lua @@ -182,7 +182,10 @@ M.embed_image_as_base64 = function(file_path, opts) end -- check if base64 string is too long (max_base64_size is in KB) - if string.len(base64) > config.get_opt("max_base64_size", opts) * 1024 then + local base64_size_kb = (string.len(base64) * 6) / (8 * 1024) + local max_size_kb = config.get_opt("max_base64_size", opts) + if base64_size_kb > max_size_kb then + util.warn("Base64 string is too large (" .. base64_size_kb .. " KB). Max allowed size is " .. max_size_kb .. " KB.") return false end