diff options
author | Petter Rodhelind <petter.rodhelind@gmail.com> | 2021-02-22 01:07:06 +0100 |
---|---|---|
committer | Petter Rodhelind <petter.rodhelind@gmail.com> | 2021-02-22 01:07:06 +0100 |
commit | 8db0c2658650ad677c90a42a61061a75af8f762e (patch) | |
tree | c4135d523d7f70470268353067cb7fcc0f4943f7 | |
parent | 8099bec4e5275f1fbb47092731a64be6e9e2cf51 (diff) | |
download | fbfeed-8db0c2658650ad677c90a42a61061a75af8f762e.tar.gz fbfeed-8db0c2658650ad677c90a42a61061a75af8f762e.tar.bz2 fbfeed-8db0c2658650ad677c90a42a61061a75af8f762e.zip |
Add a semi-hidden feature of GET /.cache.
-rw-r--r-- | main.go | 40 |
1 files changed, 24 insertions, 16 deletions
@@ -102,39 +102,47 @@ func (p *post) String() string { type handler struct{} func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/favicon.ico" { - return - } + path := r.URL.Path[1:] - if r.URL.Path == "/" { + switch path { + case "": http.Error(w, fmt.Sprintf("usage: %s/@facebookGroupName", r.Host), 400) return + case "favicon.ico": + return + case ".cache": + var s string + for k, v := range cache.v { + s += v.Time.Format("2006-01-02 15:04:05") + s += "\t" + k + "\n" + } + fmt.Fprintf(w, "%s", s) + return } - group := r.URL.Path[1:] - if group[0] == '@' { - group = group[1:] + if path[0] == '@' { + path = path[1:] } - if strings.HasSuffix(group, ".rss") { - group = strings.TrimSuffix(group, ".rss") + if strings.HasSuffix(path, ".rss") { + path = strings.TrimSuffix(path, ".rss") outputMode = "rss" } - c, ok := cache.v[group] + c, ok := cache.v[path] if !ok || time.Now().Sub(c.Time).Seconds() > cacheTimeout { var err error - c, err = fetch(group) + c, err = fetch(path) if err != nil { http.Error(w, fmt.Sprintf("error: %s", err), 400) return } if c == nil || len(c.Items) < 1 { - http.Error(w, fmt.Sprintf("%s", "Group not found."), 400) + http.Error(w, fmt.Sprintf("%s", "Page not found."), 400) return } - c.Name = group + c.Name = path c.Time = time.Now() cache.Lock() @@ -145,12 +153,12 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "%s\n", c.String()) } -func fetch(group string) (c *channel, err error) { - if group == "" { +func fetch(path string) (c *channel, err error) { + if path == "" { return } - url := "https://www.facebook.com/pg/" + group + "/posts/" + url := "https://www.facebook.com/pg/" + path + "/posts/" log.Println("Fetching:", url) |