commit 2143cc393c70eb5babb0f20cd626b5fd9ebb98f6
parent 4659b4f8b7784c7e365714a1dace43d44adcd22c
Author: Peter Kosyh <p.kosyh@gmail.com>
Date: Sat, 30 Jan 2021 21:37:31 +0000
Merge branch 'master' of https://github.com/gl00my/ii-go
Diffstat:
14 files changed, 113 insertions(+), 65 deletions(-)
diff --git a/ii-node/lib/style.css b/ii-node/lib/style.css
@@ -174,6 +174,7 @@ body {
#topic .subj a, #topic .subj a:hover, #topic .subj a:visited {
color: #000000;
font-size: large;
+ font-weight: bold;
text-decoration: none;
}
#topic .reply a, #topic .reply a:hover, #topic .reply a:visited {
@@ -256,6 +257,14 @@ body {
image-rendering: pixelated;
}
+.more {
+ color: black;
+ color: #ea5555;
+ text-decoration: underline;
+ font-weight: bold;
+ font-size: smaller;
+}
+
.avatar {
width: 4em;
float: left;
diff --git a/ii-node/tpl/edit.tpl b/ii-node/tpl/edit.tpl
@@ -2,7 +2,7 @@
{{ $msg := index .Msg 0 }}
{{ with $msg }}
<table id="edit">
-<form method="post" enctype="application/x-www-form-urlencoded" action="/{{.MsgId}}/edit">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{$.PfxPath}}/{{.MsgId}}/edit">
<tr><td class="odd">
<input type="hidden" name="id" value="{{.MsgId}}">
<input type="hidden" name="repto" value="{{ . | repto}}">
diff --git a/ii-node/tpl/header.tpl b/ii-node/tpl/header.tpl
@@ -6,7 +6,8 @@
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link rel="icon" href="/lib/icon.png" type="image/png">
<link rel="stylesheet" type="text/css" href="/lib/style.css">
-{{ if eq .Template "query.tpl" }}<link href="/{{.BasePath}}/rss" type="application/rss+xml" rel="alternate" title="{{.Sysname}} {{.BasePath}} :: Atom feed" />{{ end }}
+{{ if eq .Template "query.tpl" }}<link href="{{.PfxPath}}/{{.BasePath}}/rss" type="application/rss+xml" rel="alternate" title="{{.Sysname}} {{.BasePath}} :: RSS feed" />{{ end }}
+{{ if eq .Template "blog.tpl" }}<link href="{{.PfxPath}}/{{.BasePath}}+topics/rss" type="application/rss+xml" rel="alternate" title="{{.Sysname}} {{.BasePath}} :: RSS feed" />{{ end }}
<title>{{.Sysname}}</title>
</head>
@@ -15,13 +16,13 @@
<table id="header">
<tr>
<td class="title">
- <span class="logo"><a href="/"><img class="logo" src="/lib/icon.png">{{.Sysname}}</a></span>
- {{ if eq .BasePath "" }}
- <span class="info">II/IDEC networks :: <a href="/echo/all">New posts</a>
- {{ else if gt (len .Topics) 0}}
- <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="/echo/{{.}}">{{.}}</a> :: <span class="info">{{index $.Echolist.Info .}}</span>{{end}}
+ <span class="logo"><a href="{{$.PfxPath}}/"><img class="logo" src="/lib/icon.png">{{.Sysname}}</a></span>
+{{ if eq .BasePath "" }}
+ <span class="info">II/IDEC networks :: <a href="{{ $.PfxPath }}/echo/all">New posts</a>
+{{ else if gt (len .Topics) 0}}
+ <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="{{$.PfxPath}}/echo/{{.}}">{{.}}</a> :: <span class="info">{{index $.Echolist.Info .}}</span>{{end}}
{{ else }}
- <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="/{{.}}">{{.}}</a> :: <span class="info">{{index $.Echolist.Info .}}</span>{{end}}
+ <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="{{$.PfxPath}}/{{.}}">{{.}}</a> :: <span class="info">{{index $.Echolist.Info .}}</span>{{end}}
{{ end }}
</span>
</td>
@@ -30,23 +31,23 @@
{{ template "links.tpl" }}
{{ if .User.Name }}
{{ if eq .BasePath "profile" }}
- <a href="/logout">Logout</a>
+ <a href="{{$.PfxPath}}/logout">Logout</a>
{{ else }}
- <a href="/profile">{{.User.Name}}</a>
+ <a href="{{$.PfxPath}}/profile">{{.User.Name}}</a>
{{ end }}
{{ with .Echo }}
{{ if $.Topic }}
- :: <a href="/{{$.Topic}}/reply/new">New</a>
+ :: <a href="{{$.PfxPath}}/{{$.Topic}}/reply/new">New</a>
{{ else }}
- :: <a href="/{{.}}/new">New</a>
+ :: <a href="{{$.PfxPath}}/{{.}}/new">New</a>
{{ end }}
{{ end }}
{{ else if eq .BasePath "login" }}
- <a href="/register">Register</a>
+ <a href="{{$.PfxPath}}/register">Register</a>
{{ else }}
- <a href="/login">Login</a>
+ <a href="{{$.PfxPath}}/login">Login</a>
{{ end }}
</span>
diff --git a/ii-node/tpl/index.tpl b/ii-node/tpl/index.tpl
@@ -12,12 +12,12 @@
{{ else }}
<tr class="odd">
{{ end }}
-<td class="echo"><a href="/{{.Name}}/">{{.Name}}</a><br>
+<td class="echo"><a href="{{$.PfxPath}}/{{.Name}}/">{{.Name}}</a><br>
<span class="info">{{ index $.Echolist.Info .Name }}</span>
</td>
<td class="topics extra">{{.Topics}}</td>
<td class="count extra">{{.Count}}</td>
-<td class="info">{{with .Msg}}<span class="subj">{{.Subj}}</span><br><a href="/echo/{{.Echo}}">{{.Date | fdate}}</a> by {{.From}}{{end}}</td>
+<td class="info">{{with .Msg}}<span class="subj">{{.Subj}}</span><br><a href="{{$.PfxPath}}/echo/{{.Echo}}">{{.Date | fdate}}</a> by {{.From}}{{end}}</td>
</tr>
{{ end }}
</table>
diff --git a/ii-node/tpl/login.tpl b/ii-node/tpl/login.tpl
@@ -1,6 +1,6 @@
{{template "header.tpl" $}}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/login">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{.PfxPath}}/login">
<table id="login" cellspacing=0 cellpadding=0>
<tr class="odd"><td>
diff --git a/ii-node/tpl/new.tpl b/ii-node/tpl/new.tpl
@@ -1,9 +1,9 @@
{{template "header.tpl" $}}
<table id="edit">
{{ if eq .Echo "" }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{.PfxPath}}/new">
{{ else }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/{{.Echo}}/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{.PfxPath}}/{{.Echo}}/new">
{{ end }}
<tr><td class="odd">
{{ if eq .Echo "" }}
diff --git a/ii-node/tpl/pager.tpl b/ii-node/tpl/pager.tpl
@@ -10,7 +10,9 @@ Pages:
{{ if eq . $.Page }}
<span class="selected">{{.}}</span>
{{ else }}
-<a href="/{{$.BasePath}}/{{.}}">{{.}}</a>
+
+<a href="{{$.PfxPath}}/{{$.BasePath}}/{{.}}">{{.}}</a>
+
{{ end }}
{{ end }}
</div>
diff --git a/ii-node/tpl/preview.tpl b/ii-node/tpl/preview.tpl
@@ -16,9 +16,9 @@
<table id="edit">
{{ if eq $.Echo "" }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{$.PfxPath}}/new">
{{ else }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/{{.Echo}}/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{$.PfxPath}}/{{.Echo}}/new">
{{ end }}
<tr><td class="even">
{{ if eq $.Echo "" }}
diff --git a/ii-node/tpl/profile.tpl b/ii-node/tpl/profile.tpl
@@ -6,11 +6,11 @@
<tr class="even"><td>Auth:</td><td>{{.User.Secret}}</td></tr>
<tr class="odd"><td>e-mail:</td><td>{{.User.Mail}}</td></tr>
<tr class="even"><td>Addr:</td><td>{{.Selected}}</td></tr>
-<tr class="odd"><td class="links" colspan="2"><a href="/from/{{.User.Name}}">/from/{{.User.Name}}</a> :: <a href="/to/{{.User.Name}}">/to/{{.User.Name}}</a>
+<tr class="odd"><td class="links" colspan="2"><a href="{{.PfxPath}}/from/{{.User.Name}}">/from/{{.User.Name}}</a> :: <a href="{{.PfxPath}}/to/{{.User.Name}}">/to/{{.User.Name}}</a>
</td></tr>
<tr><td class="even" colspan="2">
-<form method="post" enctype="application/x-www-form-urlencoded" action="/avatar/{{.User.Name}}">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{.PfxPath}}/avatar/{{.User.Name}}">
<textarea type="text" name="avatar" class="message" cols=60 row=16 placeholder="Add XPM avatar here">{{.Info}}</textarea>
</td></tr>
<tr><td class="odd center" colspan="2">
diff --git a/ii-node/tpl/query.tpl b/ii-node/tpl/query.tpl
@@ -1,25 +1,25 @@
{{template "header.tpl" $}}
{{template "pager.tpl" $}}
-<a class="rss" href="/{{.BasePath}}/rss">RSS</a>
+<a class="rss" href="{{.PfxPath}}/{{.BasePath}}/rss">RSS</a>
<div id="topic">
{{ range .Msg }}
<div class="msg">
{{ if has_avatar .From }}
<img class="avatar" src="/avatar/{{.From}}">
{{ end }}
-<a class="msgid" href="/{{.MsgId}}#{{.MsgId}}">#</a><span class="subj"> <a href="/{{. | repto}}#{{. | repto}}">{{with .Subj}}{{.}}{{else}}No subject{{end}}</a></span><br>
-<span class="echo"><a href="/{{.Echo}}">{{.Echo}}</a></span><br>
+<a class="msgid" href="{{$.PfxPath}}/{{.MsgId}}#{{.MsgId}}">#</a><span class="subj"> <a href="{{$.PfxPath}}/{{. | repto}}#{{. | repto}}">{{with .Subj}}{{.}}{{else}}No subject{{end}}</a></span><br>
+<span class="echo"><a href="{{$.PfxPath}}/{{.Echo}}">{{.Echo}}</a></span><br>
<span class="info">{{.From}}({{.Addr}}) — {{.To}}<br>{{.Date | fdate}}</span><br>
<div class="text">
<br>
-{{. | msg_text}}
+{{ msg_text . }}
<br>
{{if $.User.Name}}
-<span class="reply"><a href="/{{.MsgId}}/reply/new">Reply</a> :: </span>
-<span class="reply"><a href="/{{.MsgId}}/reply">Quote</a></span>
+<span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/reply/new">Reply</a> :: </span>
+<span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/reply">Quote</a></span>
{{end}}
{{ if msg_access . $.User }}
- :: <span class="reply"><a href="/{{.MsgId}}/edit">Edit</a></span>
+ :: <span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/edit">Edit</a></span>
{{ end }}
{{if $.User.Name}}
<br>
diff --git a/ii-node/tpl/reply.tpl b/ii-node/tpl/reply.tpl
@@ -1,7 +1,7 @@
{{template "header.tpl" $}}
<table id="edit">
{{ with index .Msg 0 }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/{{.Echo}}/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{$.PfxPath}}/{{.Echo}}/new">
<tr><td class="odd">
<input type="text" name="to" class="to" placeholder="{{.To}}" value="{{.To}}"><br>
<input type="text" name="subj" class="subj" placeholder="{{.Subj}}" value="{{.Subj}}"><br>
diff --git a/ii-node/tpl/topic.tpl b/ii-node/tpl/topic.tpl
@@ -11,18 +11,18 @@
{{ if has_avatar .From }}
<img class="avatar" src="/avatar/{{.From}}">
{{ end }}
-<a class="msgid" href="/{{.MsgId}}#{{.MsgId}}">#</a><span class="subj"> <a href="/{{. | repto}}#{{. | repto}}">{{with .Subj}}{{.}}{{else}}No subject{{end}}</a></span><br>
-<span class="info"><a href="/from/{{.From}}">{{.From}}</a>({{.Addr}}) — {{.To}}<br>{{.Date | fdate}}</span><br>
+<a class="msgid" href="{{$.PfxPath}}/{{.MsgId}}#{{.MsgId}}">#</a><span class="subj"> <a href="{{$.PfxPath}}/{{. | repto}}#{{. | repto}}">{{with .Subj}}{{.}}{{else}}No subject{{end}}</a></span><br>
+<span class="info"><a href="{{$.PfxPath}}/from/{{.From}}">{{.From}}</a>({{.Addr}}) — {{.To}}<br>{{.Date | fdate}}</span><br>
<div class="text">
<br>
{{. | msg_text}}
<br>
{{if $.User.Name}}
-<span class="reply"><a href="/{{.MsgId}}/reply/new">Reply</a> :: </span>
-<span class="reply"><a href="/{{.MsgId}}/reply">Quote</a></span>
+<span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/reply/new">Reply</a> :: </span>
+<span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/reply">Quote</a></span>
{{end}}
{{ if msg_access . $.User }}
- :: <span class="reply"><a href="/{{.MsgId}}/edit">Edit</a></span>
+ :: <span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/edit">Edit</a></span>
{{ end }}
{{if $.User.Name}}
<br>
diff --git a/ii-node/web.go b/ii-node/web.go
@@ -25,6 +25,7 @@ type WebContext struct {
Msg []*ii.Msg
Error string
Echo string
+ PfxPath string
Page int
Pages int
Pager []int
@@ -66,7 +67,7 @@ func www_register(ctx *WebContext, w http.ResponseWriter, r *http.Request) error
ii.Info.Printf("Can not edit user %s: %s", ctx.User.Name, err)
return err
}
- http.Redirect(w, r, "/login", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/login", http.StatusSeeOther)
return nil
}
user := r.FormValue("username")
@@ -79,7 +80,7 @@ func www_register(ctx *WebContext, w http.ResponseWriter, r *http.Request) error
return err
}
ii.Info.Printf("Registered user: %s", user)
- http.Redirect(w, r, "/login", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/login", http.StatusSeeOther)
default:
return nil
}
@@ -109,7 +110,7 @@ func www_login(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
cookie := http.Cookie{Name: "pauth", Value: udb.Secret(user), Expires: exp}
http.SetCookie(w, &cookie)
ii.Info.Printf("User logged in: %s\n", user)
- http.Redirect(w, r, "/", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/", http.StatusSeeOther)
return nil
}
return errors.New("Wrong method")
@@ -141,7 +142,7 @@ func www_logout(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
}
cookie := http.Cookie{Name: "pauth", Value: "", Expires: time.Unix(0, 0)}
http.SetCookie(w, &cookie)
- http.Redirect(w, r, "/", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/", http.StatusSeeOther)
return nil
}
@@ -272,7 +273,7 @@ func www_avatar(ctx *WebContext, w http.ResponseWriter, r *http.Request, user st
ii.Error.Printf("Error saving avatar: " + user)
return errors.New("Error saving avatar")
}
- http.Redirect(w, r, "/profile", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/profile", http.StatusSeeOther)
return nil
}
// var id int32
@@ -407,7 +408,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que
fmt.Fprintf(w,
`<item><title>%s</title><guid>%s</guid><pubDate>%s</pubDate><author>%s</author><link>%s/%s</link>
<description>
- %s
+ %s...
</description>
<content:encoded>
<![CDATA[
@@ -417,7 +418,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que
</content:encoded></item>
`,
str_esc(m.Subj), m.MsgId, time.Unix(m.Date, 0).Format("2006-01-02 15:04:05"),
- str_esc(m.From), ctx.www.Host, m.MsgId,
+ str_esc(m.From), ctx.www.Host + ctx.PfxPath, m.MsgId,
str_esc(trunc(m.Text, 280)),
fmt.Sprintf("%s -> %s<br><br>", m.From, m.To),
msg_text(m))
@@ -432,8 +433,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que
func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page int) error {
db := ctx.www.db
- echo := ctx.BasePath
- ctx.Echo = echo
+ echo := ctx.Echo
mis := db.LookupIDS(Select(ctx, ii.Query{Echo: echo}))
ii.Trace.Printf("www topics: %s", echo)
topicsIds := db.GetTopics(mis)
@@ -447,18 +447,20 @@ func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page in
topic := Topic{}
topic.Ids = t
topic.Count = len(topic.Ids) - 1
- topic.Last = db.LookupFast(topic.Ids[topic.Count], false)
+ if ctx.PfxPath == "/blog" {
+ topic.Last = db.LookupFast(topic.Ids[0], false)
+ } else {
+ topic.Last = db.LookupFast(topic.Ids[topic.Count], false)
+ }
if topic.Last == nil {
ii.Error.Printf("Skip wrong message: %s\n", t[0])
continue
}
topics = append(topics, &topic)
}
-
sort.SliceStable(topics, func(i, j int) bool {
return topics[i].Last.Num > topics[j].Last.Num
})
- ctx.BasePath = echo
tcount := len(topics)
start := makePager(ctx, tcount, page)
nr := PAGE_SIZE
@@ -474,6 +476,12 @@ func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page in
nr--
}
ii.Trace.Printf("Stop to generate topics")
+
+ if ctx.PfxPath == "/blog" {
+ ctx.Template = "blog.tpl"
+ err := ctx.www.tpl.ExecuteTemplate(w, "blog.tpl", ctx)
+ return err
+ }
ctx.Template = "topics.tpl"
err := ctx.www.tpl.ExecuteTemplate(w, "topics.tpl", ctx)
return err
@@ -495,6 +503,9 @@ func www_topic(ctx *WebContext, w http.ResponseWriter, r *http.Request, page int
topic := mi.Id
for p := mi; p != nil; p = db.LookupFast(p.Repto, false) {
+ if p.Repto == p.Id {
+ break
+ }
if p.Echo != mi.Echo {
continue
}
@@ -548,7 +559,7 @@ func www_blacklist(ctx *WebContext, w http.ResponseWriter, r *http.Request) erro
ii.Error.Printf("Error blacklisting: %s", id)
return err
}
- http.Redirect(w, r, "/", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/", http.StatusSeeOther)
return nil
}
@@ -605,6 +616,9 @@ func www_new(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
msg := r.FormValue("msg")
repto := r.FormValue("repto")
id := r.FormValue("id")
+ if repto == id {
+ repto = ""
+ }
newecho := r.FormValue("echo")
if newecho != "" {
echo = newecho
@@ -646,7 +660,7 @@ func www_new(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
ii.Error.Printf("Error while storig new topic %s: %s", m.MsgId, err)
return err
}
- http.Redirect(w, r, "/"+m.MsgId+"#"+m.MsgId, http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/"+m.MsgId+"#"+m.MsgId, http.StatusSeeOther)
return nil
}
if !edit {
@@ -767,6 +781,10 @@ func msg_esc(l string) string {
}
func msg_text(m *ii.Msg) string {
+ return msg_trunc(m, 0, "")
+}
+
+func msg_trunc(m *ii.Msg, maxlen int, more string) string {
if m == nil {
return ""
}
@@ -834,7 +852,13 @@ func msg_text(m *ii.Msg) string {
} else {
l = msg_esc(l)
}
- f += l + "<br>\n"
+ f += l
+ if maxlen > 0 && len(f) > maxlen {
+ f += more + "<br>\n"
+ break
+ } else {
+ f += "<br>\n"
+ }
}
if pre {
pre = false
@@ -859,6 +883,9 @@ func WebInit(www *WWW) {
"msg_text": func(m *ii.Msg) template.HTML {
return template.HTML(msg_text(m))
},
+ "msg_trunc": func(m *ii.Msg, len int, more string) template.HTML {
+ return template.HTML(msg_trunc(m, len, more))
+ },
"repto": func(m ii.Msg) string {
r, _ := m.Tag("repto")
if r == "" {
@@ -923,22 +950,26 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
args := strings.Split(path, "/")
ctx.Echolist = ctx.www.edb
ctx.Ref = r.Header.Get("Referer")
- if path == "" {
+ if len(args) > 1 && args[0] == "blog" {
+ ctx.PfxPath = "/blog"
+ args = args[1:]
+ }
+ if args[0] == "" {
ctx.BasePath = ""
return www_index(ctx, w, r)
- } else if path == "login" {
+ } else if args[0] == "login" {
ctx.BasePath = "login"
return www_login(ctx, w, r)
- } else if path == "logout" {
+ } else if args[0] == "logout" {
ctx.BasePath = "logout"
return www_logout(ctx, w, r)
- } else if path == "profile" {
+ } else if args[0] == "profile" {
ctx.BasePath = "profile"
return www_profile(ctx, w, r)
- } else if path == "register" {
+ } else if args[0] == "register" {
ctx.BasePath = "register"
return www_register(ctx, w, r)
- } else if path == "reset" {
+ } else if args[0] == "reset" {
ctx.Template = "reset.tpl"
return ctx.www.tpl.ExecuteTemplate(w, "reset.tpl", ctx)
} else if args[0] == "avatar" {
@@ -949,25 +980,21 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
return www_avatar(ctx, w, r, args[1])
} else if ii.IsMsgId(args[0]) {
page := 0
+ ctx.BasePath = args[0]
if len(args) > 1 {
if args[1] == "reply" {
- ctx.BasePath = args[0]
return www_reply(ctx, w, r, !(len(args) > 2 && args[2] == "new"))
} else if args[1] == "edit" {
- ctx.BasePath = args[0]
return www_edit(ctx, w, r)
} else if args[1] == "blacklist" {
- ctx.BasePath = args[0]
return www_blacklist(ctx, w, r)
} else if args[1] == "base64" {
- ctx.BasePath = args[0]
return www_base64(ctx, w, r)
}
fmt.Sscanf(args[1], "%d", &page)
}
- ctx.BasePath = args[0]
return www_topic(ctx, w, r, page)
- } else if path == "new" {
+ } else if args[0] == "new" {
ctx.BasePath = ""
return www_new(ctx, w, r)
} else if args[0] == "to" {
@@ -1028,6 +1055,8 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
return www_query(ctx, w, r, q, page, rss)
} else if ii.IsEcho(args[0]) {
page := 1
+ ctx.Echo = args[0]
+ ctx.BasePath = args[0]
if len(args) > 1 {
if args[1] == "new" {
ctx.BasePath = args[0]
@@ -1035,7 +1064,6 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
}
fmt.Sscanf(args[1], "%d", &page)
}
- ctx.BasePath = args[0]
return www_topics(ctx, w, r, page)
} else {
w.WriteHeader(http.StatusNotFound)
diff --git a/ii/db.go b/ii/db.go
@@ -683,6 +683,9 @@ func (db *DB) GetTopics(mi []*MsgInfo) map[string][]string {
}
var l []*MsgInfo
for p := m; p != nil; p = db.LookupFast(p.Repto, false) {
+ if p.Repto == p.Id { // self answer?
+ break
+ }
if m.Echo != p.Echo {
continue
}
@@ -765,6 +768,11 @@ func (db *DB) _Store(m *Msg, edit bool) error {
if _, ok := db.Idx.Hash[m.MsgId]; ok && !edit { // exist and not edit
return errors.New("Already exists")
}
+ if repto != "" {
+ if _, ok := db.Idx.Hash[repto]; !ok { // repto is absent, we should avoid loops!
+ return errors.New("Wrong repto")
+ }
+ }
fi, err := os.Stat(db.BundlePath())
var off int64
if err == nil {