fix bug where subsequent reads of the same article come back empty

This commit is contained in:
TJP 2023-02-09 13:44:10 -07:00
parent 3762f7363f
commit e91b8a4138
1 changed files with 9 additions and 2 deletions

11
main.go
View File

@ -122,7 +122,7 @@ func (b *backend) GetArticles(_ *nntp.Group, from, to int64) ([]nntpserver.Numbe
if num >= from && num <= to {
numbered = append(numbered, nntpserver.NumberedArticle{
Num: num,
Article: msg,
Article: copyArticle(msg),
})
}
}
@ -145,7 +145,7 @@ func (b *backend) GetArticle(_ *nntp.Group, messageID string) (*nntp.Article, er
num, err := strconv.Atoi(messageID)
if err == nil && num <= len(b.messages) {
return b.messages[num-1], nil
return copyArticle(b.messages[num-1]), nil
}
return nil, nntpserver.ErrInvalidMessageID
@ -171,6 +171,13 @@ func (b backend) Post(article *nntp.Article) error {
return appendMessage(msg)
}
func copyArticle(article *nntp.Article) *nntp.Article {
var out nntp.Article
out = *article
out.Body = bytes.NewBuffer(article.Body.(*bytes.Buffer).Bytes())
return &out
}
type irisMsg struct {
Hash string `json:"hash"`
EditHash *string `json:"edit_hash"`