1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
Former-commit-id: ab33ec4b9e7bae76ca4cc595b5f592ce270e82da [formerly ce5634e48d51105387d3e26507b7defc9054a28b] [formerly d84debd3176eb769221034f5e01aadc0ab70fc42 [formerly 6a6b53ca0a]]
Former-commit-id: baf9031e3fc929802c670c7352d6ba5b104dfeee [formerly 6c3b7c7c0e666e8fac5890e569db8a7ca9929b05]
Former-commit-id: 50d2a8dc179e0f705a21f03283cefcf0ad82f2f0
This commit is contained in:
Zack Scholl 2016-02-10 09:13:21 -05:00
parent 1bb73acaa8
commit 3669e8809b
6 changed files with 28 additions and 28 deletions

24
db.go
View File

@ -33,8 +33,8 @@ func Close() {
db.Close() db.Close()
} }
// CowyoData is data for storing in DB // WikiData is data for storing in DB
type CowyoData struct { type WikiData struct {
Title string Title string
CurrentText string CurrentText string
Diffs []string Diffs []string
@ -58,7 +58,7 @@ func hasPassword(title string) (bool, error) {
if val == nil { if val == nil {
return nil return nil
} }
var p CowyoData var p WikiData
err = p.decode(val) err = p.decode(val)
if err != nil { if err != nil {
return err return err
@ -71,7 +71,7 @@ func hasPassword(title string) (bool, error) {
return nil return nil
}) })
if err != nil { if err != nil {
fmt.Printf("Could not get CowyoData: %s", err) fmt.Printf("Could not get WikiData: %s", err)
return false, err return false, err
} }
return hasPassword, nil return hasPassword, nil
@ -96,7 +96,7 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool) {
if val == nil { if val == nil {
return nil return nil
} }
var p CowyoData var p WikiData
err = p.decode(val) err = p.decode(val)
if err != nil { if err != nil {
return err return err
@ -111,12 +111,12 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool) {
return nil return nil
}) })
if err != nil { if err != nil {
fmt.Printf("Could not get CowyoData: %s", err) fmt.Printf("Could not get WikiData: %s", err)
} }
return currentText, vi, isCurrent return currentText, vi, isCurrent
} }
func (p *CowyoData) load(title string) error { func (p *WikiData) load(title string) error {
title = strings.ToLower(title) title = strings.ToLower(title)
if !open { if !open {
return fmt.Errorf("db must be opened before loading!") return fmt.Errorf("db must be opened before loading!")
@ -144,13 +144,13 @@ func (p *CowyoData) load(title string) error {
return nil return nil
}) })
if err != nil { if err != nil {
fmt.Printf("Could not get CowyoData: %s", err) fmt.Printf("Could not get WikiData: %s", err)
return err return err
} }
return nil return nil
} }
func (p *CowyoData) save(newText string) error { func (p *WikiData) save(newText string) error {
if !open { if !open {
return fmt.Errorf("db must be opened before saving") return fmt.Errorf("db must be opened before saving")
} }
@ -168,7 +168,7 @@ func (p *CowyoData) save(newText string) error {
p.Diffs = append(p.Diffs, delta) p.Diffs = append(p.Diffs, delta)
enc, err := p.encode() enc, err := p.encode()
if err != nil { if err != nil {
return fmt.Errorf("could not encode CowyoData: %s", err) return fmt.Errorf("could not encode WikiData: %s", err)
} }
err = bucket.Put([]byte(p.Title), enc) err = bucket.Put([]byte(p.Title), enc)
return err return err
@ -176,7 +176,7 @@ func (p *CowyoData) save(newText string) error {
return err return err
} }
func (p *CowyoData) encode() ([]byte, error) { func (p *WikiData) encode() ([]byte, error) {
enc, err := json.Marshal(p) enc, err := json.Marshal(p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -184,7 +184,7 @@ func (p *CowyoData) encode() ([]byte, error) {
return enc, nil return enc, nil
} }
func (p *CowyoData) decode(data []byte) error { func (p *WikiData) decode(data []byte) error {
err := json.Unmarshal(data, &p) err := json.Unmarshal(data, &p)
if err != nil { if err != nil {
return err return err

16
main.go
View File

@ -11,7 +11,7 @@ import (
) )
// AllowedIPs is a white/black list of // AllowedIPs is a white/black list of
// IP addresses allowed to access cowyo // IP addresses allowed to access awwkoala
var AllowedIPs = map[string]bool{ var AllowedIPs = map[string]bool{
"192.168.1.13": true, "192.168.1.13": true,
"192.168.1.12": true, "192.168.1.12": true,
@ -39,13 +39,13 @@ func main() {
flag.StringVar(&RuntimeArgs.ServerCRT, "crt", "", "location of ssl crt") flag.StringVar(&RuntimeArgs.ServerCRT, "crt", "", "location of ssl crt")
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key") flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key")
flag.CommandLine.Usage = func() { flag.CommandLine.Usage = func() {
fmt.Println(`cowyo: a websocket notepad fmt.Println(`awwkoala: a websocket notepad
run this to start the server and then visit localhost at the port you specify run this to start the server and then visit localhost at the port you specify
(see parameters). (see parameters).
Example: 'cowyo localhost' Example: 'awwkoala localhost'
Example: 'cowyo -p :8080 localhost' Example: 'awwkoala -p :8080 localhost'
Example: 'cowyo -db /var/lib/cowyo/db.bolt localhost' Example: 'awwkoala -db /var/lib/awwkoala/db.bolt localhost'
Example: 'cowyo -p :8080 -crt ssl/server.crt -key ssl/server.key localhost' Example: 'awwkoala -p :8080 -crt ssl/server.crt -key ssl/server.key localhost'
Options:`) Options:`)
flag.CommandLine.PrintDefaults() flag.CommandLine.PrintDefaults()
} }
@ -59,10 +59,10 @@ Options:`)
defer Close() defer Close()
// Default page // Default page
p := CowyoData{"about", about_page, []string{}, []string{}} p := WikiData{"about", about_page, []string{}, []string{}}
p.save(about_page) p.save(about_page)
var q CowyoData var q WikiData
q.load("SpikySeaSlug2") q.load("SpikySeaSlug2")
fmt.Println(getImportantVersions(q)) fmt.Println(getImportantVersions(q))

View File

@ -165,7 +165,7 @@ func renderList(c *gin.Context, title string) {
if strings.ToLower(title) == "about" { //}&& strings.Contains(AllowedIPs, c.ClientIP()) != true { if strings.ToLower(title) == "about" { //}&& strings.Contains(AllowedIPs, c.ClientIP()) != true {
c.Redirect(302, "/about/view") c.Redirect(302, "/about/view")
} }
var p CowyoData var p WikiData
err := p.load(strings.ToLower(title)) err := p.load(strings.ToLower(title))
if err != nil { if err != nil {
panic(err) panic(err)
@ -183,7 +183,7 @@ func deleteListItem(c *gin.Context) {
lineNum, err := strconv.Atoi(c.DefaultQuery("lineNum", "None")) lineNum, err := strconv.Atoi(c.DefaultQuery("lineNum", "None"))
title := c.Query("title") // shortcut for c.Request.URL.Query().Get("lastname") title := c.Query("title") // shortcut for c.Request.URL.Query().Get("lastname")
if err == nil { if err == nil {
var p CowyoData var p WikiData
err := p.load(strings.ToLower(title)) err := p.load(strings.ToLower(title))
if err != nil { if err != nil {
panic(err) panic(err)
@ -225,7 +225,7 @@ func listEverything() string {
b := tx.Bucket([]byte("datas")) b := tx.Bucket([]byte("datas"))
c := b.Cursor() c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() { for k, v := c.First(); k != nil; k, v = c.Next() {
var p CowyoData var p WikiData
p.load(string(k)) p.load(string(k))
if len(p.CurrentText) > 1 { if len(p.CurrentText) > 1 {
contentSize := strconv.Itoa(len(p.CurrentText)) contentSize := strconv.Itoa(len(p.CurrentText))

View File

@ -55,7 +55,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="/">Cowyo</a> <a class="navbar-brand" href="/">Wiki</a>
</div> </div>
<div id="navbar" class="collapse navbar-collapse"> <div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">

File diff suppressed because one or more lines are too long

View File

@ -40,7 +40,7 @@ func wshandler(w http.ResponseWriter, r *http.Request) {
panic(err) panic(err)
} }
var p CowyoData var p WikiData
err = p.load(strings.ToLower(m.Title)) err = p.load(strings.ToLower(m.Title))
if err != nil { if err != nil {
panic(err) panic(err)