|
|
|
@ -9,12 +9,13 @@ import ( |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"git.eeqj.de/sneak/goutil" |
|
|
|
|
"github.com/k0kubun/pp" |
|
|
|
|
|
|
|
|
|
// db driver:
|
|
|
|
|
_ "github.com/mattn/go-sqlite3" |
|
|
|
|
"github.com/rs/zerolog/log" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func (hp *HistoryPoster) postUrls(ctx context.Context, cancel context.CancelFunc) { |
|
|
|
|
func (hp *HistoryPoster) postURLs(ctx context.Context, cancel context.CancelFunc) { |
|
|
|
|
log.Info().Msg("finding history files") |
|
|
|
|
files, err := findHistoryFiles() |
|
|
|
|
if err != nil { |
|
|
|
@ -30,40 +31,39 @@ func (hp *HistoryPoster) postUrls(ctx context.Context, cancel context.CancelFunc |
|
|
|
|
hp.shutdown(err.Error(), -1) |
|
|
|
|
} |
|
|
|
|
for _, hitem := range hl { |
|
|
|
|
hp.processUrlFromHistory(hitem) |
|
|
|
|
hp.processURLFromHistory(hitem) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (hp *HistoryPoster) processUrlFromHistory(hi historyItem) { |
|
|
|
|
func (hp *HistoryPoster) processURLFromHistory(hi historyItem) { |
|
|
|
|
log.Debug(). |
|
|
|
|
Str("url", hi.url). |
|
|
|
|
Str("url", hi.URL). |
|
|
|
|
Msg("got url to process") |
|
|
|
|
if hp.store.UrlAlreadySeen(hi.url) { |
|
|
|
|
if hp.store.URLAlreadySeen(hi.URL) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
log.Debug(). |
|
|
|
|
Str("url", hi.url). |
|
|
|
|
Str("url", hi.URL). |
|
|
|
|
Msg("url is new, must be posted") |
|
|
|
|
err := hp.postUrl(hi) |
|
|
|
|
err := hp.postURL(hi) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(). |
|
|
|
|
Err(err). |
|
|
|
|
Msg("url could not be posted :(") |
|
|
|
|
} else { |
|
|
|
|
hp.store.MarkUrlSeen(hi.url) |
|
|
|
|
hp.store.MarkURLSeen(hi.URL) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (hp *HistoryPoster) postUrl(hi historyItem) error { |
|
|
|
|
func (hp *HistoryPoster) postURL(hi historyItem) error { |
|
|
|
|
// FIXME
|
|
|
|
|
//panic("unimplemented")
|
|
|
|
|
// panic("unimplemented")
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func findHistoryFiles() ([]string, error) { |
|
|
|
|
//FIXME make this support safari one day
|
|
|
|
|
// FIXME make this support safari one day
|
|
|
|
|
home := os.Getenv("HOME") |
|
|
|
|
chromeDir := home + "/Library/Application Support/Google/Chrome" |
|
|
|
|
defaultProfileDir := chromeDir + "/Default" |
|
|
|
@ -81,10 +81,10 @@ func findHistoryFiles() ([]string, error) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type historyItem struct { |
|
|
|
|
last_visit_time time.Time |
|
|
|
|
url string |
|
|
|
|
title string |
|
|
|
|
visit_count int |
|
|
|
|
lastVisitTime time.Time |
|
|
|
|
URL string |
|
|
|
|
title string |
|
|
|
|
visitCount int |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func dumpHistoryFromChromeHistoryFile(path string) ([]historyItem, error) { |
|
|
|
@ -98,7 +98,15 @@ func dumpHistoryFromChromeHistoryFile(path string) ([]historyItem, error) { |
|
|
|
|
Msg("created tempdir") |
|
|
|
|
|
|
|
|
|
dbfn := tempdir + "/History" |
|
|
|
|
goutil.CopyFile(path, dbfn) |
|
|
|
|
err = goutil.CopyFile(path, dbfn) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(). |
|
|
|
|
Str("source", path). |
|
|
|
|
Str("target", dbfn). |
|
|
|
|
Err(err). |
|
|
|
|
Msg("unable to copy history file") |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
log.Debug(). |
|
|
|
|
Str("dbfn", dbfn). |
|
|
|
|
Msg("copied history file") |
|
|
|
@ -145,30 +153,34 @@ func dumpHistoryFromChromeHistoryFile(path string) ([]historyItem, error) { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if rows.Err() != nil { |
|
|
|
|
return nil, rows.Err() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
defer rows.Close() |
|
|
|
|
|
|
|
|
|
output := make([]historyItem, 0) |
|
|
|
|
for rows.Next() { |
|
|
|
|
//log.Debug().Msg("processing row")
|
|
|
|
|
var last_visit_time int64 |
|
|
|
|
// log.Debug().Msg("processing row")
|
|
|
|
|
var lastVisitTime int64 |
|
|
|
|
var url string |
|
|
|
|
var title string |
|
|
|
|
var visit_count int |
|
|
|
|
err := rows.Scan(&last_visit_time, &url, &title, &visit_count) |
|
|
|
|
var visitCount int |
|
|
|
|
err := rows.Scan(&lastVisitTime, &url, &title, &visitCount) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Debug().Err(err).Msg("row error") |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
t := goutil.TimeFromWebKit(last_visit_time).UTC() |
|
|
|
|
t := goutil.TimeFromWebKit(lastVisitTime).UTC() |
|
|
|
|
hi := historyItem{ |
|
|
|
|
last_visit_time: t, |
|
|
|
|
url: url, |
|
|
|
|
title: title, |
|
|
|
|
visit_count: visit_count, |
|
|
|
|
lastVisitTime: t, |
|
|
|
|
URL: url, |
|
|
|
|
title: title, |
|
|
|
|
visitCount: visitCount, |
|
|
|
|
} |
|
|
|
|
output = append(output, hi) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pp.Print(output) |
|
|
|
|
// pp.Print(output)
|
|
|
|
|
return output, nil |
|
|
|
|
} |
|
|
|
|