mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
wip: debug
This commit is contained in:
parent
5fadcd731c
commit
adbf3046ef
@ -1,51 +1,57 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/foomo/sesamy-go/pkg/client"
|
"github.com/foomo/sesamy-go/pkg/client"
|
||||||
"github.com/foomo/sesamy-go/pkg/encoding/mpv2"
|
"github.com/foomo/sesamy-go/pkg/encoding/mpv2"
|
||||||
"github.com/foomo/sesamy-go/pkg/provider/cookiebot"
|
"github.com/foomo/sesamy-go/pkg/provider/cookiebot"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MPv2MiddlewarConsent(next client.MPv2Handler) client.MPv2Handler {
|
func MPv2MiddlewarConsent(l *zap.Logger) client.MPv2Middleware {
|
||||||
return func(r *http.Request, payload *mpv2.Payload[any]) error {
|
return func(next client.MPv2Handler) client.MPv2Handler {
|
||||||
fmt.Println("---> 1")
|
return func(r *http.Request, payload *mpv2.Payload[any]) error {
|
||||||
cookie, err := r.Cookie(cookiebot.CookieName)
|
cookie, err := r.Cookie(cookiebot.CookieName)
|
||||||
if err != nil || cookie.Value == "" {
|
if errors.Is(err, http.ErrNoCookie) {
|
||||||
return next(r, payload)
|
return next(r, payload)
|
||||||
}
|
} else if err != nil {
|
||||||
|
l.With(zap.Error(err)).Warn("failed to retrieve cookie bot cookie")
|
||||||
fmt.Println("---> 2: " + cookie.Value)
|
return next(r, payload)
|
||||||
data, err := base64.StdEncoding.DecodeString(cookie.Value)
|
} else if cookie.Value == "" {
|
||||||
if err != nil {
|
l.With(zap.Error(err)).Warn("empty cookie bot cookie")
|
||||||
fmt.Println("---> 2: " + err.Error())
|
return next(r, payload)
|
||||||
return next(r, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
var value cookiebot.Cookie
|
|
||||||
fmt.Println("---> 3")
|
|
||||||
if err := json.Unmarshal(data, &value); err != nil {
|
|
||||||
return next(r, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
consent := func(b bool) *string {
|
|
||||||
ret := "denied"
|
|
||||||
if b {
|
|
||||||
ret = "granted"
|
|
||||||
}
|
}
|
||||||
return &ret
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("---> 4")
|
data, err := url.PathUnescape(cookie.Value)
|
||||||
payload.Consent = &mpv2.Consent{
|
if err != nil {
|
||||||
AdUserData: consent(value.Marketing),
|
l.With(zap.Error(err)).Warn("failed to unescape cookie bot cookie")
|
||||||
AdPersonalization: consent(value.Statistics),
|
return next(r, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
return next(r, payload)
|
var value cookiebot.Cookie
|
||||||
|
if err := json.Unmarshal([]byte(data), &value); err != nil {
|
||||||
|
l.With(zap.Error(err)).Warn("failed to unmarshal cookie bot cookie")
|
||||||
|
return next(r, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
consent := func(b bool) *string {
|
||||||
|
ret := "denied"
|
||||||
|
if b {
|
||||||
|
ret = "granted"
|
||||||
|
}
|
||||||
|
return &ret
|
||||||
|
}
|
||||||
|
|
||||||
|
payload.Consent = &mpv2.Consent{
|
||||||
|
AdUserData: consent(value.Marketing),
|
||||||
|
AdPersonalization: consent(value.Statistics),
|
||||||
|
}
|
||||||
|
|
||||||
|
return next(r, payload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user