@@ -56,6 +56,7 @@ func (app *app) initRouter() { | |||||
api := app.router.PathPrefix("/⌂/").Subrouter() | api := app.router.PathPrefix("/⌂/").Subrouter() | ||||
api.HandleFunc("/create", app.handler(createHouse)).Methods("POST").Name("create") | api.HandleFunc("/create", app.handler(createHouse)).Methods("POST").Name("create") | ||||
api.HandleFunc("/{house:[A-Za-z0-9.-]{8}}", app.handler(renovateHouse)).Methods("POST").Name("update") | api.HandleFunc("/{house:[A-Za-z0-9.-]{8}}", app.handler(renovateHouse)).Methods("POST").Name("update") | ||||
api.HandleFunc("/public", app.handler(getPublicHousesData)).Methods("GET").Name("browse-api") | |||||
admin := app.router.PathPrefix("/admin/").Subrouter() | admin := app.router.PathPrefix("/admin/").Subrouter() | ||||
admin.HandleFunc("/unpublish", app.handler(banHouse)).Methods("POST").Name("unpublish") | admin.HandleFunc("/unpublish", app.handler(banHouse)).Methods("POST").Name("unpublish") | ||||
@@ -198,6 +198,19 @@ func getHouseHTML(app *app, houseID string) (string, error) { | |||||
return html, nil | return html, nil | ||||
} | } | ||||
func getPublicHousesData(app *app, w http.ResponseWriter, r *http.Request) error { | |||||
houses, err := getPublicHouses(app) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
for i := range *houses { | |||||
(*houses)[i].process(app) | |||||
} | |||||
return impart.WriteSuccess(w, houses, http.StatusOK) | |||||
} | |||||
// regular expressions for extracting data | // regular expressions for extracting data | ||||
var ( | var ( | ||||
htmlReg = regexp.MustCompile("<html( ?.*)>") | htmlReg = regexp.MustCompile("<html( ?.*)>") | ||||
@@ -1,10 +1,15 @@ | |||||
package htmlhouse | package htmlhouse | ||||
import ( | |||||
"fmt" | |||||
) | |||||
type ( | type ( | ||||
PublicHouse struct { | PublicHouse struct { | ||||
ID string | |||||
Title string | |||||
ThumbURL string | |||||
ID string `json:"id"` | |||||
Title string `json:"title"` | |||||
URL string `json:"url"` | |||||
ThumbURL string `json:"thumb_url"` | |||||
} | } | ||||
HouseStats struct { | HouseStats struct { | ||||
@@ -17,3 +22,10 @@ type ( | |||||
Label string | Label string | ||||
} | } | ||||
) | ) | ||||
func (h *PublicHouse) process(app *app) { | |||||
h.URL = fmt.Sprintf("%s/%s.html", app.cfg.HostName, h.ID) | |||||
if h.ThumbURL != "" { | |||||
h.ThumbURL = "https://peeper.html.house/" + h.ThumbURL | |||||
} | |||||
} |