MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / decodeBase64URL

Method decodeBase64URL

options/parser/url.go:25–53  ·  view source on GitHub ↗
(ctx context.Context, parts []string)

Source from the content-addressed store, hash-verified

23}
24
25func (p *Parser) decodeBase64URL(ctx context.Context, parts []string) (string, string, error) {
26 var format string
27
28 if len(parts) > 1 && p.config.Base64URLIncludesFilename {
29 parts = parts[:len(parts)-1]
30 }
31
32 encoded := strings.Join(parts, "")
33 urlParts := strings.Split(encoded, ".")
34
35 if len(urlParts[0]) == 0 {
36 return "", "", newInvalidURLError(ctx, "Image URL is empty")
37 }
38
39 if len(urlParts) > 2 {
40 return "", "", newInvalidURLError(ctx, "Multiple formats are specified: %s", encoded)
41 }
42
43 if len(urlParts) == 2 && len(urlParts[1]) > 0 {
44 format = urlParts[1]
45 }
46
47 imageURL, err := base64.RawURLEncoding.DecodeString(strings.TrimRight(urlParts[0], "="))
48 if err != nil {
49 return "", "", newInvalidURLError(ctx, "Invalid url encoding: %s", encoded)
50 }
51
52 return p.preprocessURL(string(imageURL)), format, nil
53}
54
55func (p *Parser) decodePlainURL(ctx context.Context, parts []string) (string, string, error) {
56 var format string

Callers 1

DecodeURLMethod · 0.95

Calls 3

preprocessURLMethod · 0.95
newInvalidURLErrorFunction · 0.85
SplitMethod · 0.80

Tested by

no test coverage detected