diff --git a/api/channel.go b/api/channel.go index 8aa4019..980fb0b 100644 --- a/api/channel.go +++ b/api/channel.go @@ -131,6 +131,7 @@ func (s *Server) getChannelLogs(c echo.Context) error { Text: message.Message, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } case *twitch.ClearChatMessage: message := *parsedMessage.(*twitch.ClearChatMessage) @@ -149,6 +150,7 @@ func (s *Server) getChannelLogs(c echo.Context) error { Text: text, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } case *twitch.UserNoticeMessage: message := *parsedMessage.(*twitch.UserNoticeMessage) @@ -160,6 +162,7 @@ func (s *Server) getChannelLogs(c echo.Context) error { Text: message.SystemMsg + " " + message.Message, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } } @@ -170,6 +173,10 @@ func (s *Server) getChannelLogs(c echo.Context) error { return writeJSONResponse(c, &logResult) } + if shouldRespondWithRaw(c) { + return writeRawResponse(c, &logResult) + } + return writeTextResponse(c, &logResult) } @@ -221,6 +228,7 @@ func (s *Server) getChannelLogsRange(c echo.Context) error { Text: message.Message, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } case *twitch.ClearChatMessage: message := *parsedMessage.(*twitch.ClearChatMessage) @@ -243,6 +251,7 @@ func (s *Server) getChannelLogsRange(c echo.Context) error { Text: text, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } case *twitch.UserNoticeMessage: message := *parsedMessage.(*twitch.UserNoticeMessage) @@ -254,6 +263,7 @@ func (s *Server) getChannelLogsRange(c echo.Context) error { Text: message.SystemMsg + " " + message.Message, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } } @@ -264,5 +274,9 @@ func (s *Server) getChannelLogsRange(c echo.Context) error { return writeJSONResponse(c, &logResult) } + if shouldRespondWithRaw(c) { + return writeRawResponse(c, &logResult) + } + return writeTextResponse(c, &logResult) } diff --git a/api/server.go b/api/server.go index 0addff5..bb1e876 100644 --- a/api/server.go +++ b/api/server.go @@ -119,6 +119,7 @@ type chatMessage struct { Channel string `json:"channel"` Timestamp timestamp `json:"timestamp"` Type twitch.MessageType `json:"type"` + Raw string `json:"raw"` } type ErrorResponse struct { @@ -234,6 +235,17 @@ func writeTextResponse(c echo.Context, cLog *chatLog) error { return nil } +func writeRawResponse(c echo.Context, cLog *chatLog) error { + c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextPlainCharsetUTF8) + c.Response().WriteHeader(http.StatusOK) + + for _, cMessage := range cLog.Messages { + c.Response().Write([]byte(cMessage.Raw + "\n")) + } + + return nil +} + func writeJSONResponse(c echo.Context, logResult *chatLog) error { _, stream := c.QueryParams()["stream"] if stream { @@ -272,3 +284,9 @@ func shouldRespondWithJson(c echo.Context) bool { return c.Request().Header.Get("Content-Type") == "application/json" || c.Request().Header.Get("accept") == "application/json" || c.QueryParam("type") == "json" || ok } + +func shouldRespondWithRaw(c echo.Context) bool { + _, ok := c.QueryParams()["raw"] + + return c.QueryParam("type") == "raw" || ok +} diff --git a/api/user.go b/api/user.go index e28d657..130c765 100644 --- a/api/user.go +++ b/api/user.go @@ -305,6 +305,7 @@ func (s *Server) getUserLogs(c echo.Context) error { Text: message.Message, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } case *twitch.ClearChatMessage: message := *parsedMessage.(*twitch.ClearChatMessage) @@ -323,6 +324,7 @@ func (s *Server) getUserLogs(c echo.Context) error { Text: text, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } case *twitch.UserNoticeMessage: message := *parsedMessage.(*twitch.UserNoticeMessage) @@ -334,6 +336,7 @@ func (s *Server) getUserLogs(c echo.Context) error { Text: message.SystemMsg + " " + message.Message, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } } @@ -344,6 +347,10 @@ func (s *Server) getUserLogs(c echo.Context) error { return writeJSONResponse(c, &logResult) } + if shouldRespondWithRaw(c) { + return writeRawResponse(c, &logResult) + } + return writeTextResponse(c, &logResult) } @@ -396,6 +403,7 @@ func (s *Server) getUserLogsRange(c echo.Context) error { Text: message.Message, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } case *twitch.ClearChatMessage: message := *parsedMessage.(*twitch.ClearChatMessage) @@ -418,6 +426,7 @@ func (s *Server) getUserLogsRange(c echo.Context) error { Text: text, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } case *twitch.UserNoticeMessage: message := *parsedMessage.(*twitch.UserNoticeMessage) @@ -429,6 +438,7 @@ func (s *Server) getUserLogsRange(c echo.Context) error { Text: message.SystemMsg + " " + message.Message, Type: message.Type, Channel: message.Channel, + Raw: message.Raw, } } @@ -439,5 +449,9 @@ func (s *Server) getUserLogsRange(c echo.Context) error { return writeJSONResponse(c, &logResult) } + if shouldRespondWithRaw(c) { + return writeRawResponse(c, &logResult) + } + return writeTextResponse(c, &logResult) }