add option to fetch referenced uri
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user