add option to fetch referenced uri
This commit is contained in:
parent
8ef4322fba
commit
0252dfa512
@ -1062,27 +1062,30 @@ func (self httpFrontend) handle_authed_api(wr http.ResponseWriter, r *http.Reque
|
||||
func (self *httpFrontend) handle_api_find(wr http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
h := q.Get("hash")
|
||||
msgid := q.Get("id")
|
||||
if len(h) > 0 {
|
||||
msgid := q.Get("id")
|
||||
if len(h) > 0 {
|
||||
e, err := self.daemon.database.GetMessageIDByHash(h)
|
||||
if err == nil {
|
||||
msgid = e.MessageID()
|
||||
}
|
||||
e, err := self.daemon.database.GetMessageIDByHash(h)
|
||||
if err == nil {
|
||||
msgid = e.MessageID()
|
||||
}
|
||||
if len(msgid) > 0 {
|
||||
// found it (probaly)
|
||||
model := self.daemon.database.GetPostModel(self.prefix, msgid)
|
||||
if model == nil {
|
||||
// no model
|
||||
}
|
||||
|
||||
if !ValidMessageID(msgid) {
|
||||
msgid = ""
|
||||
}
|
||||
|
||||
if len(msgid) > 0 {
|
||||
self.daemon.store.GetMessage(msgid, func(nntp NNTPMessage) {
|
||||
if nntp == nil {
|
||||
wr.WriteHeader(404)
|
||||
} else {
|
||||
// we found it
|
||||
wr.Header().Add("Content-Type", "text/json; encoding=UTF-8")
|
||||
json.NewEncoder(wr).Encode([]PostModel{model})
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
model := PostModelFromMessage(self.prefix, nntp)
|
||||
// we found it
|
||||
wr.Header().Add("Content-Type", "text/json; encoding=UTF-8")
|
||||
json.NewEncoder(wr).Encode([]PostModel{model})
|
||||
})
|
||||
return
|
||||
}
|
||||
s := q.Get("text")
|
||||
g := q.Get("group")
|
||||
|
@ -295,6 +295,7 @@ type post struct {
|
||||
Type string
|
||||
nntp_id int
|
||||
FrontendPublicKey string
|
||||
ReferencedURI string
|
||||
}
|
||||
|
||||
func (p *post) IsCtl() bool {
|
||||
@ -411,7 +412,7 @@ func (self *attachment) Filename() string {
|
||||
return self.Name
|
||||
}
|
||||
|
||||
func PostModelFromMessage(parent, prefix string, nntp NNTPMessage) PostModel {
|
||||
func PostModelFromMessage(prefix string, nntp NNTPMessage) PostModel {
|
||||
p := new(post)
|
||||
p.PostName = nntp.Name()
|
||||
p.PostSubject = nntp.Subject()
|
||||
@ -422,10 +423,11 @@ func PostModelFromMessage(parent, prefix string, nntp NNTPMessage) PostModel {
|
||||
p.Posted = nntp.Posted()
|
||||
p.op = nntp.OP()
|
||||
p.prefix = prefix
|
||||
p.Parent = parent
|
||||
p.Parent = nntp.Reference()
|
||||
p.addr = nntp.Addr()
|
||||
p.sage = nntp.Sage()
|
||||
p.Key = nntp.Pubkey()
|
||||
p.ReferencedURI = nntp.Headers().Get("X-Referenced-Uri", "")
|
||||
p.FrontendPublicKey = nntp.FrontendPubkey()
|
||||
for _, att := range nntp.Attachments() {
|
||||
p.Files = append(p.Files, att.ToModel(prefix))
|
||||
@ -627,6 +629,7 @@ func (self *post) Truncate() PostModel {
|
||||
// TODO: copy?
|
||||
Files: self.Files,
|
||||
FrontendPublicKey: self.FrontendPublicKey,
|
||||
ReferencedURI: self.ReferencedURI,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,5 +42,27 @@
|
||||
</span>
|
||||
<br /><br />
|
||||
<span id="post_body_{{post.PostHash}}" class="message_span">{{{post.RenderBody}}}</span>
|
||||
{{#post.OP}}
|
||||
<script type="text/javascript">
|
||||
var j = fetch("/api/find?id={{post.MessageID}}").then(function(resp) {
|
||||
return resp.json();
|
||||
}).catch(function(resp) {
|
||||
return [];
|
||||
});
|
||||
if (j.legnth) {
|
||||
var e = document.getElementById("post_body_{{post.PostHash}}");
|
||||
if(e) {
|
||||
var link = document.createElement("a");
|
||||
var u = new URL(j[0].ReferencedURI);
|
||||
if(u.protocol === "https" || u.protocol === "http") {
|
||||
link.href = u.toString();
|
||||
link.innerText = "[Link]";
|
||||
e.appendChild(txt);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{{/post.OP}}
|
||||
<br style="clear: both;" />
|
||||
|
||||
</div>
|
||||
|
@ -57,10 +57,10 @@
|
||||
{{^thread.BumpLock}}
|
||||
<div class="thread" id="thread_{{thread.OP.PostHash}}">
|
||||
{{/thread.BumpLock}}
|
||||
{{{thread.OP.RenderPost}}}
|
||||
{{#thread.Replies}}
|
||||
{{{RenderPost}}}
|
||||
{{/thread.Replies}}
|
||||
{{{thread.OP.RenderPost}}}
|
||||
{{#thread.Replies}}
|
||||
{{{RenderPost}}}
|
||||
{{/thread.Replies}}
|
||||
</div>
|
||||
<hr style="clear: both;">
|
||||
<footer>
|
||||
|
Reference in New Issue
Block a user