aboutsummaryrefslogtreecommitdiff
path: root/hotline/news.go
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-11-28 00:39:17 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2025-11-28 00:39:17 +0100
commit9f67542d8469db45c823e347b1868b3582d9e5a7 (patch)
tree88741b3d8633758e4f6f5cbc292f338bc99602a0 /hotline/news.go
parent8f9edf2f3bb18f7ab1a04ead182a1daf2cfd41d9 (diff)
parent8ddb9bb228389b198a76d6df21de005da4fad66b (diff)
Merge branch 'master' of https://github.com/jhalter/mobiusHEADmain
Diffstat (limited to 'hotline/news.go')
-rw-r--r--hotline/news.go25
1 files changed, 12 insertions, 13 deletions
diff --git a/hotline/news.go b/hotline/news.go
index a490a89..1ddeebd 100644
--- a/hotline/news.go
+++ b/hotline/news.go
@@ -14,7 +14,7 @@ var (
)
type ThreadedNewsMgr interface {
- ListArticles(newsPath []string) NewsArtListData
+ ListArticles(newsPath []string) (NewsArtListData, error)
GetArticle(newsPath []string, articleID uint32) *NewsArtData
DeleteArticle(newsPath []string, articleID uint32, recursive bool) error
PostArticle(newsPath []string, parentArticleID uint32, article NewsArtData) error
@@ -41,13 +41,13 @@ type NewsCategoryListData15 struct {
readOffset int // Internal offset to track read progress
}
-func (newscat *NewsCategoryListData15) GetNewsArtListData() NewsArtListData {
+func (newscat *NewsCategoryListData15) GetNewsArtListData() (NewsArtListData, error) {
var newsArts []NewsArtList
var newsArtsPayload []byte
for i, art := range newscat.Articles {
id := make([]byte, 4)
- binary.BigEndian.PutUint32(id, i)
+ binary.BigEndian.PutUint32(id, i) // The article's map key in the Articles map is its ID.
newsArts = append(newsArts, NewsArtList{
ID: [4]byte(id),
@@ -70,8 +70,7 @@ func (newscat *NewsCategoryListData15) GetNewsArtListData() NewsArtListData {
for _, v := range newsArts {
b, err := io.ReadAll(&v)
if err != nil {
- // TODO
- panic(err)
+ return NewsArtListData{}, err
}
newsArtsPayload = append(newsArtsPayload, b...)
}
@@ -81,7 +80,7 @@ func (newscat *NewsCategoryListData15) GetNewsArtListData() NewsArtListData {
Name: []byte{},
Description: []byte{},
NewsArtList: newsArtsPayload,
- }
+ }, nil
}
// NewsArtData represents an individual news article.
@@ -157,8 +156,8 @@ type NewsArtList struct {
}
var (
- NewsFlavorLen = []byte{0x0a}
- NewsFlavor = []byte("text/plain")
+ NewsFlavor = []byte("text/plain") // NewsFlavor is always "text/plain"
+ NewsFlavorCount = []byte{0, 1} // NewsFlavorCount is always 1
)
func (nal *NewsArtList) Read(p []byte) (int, error) {
@@ -167,12 +166,12 @@ func (nal *NewsArtList) Read(p []byte) (int, error) {
nal.TimeStamp[:],
nal.ParentID[:],
nal.Flags[:],
- []byte{0, 1}, // Flavor Count TODO: make this not hardcoded
+ NewsFlavorCount,
[]byte{uint8(len(nal.Title))},
nal.Title,
[]byte{uint8(len(nal.Poster))},
nal.Poster,
- NewsFlavorLen,
+ []byte{uint8(len(NewsFlavor))},
NewsFlavor,
nal.ArticleSize[:],
)
@@ -184,7 +183,7 @@ func (nal *NewsArtList) Read(p []byte) (int, error) {
n := copy(p, out[nal.readOffset:])
nal.readOffset += n
- return n, io.EOF
+ return n, nil
}
type NewsFlavorList struct {
@@ -242,10 +241,10 @@ type MockThreadNewsMgr struct {
mock.Mock
}
-func (m *MockThreadNewsMgr) ListArticles(newsPath []string) NewsArtListData {
+func (m *MockThreadNewsMgr) ListArticles(newsPath []string) (NewsArtListData, error) {
args := m.Called(newsPath)
- return args.Get(0).(NewsArtListData)
+ return args.Get(0).(NewsArtListData), args.Error(1)
}
func (m *MockThreadNewsMgr) GetArticle(newsPath []string, articleID uint32) *NewsArtData {