mirror of
https://github.com/ChronosX88/yans.git
synced 2024-11-21 19:32:17 +00:00
Implement NEWNEWS command
This commit is contained in:
parent
5981fd1415
commit
e6f8e39a8e
@ -43,11 +43,11 @@
|
|||||||
- :heavy_check_mark: `LIST NEWSGROUPS`
|
- :heavy_check_mark: `LIST NEWSGROUPS`
|
||||||
- :x: `LIST ACTIVE.TIMES`
|
- :x: `LIST ACTIVE.TIMES`
|
||||||
- :x: `LIST DISTRIB.PATS`
|
- :x: `LIST DISTRIB.PATS`
|
||||||
- :construction: Information Commands
|
- :heavy_check_mark: Information Commands
|
||||||
- :heavy_check_mark: `DATE`
|
- :heavy_check_mark: `DATE`
|
||||||
- :heavy_check_mark: `HELP`
|
- :heavy_check_mark: `HELP`
|
||||||
- :heavy_check_mark: `NEWGROUPS`
|
- :heavy_check_mark: `NEWGROUPS`
|
||||||
- :x: `NEWNEWS`
|
- :heavy_check_mark: `NEWNEWS`
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -168,3 +168,8 @@ func (sb *SQLiteBackend) GetArticleNumbers(g *models.Group, low, high int64) ([]
|
|||||||
|
|
||||||
return numbers, nil
|
return numbers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sb *SQLiteBackend) GetNewArticlesSince(timestamp int64) ([]string, error) {
|
||||||
|
var articleIds []string
|
||||||
|
return articleIds, sb.db.Select(&articleIds, "SELECT json_extract(articles.header, '$.Message-Id[0]') FROM articles WHERE created_at > datetime(?, 'unixepoch')", timestamp)
|
||||||
|
}
|
||||||
|
@ -18,4 +18,5 @@ type StorageBackend interface {
|
|||||||
GetArticle(messageID string) (models.Article, error)
|
GetArticle(messageID string) (models.Article, error)
|
||||||
GetArticleByNumber(g *models.Group, num int) (models.Article, error)
|
GetArticleByNumber(g *models.Group, num int) (models.Article, error)
|
||||||
GetArticleNumbers(g *models.Group, low, high int64) ([]int64, error)
|
GetArticleNumbers(g *models.Group, low, high int64) ([]int64, error)
|
||||||
|
GetNewArticlesSince(timestamp int64) ([]string, error)
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ const (
|
|||||||
CommandBody = "BODY"
|
CommandBody = "BODY"
|
||||||
CommandStat = "STAT"
|
CommandStat = "STAT"
|
||||||
CommandHelp = "HELP"
|
CommandHelp = "HELP"
|
||||||
|
CommandNewNews = "NEWNEWS"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -41,6 +41,7 @@ func NewHandler(b backend.StorageBackend, serverDomain string) *Handler {
|
|||||||
protocol.CommandBody: h.handleArticle,
|
protocol.CommandBody: h.handleArticle,
|
||||||
protocol.CommandStat: h.handleArticle,
|
protocol.CommandStat: h.handleArticle,
|
||||||
protocol.CommandHelp: h.handleHelp,
|
protocol.CommandHelp: h.handleHelp,
|
||||||
|
protocol.CommandNewNews: h.handleNewNews,
|
||||||
}
|
}
|
||||||
h.serverDomain = serverDomain
|
h.serverDomain = serverDomain
|
||||||
return h
|
return h
|
||||||
@ -530,6 +531,7 @@ func (h *Handler) handleHelp(s *Session, command string, arguments []string, id
|
|||||||
" LISTGROUP [newsgroup [range]]\r\n" +
|
" LISTGROUP [newsgroup [range]]\r\n" +
|
||||||
" MODE READER\r\n" +
|
" MODE READER\r\n" +
|
||||||
" NEWGROUPS [yy]yymmdd hhmmss [GMT]\r\n" +
|
" NEWGROUPS [yy]yymmdd hhmmss [GMT]\r\n" +
|
||||||
|
" NEWNEWS [yy]yymmdd hhmmss [GMT]\r\n" +
|
||||||
" NEXT\r\n" +
|
" NEXT\r\n" +
|
||||||
" POST\r\n" +
|
" POST\r\n" +
|
||||||
" QUIT\r\n" +
|
" QUIT\r\n" +
|
||||||
@ -556,6 +558,53 @@ func (h *Handler) handleHelp(s *Session, command string, arguments []string, id
|
|||||||
return dw.Close()
|
return dw.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) handleNewNews(s *Session, command string, arguments []string, id uint) error {
|
||||||
|
s.tconn.StartResponse(id)
|
||||||
|
defer s.tconn.EndResponse(id)
|
||||||
|
|
||||||
|
if len(arguments) < 2 || len(arguments) > 3 {
|
||||||
|
return s.tconn.PrintfLine(protocol.ErrSyntaxError.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
dateString := arguments[0] + " " + arguments[1]
|
||||||
|
|
||||||
|
var date time.Time
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if len(dateString) == 15 {
|
||||||
|
date, err = time.Parse("20060102 150405", dateString)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if len(dateString) == 13 {
|
||||||
|
date, err = time.Parse("060102 150405", dateString)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return s.tconn.PrintfLine(protocol.ErrSyntaxError.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
a, err := h.backend.GetNewArticlesSince(date.Unix())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dw := s.tconn.DotWriter()
|
||||||
|
_, err = dw.Write([]byte(protocol.NNTPResponse{Code: 230, Message: "list of new articles by message-id follows"}.String() + protocol.CRLF))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, v := range a {
|
||||||
|
_, err = dw.Write([]byte(v + protocol.CRLF))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dw.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) Handle(s *Session, message string, id uint) error {
|
func (h *Handler) Handle(s *Session, message string, id uint) error {
|
||||||
splittedMessage := strings.Split(message, " ")
|
splittedMessage := strings.Split(message, " ")
|
||||||
for i, v := range splittedMessage {
|
for i, v := range splittedMessage {
|
||||||
|
Loading…
Reference in New Issue
Block a user