summaryrefslogtreecommitdiff
path: root/fetch/gopher.go
diff options
context:
space:
mode:
Diffstat (limited to 'fetch/gopher.go')
-rw-r--r--fetch/gopher.go43
1 files changed, 14 insertions, 29 deletions
diff --git a/fetch/gopher.go b/fetch/gopher.go
index d42d5eb..c0d515b 100644
--- a/fetch/gopher.go
+++ b/fetch/gopher.go
@@ -12,7 +12,6 @@ import (
"net/url"
"time"
- //"github.com/mmcdole/gofeed"
"github.com/prologic/go-gopher"
"golang.nytpu.com/comitium/core"
@@ -27,34 +26,17 @@ func fetchGopher(remoteURL *url.URL) (*gopher.Response, error) {
return resp, nil
}
-// newGopherFeed will fetch and create a new core.Feed given a gopher url
-func newGopherFeed(remoteURL *url.URL, title string) (*core.Feed, error) {
- // TODO
- return nil, fmt.Errorf("Feeds served over gopher are currently unsupported.")
-}
-
-// updateGopherFeed will check an existing core.Feed for updates
-func updateGopherFeed(*core.Feed) error {
+// gopherFeed will fetch and insert a new core.Feed into a core.FullData given a
+// gopher url (or update if it's preexisting)
+func gopherFeed(data *core.FullData, remote *url.URL, title string) error {
// TODO
return fmt.Errorf("Feeds served over gopher are currently unsupported.")
}
-// newGopherPage will create a new core.Page given a gopher url
-func newGopherPage(remoteURL *url.URL, title string) (*core.Page, error) {
- var page core.Page
- page.Title = title
- page.Link = remoteURL
-
- err := updateGopherPage(&page)
- if err != nil {
- return nil, err
- }
- return &page, nil
-}
-
-// updateGopherPage wll check an existing core.Page for changes
-func updateGopherPage(p *core.Page) error {
- resp, err := fetchGopher(p.Link)
+// gopherPage will fetch and insert a new core.Page into a core.FullData given a
+// gopher url (or update if it's preexisting)
+func gopherPage(data *core.FullData, remote *url.URL, title string) error {
+ resp, err := fetchGopher(remote)
if err != nil {
return err
}
@@ -71,14 +53,17 @@ func updateGopherPage(p *core.Page) error {
reader = io.LimitReader(resp.Body, 1073741824) // 1 GiB
}
+ var page core.Page
+ page.Title = title
+ page.Link = remote
h := sha256.New()
if _, err := io.Copy(h, reader); err != nil {
return err
}
newHash := fmt.Sprintf("%x", h.Sum(nil))
- if newHash != p.Hash {
- p.Hash = newHash
- p.Updated = time.Now()
- }
+ page.Hash = newHash
+ page.Updated = time.Now()
+
+ InsertPage(data, &page, remote)
return nil
}