all repos — honk @ 8a01b26d77b4022a9d339d5fd2ae74a43b196d69

my fork of honk

bloat.go (view raw)

 1//
 2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
 3//
 4// Permission to use, copy, modify, and distribute this software for any
 5// purpose with or without fee is hereby granted, provided that the above
 6// copyright notice and this permission notice appear in all copies.
 7//
 8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16package main
17
18import (
19	"net/http"
20	"strings"
21
22	"humungus.tedunangst.com/r/webs/junk"
23)
24
25func servewonkles(w http.ResponseWriter, r *http.Request) {
26	url := r.FormValue("w")
27	dlog.Printf("getting wordlist: %s", url)
28	wonkles := getxonker(url, "wonkles")
29	if wonkles == "" {
30		wonkles = savewonkles(url)
31		if wonkles == "" {
32			http.NotFound(w, r)
33			return
34		}
35	}
36	var words []string
37	for _, l := range strings.Split(wonkles, "\n") {
38		words = append(words, l)
39	}
40	if !develMode {
41		w.Header().Set("Cache-Control", "max-age=7776000")
42	}
43
44	j := junk.New()
45	j["wordlist"] = words
46	j.Write(w)
47}
48
49func savewonkles(url string) string {
50	w := getxonker(url, "wonkles")
51	if w != "" {
52		return w
53	}
54	ilog.Printf("fetching wonkles: %s", url)
55	res, err := fetchsome(url)
56	if err != nil {
57		ilog.Printf("error fetching wonkles: %s", err)
58		return ""
59	}
60	w = getxonker(url, "wonkles")
61	if w != "" {
62		return w
63	}
64	w = string(res)
65	savexonker(url, w, "wonkles", "")
66	return w
67}