Files
HackBrowserData/internal/export/cookie_editor.go
T
Roger 3e9150249c refactor: rename core types and spell out every name (#677)
Def, Request, DirID, and Source said too little, and short variables and doc comments that skip their name hid intent.
varnamelen and staticcheck ST1020-22 now keep both from coming back.
2026-11-02 11:06:05 +08:00

54 lines
1.4 KiB
Go

package export
import (
"strings"
"github.com/moond4rk/hackbrowserdata/internal/record"
)
var sameSiteNone = "no_restriction"
func cookieEditorValue(row record.Record) any {
cookie, ok := row.(*record.Cookie)
if !ok {
return row
}
var expDate float64
if !cookie.ExpireAt.IsZero() {
expDate = float64(cookie.ExpireAt.Unix())
}
sameSite := &cookie.SameSite
switch cookie.SameSite {
case "none":
sameSite = &sameSiteNone
case "", "unspecified":
sameSite = nil
}
return cookieEditorEntry{
Domain: cookie.Host,
ExpirationDate: expDate,
HTTPOnly: cookie.IsHTTPOnly,
Name: cookie.Name,
Path: cookie.Path,
Secure: cookie.IsSecure,
Value: cookie.Value,
SameSite: sameSite,
Session: expDate == 0.,
HostOnly: !strings.HasPrefix(cookie.Host, "."),
}
}
// cookieEditorEntry matches the CookieEditor browser extension's import format.
type cookieEditorEntry struct {
Domain string `json:"domain"`
ExpirationDate float64 `json:"expirationDate,omitempty"`
HTTPOnly bool `json:"httpOnly"`
Name string `json:"name"`
Path string `json:"path"`
Secure bool `json:"secure"`
Value string `json:"value"`
SameSite *string `json:"sameSite"`
Session bool `json:"session"`
HostOnly bool `json:"hostOnly"`
}