summaryrefslogtreecommitdiff
path: root/fetch
diff options
context:
space:
mode:
Diffstat (limited to 'fetch')
-rw-r--r--fetch/fetch.go4
-rw-r--r--fetch/http.go31
2 files changed, 22 insertions, 13 deletions
diff --git a/fetch/fetch.go b/fetch/fetch.go
index 3fc160b..4dfb6c2 100644
--- a/fetch/fetch.go
+++ b/fetch/fetch.go
@@ -68,9 +68,7 @@ func UpdatePage(p *core.Page) error {
case "gemini":
return updateGeminiPage(p)
case "http", "https":
- // return updateHTTPPage(p)
- // TODO
- fallthrough
+ return updateHTTPPage(p)
case "gopher", "gophers":
// return updateGopherPage(p)
// TODO
diff --git a/fetch/http.go b/fetch/http.go
index fb373e6..1b76a03 100644
--- a/fetch/http.go
+++ b/fetch/http.go
@@ -76,24 +76,35 @@ func newHTTPFeed(remoteURL *url.URL, title string) (*core.Feed, error) {
// newHTTPPage will create a new core.Page given an http url
func newHTTPPage(remoteURL *url.URL, title string) (*core.Page, error) {
- resp, err := fetchHTTP(remoteURL)
+ var page core.Page
+ page.Title = title
+ page.Link = remoteURL
+
+ err := updateHTTPPage(&page)
if err != nil {
return nil, err
}
+ return &page, nil
+}
+
+// updateHTTPPage will check an existing core.Page for changes
+func updateHTTPPage(p *core.Page) error {
+ resp, err := fetchHTTP(p.Link)
+ if err != nil {
+ return err
+ }
defer resp.Body.Close()
reader := io.LimitReader(resp.Body, 1073741824) // 1 GiB
- var page core.Page
- page.Title = title
- page.Link = remoteURL
- page.Updated = time.Now()
-
h := sha256.New()
if _, err := io.Copy(h, reader); err != nil {
- return nil, err
+ return err
}
- page.Hash = fmt.Sprintf("%x", h.Sum(nil))
-
- return &page, nil
+ newHash := fmt.Sprintf("%x", h.Sum(nil))
+ if newHash != p.Hash {
+ p.Hash = newHash
+ p.Updated = time.Now()
+ }
+ return nil
}