Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: don't use camo for gitblob rendering

Signed-off-by: Seongmin Lee <git@boltless.me>

authored by

Seongmin Lee and committed by
Tangled
97bb4786 8dcd952d

-41
-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
··· 188 188 dstUrl, _ := url.Parse(attr.Val) 189 189 if camoUrl != nil && dstUrl != nil && dstUrl.Host != camoUrl.Host { 190 190 attr.Val = ctx.imageToRawTransformer(attr.Val) 191 - attr.Val = ctx.camoImageLinkTransformer(attr.Val) 192 191 node.Attr[i] = attr 193 192 } 194 193 }
-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