Files
HackBrowserData/internal/export/order.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

45 lines
1.0 KiB
Go

package export
import (
"sort"
"time"
"github.com/moond4rk/hackbrowserdata/internal/record"
)
// sortRecords is stable, so ties and keyless records keep source order: Safari bookmarks and downloads lack a time.
func sortRecords(records []record.Record) {
sort.SliceStable(records, func(i, j int) bool {
return sortKeyOf(records[i]).before(sortKeyOf(records[j]))
})
}
type sortKey struct {
visits int
timestamp time.Time
}
func sortKeyOf(row record.Record) sortKey {
switch typed := row.(type) {
case *record.Login:
return sortKey{timestamp: typed.CreatedAt}
case *record.Cookie:
return sortKey{timestamp: typed.CreatedAt}
case *record.Bookmark:
return sortKey{timestamp: typed.CreatedAt}
case *record.Download:
return sortKey{timestamp: typed.StartTime}
case *record.History:
return sortKey{visits: typed.VisitCount}
default:
return sortKey{}
}
}
func (k sortKey) before(other sortKey) bool {
if k.visits != other.visits {
return k.visits > other.visits
}
return k.timestamp.After(other.timestamp)
}