This commit is contained in:
Brian Buller 2019-01-13 08:22:29 -06:00
parent e0f25b8529
commit 8cc411b89d
16 changed files with 520 additions and 111 deletions

127
assets.go
View File

@ -222,6 +222,94 @@ nC1WAvxNMB27f2/7AjTg5s54BOwNTttvIBe0ubuEzo83ocq/bONcqwz1BCL/BAAA///ACu/RdBMAAA==
`,
},
"/assets/img/favicon.png": {
local: "assets/img/favicon.png",
size: 4752,
modtime: 1547232209,
compressed: `
H4sIAAAAAAAC/wCQEm/tiVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAIAAAC3LO29AAAAA3NCSVQICAjb
4U/gAAASSElEQVR4nO1beXRc1Xn/7tvnzapZNdoty7ItWchgI2xwvABGxHYJSWMSN5y2IW2TZmkoJ3HS
noQApT6QJiGnTU8TiiFO6bFpUAgkgbCTeCHGlmXZEta+YO2jZfZ56739Y8TzaPRmJNkCkpz8zv1j5nvf
/e73e/e97353eYgQAn/UoD5oB95z/InhHz7+xPAPH3/8DJmlVugaHzw/0vX2SO/wzPhEbBoAOIb12z11
xavqS1fXBFfaePFKHJI1pXWos+ViR1/o4uDUiKKpAOC3uwudvvrS1bXBqupA+ZIMokWOhzrGU4nwN37+
72eHOtISmqZohAABxkTHOG3Gwglfa/zMjuprLZywNGYAKUV6vevUwy8eTCkSACAENEVRFAICOiG6jtNq
NcGV39rz92XuIppa1AO4WIbfe+XQz868ougqRaEyf8HqEq9d5FmGRgCajmVVG52JdwyMR1MyQmiVv+xb
ez6/yr+Emz0cnvj6M490jQ8QQliOWV8ZLHLbeZZhaIoAqJoeTymDoXDnOxMYE45mb6m94WuNd/EMtwwM
k4r01abvnho4T9HUmlJ/XUXAZTXvHx3jntHpc/2j05Ekx7D//OG/3bVu62LovdZx8l+e/2FCThXYLfUr
i6qC7lz9k5CV9sGJ1r5RrOOrSqoP3H633+6+IoZJJXXXT77ZFxoSeHZ3w2qPfeF3DBPyYkvPxbEZADj0
1/+6Nrgyv/754a7P/e8Dqq4F/a7dG1ZRCC3YRDQlP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uCVTXByg3lteLSv34zxbIx
zELf5FDnWH/XxGBv6OJUPJzKOIBrQGQFt81V5SurK65aU1iZ64DoFeK9YpgJQkhKNVn4WK5eyo/3g+EH
iz/+74D/H7pyLaLgRAMBAAAAAElFTkSuQmCCAQAA//8F82/kkBIAAA==
`,
},
"/assets/vendor/css/grids-responsive-min.css": {
local: "assets/vendor/css/grids-responsive-min.css",
size: 8032,
@ -389,10 +477,38 @@ ZfY39XJelrPeb2dTP1e8O5VLPwIAAP//0xnP9ywDAAA=
"/templates/user_dashboard.html": {
local: "templates/user_dashboard.html",
size: 0,
modtime: 1547138339,
size: 45,
modtime: 1547160534,
compressed: `
H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA=
H4sIAAAAAAAC/7JJVMgoSk2zVdIvLU4t0k9LTU0pVrJzTcksUQguTSpOLsosKMnMzyu20U+04wIEAAD/
/2HSavctAAAA
`,
},
"/templates/user_feeds.html": {
local: "templates/user_feeds.html",
size: 3588,
modtime: 1547234296,
compressed: `
H4sIAAAAAAAC/5xXXY/aOBe+z6+wrLkIGia0t4UgtdP3lSpVu9JC92aEkIkPiTXGjmwHZjTiv69sJ9ih
IWL3ApT4POf7wycLyo6I0RwTzrdaNqoAvS2kMIQJUHi5mFF2XCaLvVQHJMgBcrwHoFvd7HShWG2YFBoj
UtiHHM8aDWrW1JQY6EOWCUILJurGOHUWt7WSNEbmvYYcV4xSELhVEtOPhDeQY4xmTsiuMUaKlks3uwMz
eLkiR1jMPGmZLGbW3mWy8AYskyNRKIhEOXpJPj6QIqIE9MCm6OGIvuQoW8Oh5sTAd2JI9kuDylbNbsWb
UqPzOUEIf3w8HM9nPLXcIKg93cwTJ94G8F9I/z8AXfl4e9mB4+hY9pbn4eiALQShD/ePELZRwl+8Qfvs
D3IAZ1ZLJY2ppAr0r+49RmjelIFuXexRnWER3b3HCAq6CPTvoIuYyok2W18FAfSTaPPLnZ3P2CHPU+93
G8l+TPeNcEWFmGAmnTjXbZzbIn3uahTliMqiOYAw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
"/assets/vendor": {
isDir: true,
local: "assets/vendor",

BIN
assets/img/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@ -36,3 +36,7 @@ func handleRssFeed(w http.ResponseWriter, req *http.Request) {
}
fmt.Fprint(w, v)
}
func buildRssFeed(uid string) (string, error) {
return "", nil
}

View File

@ -21,16 +21,22 @@ func handleUserRequest(w http.ResponseWriter, req *http.Request) {
if !page.LoggedIn {
page.SubTitle = "ribbit login"
page.show("login.html", w)
page.show("login.html")
return
}
page.SubTitle = "dashboard"
page.show("user_dashboard.html", w)
switch f {
case "feeds":
handleUserFeeds(page)
case "updatesubscriptions":
handleUpdateUserSubs(page)
default:
handleUserDashboard(page)
}
}
func handleUserLoginForm(page *pageData) {
page.SubTitle = "ribbit login"
page.show("login.html", page.session.w)
page.show("login.html")
}
func handleUserLogin(page *pageData) {
@ -61,9 +67,59 @@ func handleUserLogin(page *pageData) {
// doLogin attempts to log in with the given email/password
// If it can't, it returns an error
func doLogin(uid, password string) error {
fmt.Println("Doing Login", uid, password)
if strings.TrimSpace(uid) != "" && strings.TrimSpace(password) != "" {
return m.checkCredentials(uid, password)
}
return errors.New("Invalid Credentials")
}
func handleUserDashboard(page *pageData) {
page.SubTitle = "dashboard"
page.show("user_dashboard.html")
}
func handleUserFeeds(page *pageData) {
page.SubTitle = "feeds"
type feedsPageData struct {
User *User
FeedSources []FeedSource
}
fpd := new(feedsPageData)
fpd.FeedSources = m.FeedSources
id, err := page.session.getStringValue("id")
if err != nil {
userError(page.session.w)
return
}
fpd.User, err = m.GetUser(id)
if err != nil {
userError(page.session.w)
return
}
page.TemplateData = fpd
page.show("user_feeds.html")
}
func handleUpdateUserSubs(page *pageData) {
subs := page.session.req.FormValue("user_feeds")
fmt.Println(subs)
subPts := strings.Split(subs, ",")
var userSubs []string
for i := range subPts {
subPts[i] = strings.TrimSpace(subPts[i])
if subPts[i] != "" {
userSubs = append(userSubs, subPts[i])
}
}
id, err := page.session.getStringValue("id")
if err != nil {
userError(page.session.w)
return
}
var u *User
u, err = m.GetUser(id)
u.SubSlugs = userSubs
m.SaveUser(u)
redirect("/user/dashboard", page.session.w, page.session.req)
}

61
main.go
View File

@ -6,10 +6,12 @@ import (
"bufio"
"fmt"
"html/template"
"io/ioutil"
"log"
"net/http"
"os"
"os/signal"
"plugin"
"strconv"
"strings"
"syscall"
@ -24,25 +26,6 @@ import (
const AppName = "ribbit"
const DbName = AppName + ".db"
// pageData is stuff that changes per request
type pageData struct {
Site *SiteData
Title string
SubTitle string
Stylesheets []string
HeaderScripts []string
Scripts []string
FlashMessage string
FlashClass string
LoggedIn bool
IsAdmin bool
Menu []menuItem
BottomMenu []menuItem
session *pageSession
TemplateData interface{}
}
type menuItem struct {
Label string
Location string
@ -130,10 +113,6 @@ func main() {
log.Fatal(http.ListenAndServe("127.0.0.1:"+strconv.Itoa(m.Site.Port), chain))
}
func buildRssFeed(uid string) (string, error) {
return uid, nil
}
func loggingHandler(h http.Handler) http.Handler {
return handlers.LoggingHandler(os.Stdout, h)
}
@ -193,22 +172,6 @@ func initPageData(w http.ResponseWriter, req *http.Request) *pageData {
return p
}
func (p *pageData) show(tmplName string, w http.ResponseWriter) error {
for _, tmpl := range []string{
"htmlheader.html",
"header.html",
tmplName,
"footer.html",
"htmlfooter.html",
} {
if err := outputTemplate(tmpl, p, w); err != nil {
fmt.Printf("%s\n", err)
return err
}
}
return nil
}
func outputTemplate(tmplName string, tmplData interface{}, w http.ResponseWriter) error {
n := "/templates/" + tmplName
l := template.Must(template.New("layout").Parse(FSMustString(m.Site.DevMode, n)))
@ -272,4 +235,24 @@ func initialize() {
m.Site.sessionSecret = sessSc
assertError(m.Site.SaveToDB())
}
// Load Feed Sources from Plugins
files, err := ioutil.ReadDir("./plugins/")
if err != nil {
log.Fatal(err)
}
for _, f := range files {
fmt.Print("Loading plugin ", f.Name(), "...")
p, err := plugin.Open("./plugins/" + f.Name())
if err != nil {
panic(err)
}
var feedSource *FeedSource
if feedSource, err = LoadFeedPlugin(p); err != nil {
fmt.Println(" ", err.Error())
continue
}
m.FeedSources = append(m.FeedSources, *feedSource)
fmt.Printf("Done. (%d feeds)\n", len(feedSource.Feeds))
}
}

View File

@ -13,8 +13,9 @@ type model struct {
bolt *boltease.DB
dbFileName string
Users []User
Feeds []Feed
Users []User
FeedSources []FeedSource
Feeds []Feed
Site *SiteData
}

View File

@ -1,9 +1,77 @@
package main
import (
"plugin"
"time"
)
type FeedSource struct {
Feeds []*Feed
// Plugin Functions
getSourceName func() string
refreshFeedList func() []map[string]string
getFeedUrl func(string, time.Time) (string, error)
getFeedDesc func(string, time.Time) (string, error)
}
func LoadFeedPlugin(p *plugin.Plugin) (*FeedSource, error) {
ret := new(FeedSource)
feedSourceSymbol, err := p.Lookup("GetSourceName")
if err != nil {
return nil, err
}
ret.getSourceName = feedSourceSymbol.(func() string)
feedListSymbol, err := p.Lookup("GetFeedList")
if err != nil {
return nil, err
}
ret.refreshFeedList = feedListSymbol.(func() []map[string]string)
feeds := ret.refreshFeedList()
// `feeds` is a []map, each map should contain keys: `slug`, `name`, `author`, `source`
for _, f := range feeds {
var slug, name, author, source string
var ok bool
if slug, ok = f["slug"]; !ok {
continue
}
if name, ok = f["name"]; !ok {
continue
}
if author, ok = f["author"]; !ok {
continue
}
if source, ok = f["source"]; !ok {
continue
}
ret.Feeds = append(ret.Feeds, NewFeed(slug, name, author, source))
}
feedUrlSymbol, err := p.Lookup("GetFeedUrl")
if err != nil {
return nil, err
}
ret.getFeedUrl = feedUrlSymbol.(func(string, time.Time) (string, error))
feedDescSymbol, err := p.Lookup("GetFeedDesc")
if err != nil {
return nil, err
}
ret.getFeedDesc = feedDescSymbol.(func(string, time.Time) (string, error))
return ret, nil
}
func (f *FeedSource) getFeed(slug string) *Feed {
for i := range f.Feeds {
if f.Feeds[i].Slug == slug {
return f.Feeds[i]
}
}
return nil
}
type Feed struct {
Name string
Author string

40
page_data.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"fmt"
)
// pageData is stuff that changes per request
type pageData struct {
Site *SiteData
Title string
SubTitle string
Stylesheets []string
HeaderScripts []string
Scripts []string
FlashMessage string
FlashClass string
LoggedIn bool
IsAdmin bool
Menu []menuItem
BottomMenu []menuItem
session *pageSession
TemplateData interface{}
}
func (p *pageData) show(tmplName string) error {
for _, tmpl := range []string{
"htmlheader.html",
"header.html",
tmplName,
"footer.html",
"htmlfooter.html",
} {
if err := outputTemplate(tmpl, p, p.session.w); err != nil {
fmt.Printf("%s\n", err)
return err
}
}
return nil
}

View File

@ -2,8 +2,6 @@ package main
import (
"C"
)
import (
"errors"
"fmt"
"net/http"
@ -12,43 +10,36 @@ import (
"github.com/PuerkitoBio/goquery"
)
func getFeedList() []Feed {
var ret []Feed
ret = append(ret, *NewFeed("dilbert", "Dilbert", "Scott Adams", "dilbert"))
func GetSourceName() string {
return "dilbert"
}
func GetFeedList() []map[string]string {
var ret []map[string]string
feedMap := make(map[string]string)
feedMap["slug"] = "dilbert"
feedMap["name"] = "Dilbert"
feedMap["author"] = "Scott Adams"
feedMap["source"] = GetSourceName()
ret = append(ret, feedMap)
return ret
}
func getRssItem(slug string) (string, error) {
desc, err := getFeedDesc(time.Now())
if err != nil {
return "", err
}
feed, err := m.GetFeed(SRC_DILBERT, slug)
if err != nil {
return "", err
}
desc = "<![CDATA[" + desc + "]]>"
ret := " <item>\n"
ret += " <title>" + feed.Name + "</title>\n"
ret += " <pubDate>" + feed.LastUpdate.Format(time.RFC1123Z) + "</pubDate>\n"
ret += " <guid>dilbert;" + slug + ";" + feed.LastUpdate.Format(time.RFC1123Z) + "</guid>\n"
ret += " <link>" + getFeedUrl(time.Now()) + "</link>\n"
ret += " <description>" + desc + "</description>\n"
ret += " </item>\n"
return ret, nil
}
func getFeedUrl(date time.Time) string {
func GetFeedUrl(slug string, date time.Time) (string, error) {
return fmt.Sprintf(
"http://dilbert.com/strip/%4d-%02d-%02d",
date.Year(),
date.Month(),
date.Day(),
)
), nil
}
func getFeedDesc(date time.Time) (string, error) {
res, err := http.Get(getFeedUrl(date))
func GetFeedDesc(slug string, date time.Time) (string, error) {
url, err := GetFeedUrl(slug, date)
if err != nil {
return "", err
}
res, err := http.Get(url)
if err != nil {
return "", err
}

View File

@ -11,8 +11,12 @@ import (
"github.com/PuerkitoBio/goquery"
)
func downloadList() {
var ret []Feed
func GetSourceName() string {
return "gocomics"
}
func GetFeedList() []map[string]string {
var ret []map[string]string
lstUrl := "http://www.gocomics.com/comics/a-to-z"
res, err := http.Get(lstUrl)
if err != nil {
@ -48,44 +52,33 @@ func downloadList() {
}
author = strings.TrimPrefix(author, "By ")
author = strings.Replace(author, "\u0026", "&", -1)
ret = append(ret, *NewFeed(slug, name, author, "gocomics"))
feedMap := make(map[string]string)
feedMap["slug"] = slug
feedMap["name"] = name
feedMap["author"] = author
feedMap["source"] = GetSourceName()
ret = append(ret, feedMap)
}
})
return ret
}
func getRssItem(slug string) (string, error) {
desc, err := getFeedDesc(slug, time.Now())
if err != nil {
return "", err
}
comic, err := m.GetComic(SRC_GOCOMICS, slug)
if err != nil {
return "", err
}
desc = "<![CDATA[" + desc + "]]>"
ret := " <item>\n"
ret += " <title>" + comic.Name + "</title>\n"
ret += " <pubDate>" + comic.LastUpdate.Format(time.RFC1123Z) + "</pubDate>\n"
ret += " <guid>gocomics;" + slug + ";" + comic.LastUpdate.Format(time.RFC1123Z) + "</guid>\n"
ret += " <link>" + getGoComicsComicUrl(slug, time.Now()) + "</link>\n"
ret += " <description>" + desc + "</description>\n"
ret += " </item>\n"
return ret, nil
}
func getFeedUrl(slug string, date time.Time) string {
func GetFeedUrl(slug string, date time.Time) (string, error) {
return fmt.Sprintf(
"http://www.gocomics.com/%s/%04d/%02d/%02d",
slug,
date.Year(),
date.Month(),
date.Day(),
)
), nil
}
func getFeedDesc(slug string, date time.Time) (string, error) {
res, err := http.Get(getFeedUrl(slug, date))
func GetFeedDesc(slug string, date time.Time) (string, error) {
url, err := GetFeedUrl(slug, date)
if err != nil {
return "", err
}
res, err := http.Get(url)
if err != nil {
return "", err
}

View File

@ -10,12 +10,22 @@ import (
"github.com/PuerkitoBio/goquery"
)
func getFeedList() []Feed {
var ret []Feed
ret = append(ret, *NewFeed("xkcd", "XKCD", "Randall Munroe", "xkcd"))
func GetSourceName() string {
return "xkcd"
}
func GetFeedList() []map[string]string {
var ret []map[string]string
feedMap := make(map[string]string)
feedMap["slug"] = "xkcd"
feedMap["name"] = "XKCD"
feedMap["author"] = "Randall Munroe"
feedMap["source"] = GetSourceName()
ret = append(ret, feedMap)
return ret
}
/*
func getRssItem(slug string) (string, error) {
desc, err := getFeedDesc(time.Now())
if err != nil {
@ -35,8 +45,9 @@ func getRssItem(slug string) (string, error) {
ret += " </item>\n"
return ret, nil
}
*/
func getFeedUrl(date time.Time) (string, error) {
func GetFeedUrl(slug string, dt time.Time) (string, error) {
var isComicDay = func(dt time.Time) bool {
return dt.Weekday() == time.Monday || dt.Weekday() == time.Wednesday || dt.Weekday() == time.Friday
}
@ -54,8 +65,13 @@ func getFeedUrl(date time.Time) (string, error) {
return fmt.Sprintf("https://xkcd.com/%d", num), nil
}
func getFeedDesc(date time.Time) (string, error) {
res, err := http.Get(getUrl(date))
func GetFeedDesc(slug string, dt time.Time) (string, error) {
var url string
var err error
if url, err = GetFeedUrl(slug, dt); err != nil {
return "", err
}
res, err := http.Get(url)
if err != nil {
return "", err
}

BIN
plugins/plugin_dilbert.so Normal file

Binary file not shown.

BIN
plugins/plugin_gocomics.so Normal file

Binary file not shown.

BIN
plugins/plugin_xkcd.so Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
<a href="/user/feeds">Edit Subscriptions</a>

135
templates/user_feeds.html Normal file
View File

@ -0,0 +1,135 @@
<div id="all_sources_container"></div>
<form name="feed_subscriptions" action="/user/updatesubscriptions" onsubmit="updateSubscriptionValue()">
<input id="user_feeds" type="hidden" name="user_feeds" value="" />
<button type="submit">Save</button>
</form>
<script>
var user_feeds = [
{{ range $i, $v := .TemplateData.User.SubSlugs }}
"{{$v}}",
{{ end }}
];
var all_feeds = [
{{ range $i, $v := .TemplateData.FeedSources }}
{{ range $vi, $vf := $v.Feeds }}
{
"name": "{{$vf.Name}}",
"author": "{{$vf.Author}}",
"slug": "{{$vf.Slug}}",
"source": "{{$vf.Source}}",
"desc": "{{$vf.Desc}}",
"last_update": "{{$vf.LastUpdate}}"
},
{{ end }}
{{ end }}
];
function init() {
var sourcesContainer = document.getElementById("all_sources_container");
var sources = [];
for(var i = 0; i < all_feeds.length; i++) {
if(sources.indexOf(all_feeds[i].source) < 0) {
sources.push(all_feeds[i].source)
}
}
for(var i = 0; i < sources.length; i++) {
sourcesContainer.appendChild(createFeedSourceTable(sources[i]));
}
}
function createFeedSourceTable(source) {
var sourceContainer = document.createElement("div");
var sourceTitle = document.createElement("h1");
sourceTitle.innerText = source+" ";
sourceContainer.appendChild(sourceTitle);
var table = document.createElement("table");
table.classList.add("pure-table","pure-table-bordered","center-all","hidden");
var thead = document.createElement("thead");
var thtr = document.createElement("tr");
var thChk = document.createElement("th");
var thn = document.createElement("th");
thn.innerText = "Name";
var tha = document.createElement("th");
tha.innerText = "Author";
var thl = document.createElement("th");
thl.innerText = "Last Update";
thtr.appendChild(document.createElement("th"));
for(var i = 0; i < all_feeds.length; i++) {
if(all_feeds[i].source == source) {
table.appendChild(createFeedTableRow(all_feeds[i]));
}
}
sourceContainer.appendChild(table);
var sourceShow = document.createElement("a");
sourceShow.style["color"] = "blue";
sourceShow.style["cursor"] = "pointer";
sourceShow.innerText = "v";
sourceShow.onclick = function() {
if(table.classList.contains("hidden")) {
sourceShow.innerText = "^";
} else {
sourceShow.innerText = "v";
}
table.classList.toggle("hidden");
}
sourceTitle.appendChild(sourceShow);
sourceContainer.style["margin-bottom"] = "2em";
return sourceContainer;
}
function createFeedTableRow(feedItem) {
var row = document.createElement("tr");
var chkCell = document.createElement("td");
var chkBox = document.createElement("input");
chkBox.setAttribute("type", "checkbox");
chkBox.setAttribute("data-slug", feedItem["source"]+";"+feedItem["slug"]);
chkBox.onclick = function() {
toggleSubscription(this.getAttribute("data-slug"));
}
if(user_feeds.indexOf(feedItem["source"]+";"+feedItem["slug"]) >= 0) {
chkBox.checked = true;
}
chkCell.append(chkBox);
row.append(chkCell);
var nameCell = document.createElement("td");
nameCell.innerText = feedItem["name"];
row.append(nameCell);
var authCell = document.createElement("td");
authCell.innerText = feedItem["author"];
row.append(authCell);
var updCell = document.createElement("td");
updCell.innerText = feedItem["last_update"];
row.append(updCell);
return row;
}
function toggleSubscription(slug) {
if(user_feeds.indexOf(slug) >= 0) {
user_feeds.splice(user_feeds.indexOf(slug), 1);
} else {
user_feeds.push(slug);
}
updateSubscriptionValue();
}
function getSubRow(slug) {
return document.getElementById("row_"+slug.replace(";","_"));
}
function updateSubscriptionTable() {
for(var i = 0; i < user_feeds.length; i++) {
var row = getSubRow(user_feeds[i]);
if(row) {
row.getElementsByTagName("input")[0].checked = true;
}
}
}
function updateSubscriptionValue() {
document.getElementById("user_feeds").value = user_feeds;
}
init();
updateSubscriptionTable();
</script>