mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(image): work-around for sha256 not allowed to be a Blob
This commit is contained in:
parent
080320bb82
commit
92a08cece7
1 changed files with 7 additions and 1 deletions
|
|
@ -23,6 +23,7 @@ local M = {}
|
|||
---@field pos snacks.image.Pos
|
||||
---@field src? string
|
||||
---@field content? string
|
||||
---@field content_id? string
|
||||
---@field ext? string
|
||||
---@field range? Range4
|
||||
---@field lang string
|
||||
|
|
@ -63,6 +64,7 @@ M.transforms = {
|
|||
return
|
||||
end
|
||||
img.content = vim.base64.decode(data)
|
||||
img.content_id = data:sub(1, 20)
|
||||
img.src = nil
|
||||
img.ext = ft:match("^image/(%w+)$") or "png"
|
||||
end,
|
||||
|
|
@ -319,7 +321,11 @@ function M._img(ctx)
|
|||
if img.content and not img.src then
|
||||
local root = Snacks.image.config.cache
|
||||
vim.fn.mkdir(root, "p")
|
||||
img.src = root .. "/" .. vim.fn.sha256(img.content):sub(1, 8) .. "-content." .. (img.ext or "png")
|
||||
img.src = root
|
||||
.. "/"
|
||||
.. (img.content_id or vim.fn.sha256(img.content):sub(1, 8))
|
||||
.. "-content."
|
||||
.. (img.ext or "png")
|
||||
if vim.fn.filereadable(img.src) == 0 then
|
||||
local fd = assert(io.open(img.src, "w"), "failed to open " .. img.src)
|
||||
fd:write(img.content)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue