mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
00ad0e0bd4
* docs: add RFC-004 for CLI (cobra) and output design * feat: add output package with Formatter interface and BrowserData.Each * fix: golangci config array syntax + add output package tests * refactor: encapsulated Output as Writer, collect-then-write pattern * refactor: unified row type with reflection-based CSV/JSON output * fix: ProfileName empty guard, writeFile close error check, sync RFC-004
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package output
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/types"
|
|
)
|
|
|
|
type cookieEditorFormatter struct{}
|
|
|
|
func (f *cookieEditorFormatter) ext() string { return "json" }
|
|
|
|
func (f *cookieEditorFormatter) format(w io.Writer, rows []row) error {
|
|
entries := make([]cookieEditorEntry, 0, len(rows))
|
|
for _, r := range rows {
|
|
c, ok := r.entry.(types.CookieEntry)
|
|
if !ok {
|
|
return nil // not cookies, skip
|
|
}
|
|
var expDate float64
|
|
if !c.ExpireAt.IsZero() {
|
|
expDate = float64(c.ExpireAt.Unix())
|
|
}
|
|
entries = append(entries, cookieEditorEntry{
|
|
Domain: c.Host,
|
|
ExpirationDate: expDate,
|
|
HTTPOnly: c.IsHTTPOnly,
|
|
Name: c.Name,
|
|
Path: c.Path,
|
|
Secure: c.IsSecure,
|
|
Value: c.Value,
|
|
})
|
|
}
|
|
|
|
enc := json.NewEncoder(w)
|
|
enc.SetIndent("", " ")
|
|
enc.SetEscapeHTML(false)
|
|
return enc.Encode(entries)
|
|
}
|
|
|
|
// cookieEditorEntry matches the CookieEditor browser extension's import format.
|
|
type cookieEditorEntry struct {
|
|
Domain string `json:"domain"`
|
|
ExpirationDate float64 `json:"expirationDate"`
|
|
HTTPOnly bool `json:"httpOnly"`
|
|
Name string `json:"name"`
|
|
Path string `json:"path"`
|
|
Secure bool `json:"secure"`
|
|
Value string `json:"value"`
|
|
}
|