mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
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.
45 lines
1.0 KiB
Go
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)
|
|
}
|