Files
HackBrowserData/internal/export/cookie_editor.go
T
Roger 9e9d1c531d refactor: rename identifiers and expand the browser table (#685)
Names say what each thing is: no package stutter, one word per concept, spelled out, none that differ only in case.
The browser table puts one field per line. Wire names (flags, output fields, keys.json) are unchanged.
2026-11-09 17:25:35 +08:00

54 lines
1.4 KiB
Go

package export
import (
"strings"
"github.com/moond4rk/hackbrowserdata/internal/record"
)
var sameSiteNone = "no_restriction"
func toCookieEditor(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"`
}