Signed-off-by: Seongmin Lee git@boltless.me
-41
Diff
round #0
-36
appview/pages/markup/camo.go
-36
appview/pages/markup/camo.go
···
1
-
package markup
2
-
3
-
import (
4
-
"crypto/hmac"
5
-
"crypto/sha256"
6
-
"encoding/hex"
7
-
"fmt"
8
-
9
-
"github.com/yuin/goldmark/ast"
10
-
)
11
-
12
-
func GenerateCamoURL(baseURL, secret, imageURL string) string {
13
-
h := hmac.New(sha256.New, []byte(secret))
14
-
h.Write([]byte(imageURL))
15
-
signature := hex.EncodeToString(h.Sum(nil))
16
-
hexURL := hex.EncodeToString([]byte(imageURL))
17
-
return fmt.Sprintf("%s/%s/%s", baseURL, signature, hexURL)
18
-
}
19
-
20
-
func (rctx *RenderContext) camoImageLinkTransformer(dst string) string {
21
-
// don't camo on dev
22
-
if rctx.IsDev {
23
-
return dst
24
-
}
25
-
26
-
if rctx.CamoUrl != "" && rctx.CamoSecret != "" {
27
-
return GenerateCamoURL(rctx.CamoUrl, rctx.CamoSecret, dst)
28
-
}
29
-
30
-
return dst
31
-
}
32
-
33
-
func (rctx *RenderContext) camoImageLinkAstTransformer(img *ast.Image) {
34
-
dst := string(img.Destination)
35
-
img.Destination = []byte(rctx.camoImageLinkTransformer(dst))
36
-
}
-1
appview/pages/markup/markdown.go
-1
appview/pages/markup/markdown.go
-4
appview/repo/blob.go
-4
appview/repo/blob.go
···
278
278
query.Set("raw", "true")
279
279
280
280
blobURL := fmt.Sprintf("%s/xrpc/%s?%s", config.KnotMirror.Url, tangled.GitTempGetBlobNSID, query.Encode())
281
-
282
-
if config.Camo.Enabled() {
283
-
return markup.GenerateCamoURL(config.Camo.Host, config.Camo.SharedSecret, blobURL)
284
-
}
285
281
return blobURL
286
282
}
287
283
History
1 round
0 comments
boltless.me
submitted
#0
1 commit
expand
collapse
appview: don't use camo for gitblob rendering
Signed-off-by: Seongmin Lee <git@boltless.me>
merge conflicts detected
expand
collapse
expand
collapse
- appview/pages/markup/camo.go:1
- appview/pages/markup/markdown.go:188
- appview/repo/blob.go:278