fix: Include scale into the hash

Should fix https://github.com/kovetskiy/mark/issues/683
This commit is contained in:
Manuel Rüger 2025-12-08 17:11:20 +01:00
parent 1c708414dd
commit 817c9684ce
4 changed files with 21 additions and 4 deletions

View File

@ -4,7 +4,9 @@ import (
"bytes"
"context"
"encoding/base64"
"encoding/binary"
"fmt"
"math"
"strconv"
"time"
@ -63,7 +65,14 @@ func ProcessD2(title string, d2Diagram []byte, scale float64) (attachment.Attach
return attachment.Attachment{}, err
}
checkSum, err := attachment.GetChecksum(bytes.NewReader(d2Diagram))
scaleAsBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(scaleAsBytes, math.Float64bits(scale))
d2Bytes := append(d2Diagram, scaleAsBytes...)
checkSum, err := attachment.GetChecksum(bytes.NewReader(d2Bytes))
log.Debugf(nil, "Checksum: %q -> %s", title, checkSum)
if err != nil {

View File

@ -75,7 +75,7 @@ func TestExtractD2Image(t *testing.T) {
Filename: "example.png",
Name: "example",
Replace: "example",
Checksum: "58fa387384181445e2d8f90a8c7fda945cb75174f73e8b9853ff59b9e0103ddd",
Checksum: "40e75f93e09da9242d4b1ab8e2892665ec7d5bd1ac78a4b65210ee219cf62297",
ID: "",
Width: "198",
Height: "441",

View File

@ -3,6 +3,8 @@ package mermaid
import (
"bytes"
"context"
"encoding/binary"
"math"
"strconv"
"time"
@ -30,7 +32,13 @@ func ProcessMermaidLocally(title string, mermaidDiagram []byte, scale float64) (
return attachment.Attachment{}, err
}
checkSum, err := attachment.GetChecksum(bytes.NewReader(mermaidDiagram))
scaleAsBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(scaleAsBytes, math.Float64bits(scale))
mermaidBytes := append(mermaidDiagram, scaleAsBytes...)
checkSum, err := attachment.GetChecksum(bytes.NewReader(mermaidBytes))
log.Debugf(nil, "Checksum: %q -> %s", title, checkSum)
if err != nil {

View File

@ -22,7 +22,7 @@ func TestExtractMermaidImage(t *testing.T) {
Filename: "example.png",
Name: "example",
Replace: "example",
Checksum: "1743a4f31ab66244591f06c8056e08053b8e0a554eb9a38709af6e9d145ac84f",
Checksum: "26296b73c960c25850b37bc9dd77cb24fce1a78db83b37755a25af7f8a48cc96",
ID: "",
Width: "87",
Height: "174",