diff options
-rw-r--r-- | CacheDatabase.go | 4 | ||||
-rw-r--r-- | Database.go | 4 | ||||
-rw-r--r-- | client.go | 18 | ||||
-rw-r--r-- | main.go | 9 | ||||
-rw-r--r-- | static/catalog.html | 189 | ||||
-rw-r--r-- | static/faq.html | 2 | ||||
-rw-r--r-- | static/main.html | 8 | ||||
-rw-r--r-- | static/manage.html | 10 | ||||
-rw-r--r-- | static/rules.html | 6 |
9 files changed, 229 insertions, 21 deletions
diff --git a/CacheDatabase.go b/CacheDatabase.go index 21c1a8f..26d7d8d 100644 --- a/CacheDatabase.go +++ b/CacheDatabase.go @@ -273,8 +273,12 @@ func GetObjectByIDFromCache(db *sql.DB, postID string) Collection { CheckError(err, "error scan object into post struct cache") + actor = GetRemoteActor(actor.Id) + post.Actor = &actor + nColl.Actor = &actor + // var postCnt int // var imgCnt int post.Replies, _, _ = GetObjectRepliesDB(db, post) diff --git a/Database.go b/Database.go index a64ceb9..d027b43 100644 --- a/Database.go +++ b/Database.go @@ -466,8 +466,12 @@ func GetObjectByIDFromDB(db *sql.DB, postID string) Collection { CheckError(err, "error scan object into post struct") + actor = GetActorFromDB(db, actor.Id) + post.Actor = &actor + nColl.Actor = &actor + // var postCnt int // var imgCnt int post.Replies, _, _ = GetObjectRepliesDB(db, post) @@ -34,6 +34,7 @@ type Board struct{ Domain string TP string Restricted bool + Post ObjectBase } type PageData struct { @@ -85,6 +86,8 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { data.Key = *Key data.Board.Domain = Domain data.Board.ModCred, _ = GetPasswordFromSession(r) + data.Board.Actor = actor + data.Board.Post.Actor = &actor t.ExecuteTemplate(w, "layout", data) } @@ -106,12 +109,14 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co returnData.Board.Summary = actor.Summary returnData.Board.InReplyTo = "" returnData.Board.To = actor.Outbox - returnData.Board.Actor.Id = actor.Id + returnData.Board.Actor = *actor returnData.Board.ModCred, _ = GetPasswordFromSession(r) returnData.Board.Domain = Domain returnData.Board.Restricted = actor.Restricted returnData.CurrentPage = page + returnData.Board.Post.Actor = actor + returnData.Board.Captcha = Domain + "/" + GetRandomCaptcha(db) returnData.Board.CaptchaCode = GetCaptchaCode(returnData.Board.Captcha) @@ -232,13 +237,15 @@ func CatalogGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection C returnData.Board.PrefName = actor.PreferredUsername returnData.Board.InReplyTo = "" returnData.Board.To = actor.Outbox - returnData.Board.Actor.Id = actor.Id + returnData.Board.Actor = *actor returnData.Board.Summary = actor.Summary returnData.Board.ModCred, _ = GetPasswordFromSession(r) returnData.Board.Domain = Domain returnData.Board.Restricted = actor.Restricted returnData.Key = *Key + returnData.Board.Post.Actor = actor + returnData.Board.Captcha = Domain + "/" + GetRandomCaptcha(db) returnData.Board.CaptchaCode = GetCaptchaCode(returnData.Board.Captcha) @@ -276,13 +283,12 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){ returnData.Board.Name = actor.Name returnData.Board.PrefName = actor.PreferredUsername returnData.Board.To = actor.Outbox - returnData.Board.Actor.Id = actor.Id + returnData.Board.Actor = actor returnData.Board.Summary = actor.Summary returnData.Board.ModCred, _ = GetPasswordFromSession(r) returnData.Board.Domain = Domain returnData.Board.Restricted = actor.Restricted - if GetDomainURL(actor) != "" { returnData.Board.Captcha = Domain + "/" + GetRandomCaptcha(db) returnData.Board.CaptchaCode = GetCaptchaCode(returnData.Board.Captcha) @@ -301,6 +307,8 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){ followActors := GetActorsFollowFromName(actor, name) followCollection := GetActorsFollowPostFromId(db, followActors, postId) + returnData.Board.Post.Actor = followCollection.Actor + DeleteRemovedPosts(db, &followCollection) DeleteTombstoneReplies(&followCollection) @@ -318,6 +326,8 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){ returnData.Board.InReplyTo = inReplyTo collection := GetActorCollectionByID(db, inReplyTo) + returnData.Board.Post.Actor = collection.Actor + DeleteRemovedPosts(db, &collection) for i, e := range collection.OrderedItems { @@ -415,7 +415,7 @@ func main() { followActivity.Actor = &nactor followActivity.Object = &obj followActivity.Actor.Id = r.FormValue("actor") - + var mactor Actor followActivity.Object.Actor = &mactor followActivity.Object.Actor.Id = r.FormValue("follow") @@ -496,9 +496,12 @@ func main() { adminData.Title = "Manage /" + actor.Name + "/" adminData.Boards = Boards adminData.Board.Name = actor.Name - adminData.Actor = actor.Id + adminData.Board.Actor = actor adminData.Key = *Key adminData.Board.TP = TP + + adminData.Board.Post.Actor = &actor + t.ExecuteTemplate(w, "layout", adminData) } else if admin || actor.Id == Domain { @@ -529,6 +532,8 @@ func main() { adminData.Board.ModCred,_ = GetPasswordFromSession(r) adminData.Boards = Boards + + adminData.Board.Post.Actor = &actor t.ExecuteTemplate(w, "layout", adminData) } diff --git a/static/catalog.html b/static/catalog.html new file mode 100644 index 0000000..b5b361e --- /dev/null +++ b/static/catalog.html @@ -0,0 +1,189 @@ +<!DOCTYPE html> +<html> + <head> + <title>{{ .Title }}</title> + </head> + <style> + a, a:link, a:visited, a:hover, a:active { + text-decoration: none + } + + a:link, a:visited, a:active { + color: black; + } + + a:hover { + color: #de0808; + } + </style> + <script> + + function getMIMEType(type) + { + re = /\/.+/g + return type.replace(re, "") + } + + function shortURL(url) + { + var check = url.replace("{{.Board.Actor}}/", "") + re = /.+\//g; + temp = re.exec(url) + if(temp[0] == "{{ .Board.Actor }}/") + { + var short = url.replace("https://", ""); + short = short.replace("http://", ""); + short = short.replace("www.", ""); + + var re = /^.{3}/g; + + var u = re.exec(short); + + re = /\w+$/g; + + u = re.exec(short); + + return u; + }else{ + var short = url.replace("https://", ""); + short = short.replace("http://", ""); + short = short.replace("www.", ""); + + var re = /^.{3}/g; + + var u = re.exec(short); + + re = /\w+$/g; + + u = re.exec(short); + + + replace = short.replace(/\/+/g, " ") + replace = replace.replace(u, " ").trim() + re = /\w+$/; + v = re.exec(replace) + + v = "f" + v[0] + "-" + u + + return v; + } + } + + </script> + <body style="background-color: #eef2fe;"> + <ul id="top" style="padding:0; display: inline;"> + {{range .Boards}} + <li style="display: inline;"><a href="{{.Location}}">{{.Name }}</a></li> + {{end}} + </ul> + {{ $board := .Board }} + {{ if $board.IsMod }} + <span style="float: right;"><a href="/{{ .Key }}/{{ .Board.Name }}">[Manage Board]</a></span> + {{ end }} + <div style="margin: 0 auto; width: 400px; margin-bottom: 100px;"> + <h1 style="color: #af0a0f;">/{{ $board.Name }}/ - {{ $board.PrefName }}</h1> + <form id="new-post" action="/post" method="post" enctype="multipart/form-data"> + <label for="name">Name:</label><br> + <input type="text" id="name" name="name" placeholder="Anonymous"><br> + <label for="options">Options:</label><br> + <input type="text" id="options" name="options"><br> + <label for="subject">Subject:</label><br> + <input type="text" id="subject" name="subject"><input type="submit" value="Post"><br> + <label for="comment">Comment:</label><br> + <textarea rows="10" cols="50" id="comment" name="comment"></textarea><br> + <input type="hidden" id="inReplyTo" name="inReplyTo" value="{{ $board.InReplyTo }}"> + <input type="hidden" id="sendTo" name="sendTo" value="{{ $board.To }}"> + <input type="hidden" id="boardName" name="boardName" value="{{ $board.Name }}"> + <input type="hidden" id="captchaCode" name="captchaCode" value="{{ $board.CaptchaCode }}"> + <input type="file" id="file" name="file"><br><br> + <label stye="display: inline-block;" for="captcha">Captcha:</label><br> + <input style="display: inline-block;" type="text" id="captcha" name="captcha"><br> + <div style="height: 65px;"> + <img src="{{ $board.Captcha }}"> + </div> + </form> + </div> + + <hr> + <ul style="margin: 0; padding: 0; display: inline"> + <li style="display: inline"><a href="/{{ $board.Name }}">[Return]</a></li> + <li style="display: inline"><a href="#bottom">[Bottom]</a></li> + <li style="display: inline"><a href="javascript:location.reload()">[Refresh]</a></li> + </ul> + <hr> + + <div style="padding: 10px; text-align: center;"> + {{ range .Posts }} + <div style="overflow: hidden; vertical-align: top; margin: 0 auto; display: inline-block; width: 180px; max-height: 320px; margin-bottom: 10px;"> + {{ if $board.IsMod }} + <a href="/delete?id={{ .Id }}">[Delete Post]</a> + {{ end }} + {{ if .Attachment }} + {{ if $board.IsMod }} + <a href="/deleteattach?id={{ .Id }}">[Delete Attachment]</a> + {{ end }} + <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/"> + <div id="media-{{ .Id }}"></div> + <script> + media = document.getElementById("media-{{ .Id }}") + if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "image"){ + var img = document.createElement("img"); + img.style = "float: left; margin-right: 10px; margin-bottom: 10px; max-width: 150px; max-height: 150px; cursor: move;" + img.setAttribute("id", "img") + img.setAttribute("main", "1") + img.setAttribute("src", "{{ (index .Attachment 0).Href }}") + media.appendChild(img) + } + + if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "audio"){ + var audio = document.createElement("audio") + audio.controls = 'controls' + audio.muted = 'muted' + audio.src = '{{ (index .Attachment 0).Href }}' + audio.type = '{{ (index .Attachment 0).MediaType }}' + audio.style = "float: left; margin-right: 10px; margin-bottom: 10px; width: 150px;" + audio.innerText = 'Audio is not supported.' + media.appendChild(audio) + } + + if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "video"){ + var video = document.createElement("video") + video.controls = 'controls' + video.muted = 'muted' + video.src = '{{ (index .Attachment 0).Href }}' + video.type = '{{ (index .Attachment 0).MediaType }}' + video.style = "float: left; margin-right: 10px; margin-bottom: 10px; width: 150px;" + video.innerText = 'Video is not supported.' + media.appendChild(video) + } + </script> + + + {{ end }} + <div> + {{ $replies := .Replies }} + <span style="display: block">R: {{ $replies.TotalItems }}{{ if $replies.TotalImgs }}/ A: {{ $replies.TotalImgs }}{{ end }}</span> + {{ if .Name }} + <span style="display: block; color: #0f0c5d;"><b>{{ .Name }}</b></span> + {{ end }} + {{ if .Content }} + <span style="display: block">{{.Content}}</span> + {{ end }} + </div> + </a> + </div> + <script> + document.getElementById("{{ .Id }}-anchor").href = "/{{ $board.Name }}/" + shortURL("{{ .Id }}") + </script> + {{ end }} + </div> + <hr> + <ul style="margin: 0; padding: 0; display: inline"> + <li style="display: inline"><a href="/{{ $board.Name }}">[Return]</a></li> + <li style="display: inline"><a id="bottom" href="#top">[Top]</a></li> + <li style="display: inline"><a href="javascript:location.reload()">[Refresh]</a></li> + </ul> + <hr> + </body> +</html> + diff --git a/static/faq.html b/static/faq.html index 2b81e43..66c053d 100644 --- a/static/faq.html +++ b/static/faq.html @@ -5,7 +5,7 @@ <h1 style="text-align: center;">FAQ</h1> <div> <h4>What is fchan</h4> - <p>fchan short for fchannel and is a federated image board based on activity pub. it removes the centralization aspect that so many of us have become accustom to. it is not trying to re-invent the wheel and draws likeness from other chans for ease of familiarity. you can get the source code here https://github.com/FChannel0 any help is appreciated.</p> + <p>fchan short for fchannel and is a federated image board based on activity pub. it removes the need for centeralized boards. many boards can be connected and feeds shared or followed. it draws likeness from other chans for ease of familiarity. you can get the source code here https://github.com/FChannel0 and modify how you choose, any help is appreciated.</p> <h4>Options</h4> <p>the options field when posting can be used for special options when posting. type noko in the options field to return to the thread you posting to. use sage to ignore updating the thread bump order. nokosage will do both.</p> diff --git a/static/main.html b/static/main.html index 7d5d236..dd9d0c0 100644 --- a/static/main.html +++ b/static/main.html @@ -19,7 +19,7 @@ } body { - {{ if .Board.Restricted }} + {{ if .Board.Post.Actor.Restricted }} background-color: #eef2fe; color: black; {{ else }} @@ -29,7 +29,7 @@ } .popup-box { - {{ if .Board.Restricted }} + {{ if .Board.Post.Actor.Restricted }} border: 4px solid #d3caf0; background-color: #eff5ff; {{ else }} @@ -43,7 +43,7 @@ } .reply { - {{ if .Board.Restricted }} + {{ if .Board.Post.Actor.Restricted }} color:#af0a0f; {{ else }} color:#000080; @@ -51,7 +51,7 @@ } .post { - {{ if .Board.Restricted }} + {{ if .Board.Post.Actor.Restricted }} background-color: #d5daf0; {{ else }} background-color: #f0e0d6; diff --git a/static/manage.html b/static/manage.html index 06288cd..570c0f5 100644 --- a/static/manage.html +++ b/static/manage.html @@ -16,7 +16,7 @@ </ul> </div> <a href="/{{ .Board.Name }}">[Return]</a> -{{ $actor := .Actor.Id }} +{{ $actor := .Board.Actor.Id }} {{ $board := .Board }} {{ $key := .Key }} {{ if .IsLocal }} @@ -24,9 +24,9 @@ <h4>Subscribed</h4> <form id="follow-form" action="/{{ .Key }}/{{ .Board.Name }}/follow" method="post" enctype="application/x-www-form-urlencoded"> <label>Subscribe:</label><br> - <input id="follow" name="follow" style="margin-bottom: 12px;" placeholder="https://localhost:3000/g"></input> + <input id="follow" name="follow" style="margin-bottom: 12px;" placeholder="https://server.fchan.xyz/g"></input> <input type="submit" value="Subscribe"><br> - <input type="hidden" name="actor" value="{{ .Actor.Id }}"> + <input type="hidden" name="actor" value="{{ $board.Actor.Id }}"> </form> <ul style="display: inline-block; padding: 0; margin: 0;"> @@ -81,8 +81,8 @@ reportedArray.forEach(function(r, i){ var id = r.getAttribute("post") - r.innerText = "/" + {{ .Board.Name }} + "/" + shortURL("{{ .Actor.Id }}", id) - r.href = {{ .Domain }} + "/" + {{ .Board.Name }} + "/" + shortURL("{{ .Actor.Id }}", id) + r.innerText = "/" + {{ .Board.Name }} + "/" + shortURL("{{ .Board.Actor.Id }}", id) + r.href = {{ .Domain }} + "/" + {{ .Board.Name }} + "/" + shortURL("{{ .Board.Actor.Id }}", id) }) </script> {{ end }} diff --git a/static/rules.html b/static/rules.html index 1ca49ee..574435a 100644 --- a/static/rules.html +++ b/static/rules.html @@ -2,15 +2,11 @@ <html> <body style="background-color:#ffffee; max-width: 800px; margin: 0 auto;"> <a style="color: black;" href="javascript:history.back()">[Back]</a> - <h1 style="padding-left: 15px;">Rules and Agreements:</h1> + <h1 style="text-align: center;">Rules and Agreements:</h1> <ol> <li>Do not break or violate United States laws.</li> <li>Age Restriction is 18 years and older.</li> <li>Any blue boards are restricted to work safe posts only.</li> </ol> - <div style="padding-top: 500px;width: 500px; margin:0 auto; margin-top: 50px; text-align: center;"> - <a href="/">[Home]</a><a href="/static/rules.html">[Rules]</a><a href="/static/faq.html">[FAQ]</a> - <p>All media are copyright to their respective owners.</p> - </div> </body> </html> |