channel logs are now daily instead of monthly
This commit is contained in:
parent
5d9e37d538
commit
4cbf6213c8
3 changed files with 12 additions and 9 deletions
14
api/logs.go
14
api/logs.go
|
@ -32,22 +32,23 @@ type Msg struct {
|
|||
func (s *Server) getCurrentUserLogs(c echo.Context) error {
|
||||
channel := strings.ToLower(c.Param("channel"))
|
||||
channel = strings.TrimSpace(channel)
|
||||
year := strconv.Itoa(time.Now().Year())
|
||||
year := time.Now().Year()
|
||||
month := time.Now().Month().String()
|
||||
username := c.Param("username")
|
||||
username = strings.ToLower(strings.TrimSpace(username))
|
||||
|
||||
redirectURL := fmt.Sprintf("/channel/%s/user/%s/%s/%s", channel, username, year, month)
|
||||
redirectURL := fmt.Sprintf("/channel/%s/user/%s/%d/%s", channel, username, year, month)
|
||||
return c.Redirect(303, redirectURL)
|
||||
}
|
||||
|
||||
func (s *Server) getCurrentChannelLogs(c echo.Context) error {
|
||||
channel := strings.ToLower(c.Param("channel"))
|
||||
channel = strings.TrimSpace(channel)
|
||||
year := strconv.Itoa(time.Now().Year())
|
||||
channel = strings.TrimSpace(channel)
|
||||
year := time.Now().Year()
|
||||
month := time.Now().Month().String()
|
||||
day := time.Now().Day()
|
||||
|
||||
redirectURL := fmt.Sprintf("/channel/%s/%s/%s", channel, year, month)
|
||||
redirectURL := fmt.Sprintf("/channel/%s/%d/%s/%d", channel, year, month, day)
|
||||
return c.Redirect(303, redirectURL)
|
||||
}
|
||||
|
||||
|
@ -56,6 +57,7 @@ func (s *Server) getDatedChannelLogs(c echo.Context) error {
|
|||
channel = strings.TrimSpace(channel)
|
||||
year := c.Param("year")
|
||||
month := strings.Title(c.Param("month"))
|
||||
day := c.Param("day")
|
||||
|
||||
if year == "" || month == "" {
|
||||
year = strconv.Itoa(time.Now().Year())
|
||||
|
@ -64,7 +66,7 @@ func (s *Server) getDatedChannelLogs(c echo.Context) error {
|
|||
|
||||
content := ""
|
||||
|
||||
file := fmt.Sprintf(s.logPath+"%s/%s/%s/channel.txt", channel, year, month)
|
||||
file := fmt.Sprintf(s.logPath+"%s/%s/%s/%s/channel.txt", channel, year, month, day)
|
||||
if _, err := os.Stat(file + ".gz"); err == nil {
|
||||
file = file + ".gz"
|
||||
f, err := os.Open(file)
|
||||
|
|
|
@ -26,7 +26,7 @@ func (s *Server) Init() {
|
|||
})
|
||||
e.GET("/channel/:channel/user/:username", s.getCurrentUserLogs)
|
||||
e.GET("/channel/:channel", s.getCurrentChannelLogs)
|
||||
e.GET("/channel/:channel/:year/:month", s.getDatedChannelLogs)
|
||||
e.GET("/channel/:channel/:year/:month/:day", s.getDatedChannelLogs)
|
||||
e.GET("/channel/:channel/user/:username/:year/:month", s.getDatedUserLogs)
|
||||
e.GET("/channel/:channel/user/:username/random", s.getRandomQuote)
|
||||
|
||||
|
|
|
@ -11,11 +11,12 @@ func (l *Logger) LogMessageForChannel(msg twitch.Message) error {
|
|||
year := msg.Time.Year()
|
||||
month := msg.Time.Month()
|
||||
channel := strings.Replace(msg.Channel.Name, "#", "", 1)
|
||||
err := os.MkdirAll(fmt.Sprintf(l.logPath+"%s/%d/%s/", channel, year, month), 0755)
|
||||
day := msg.Time.Day()
|
||||
err := os.MkdirAll(fmt.Sprintf(l.logPath+"%s/%d/%s/%d", channel, year, month, day), 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filename := fmt.Sprintf(l.logPath+"%s/%d/%s/channel.txt", channel, year, month)
|
||||
filename := fmt.Sprintf(l.logPath+"%s/%d/%s/%d/channel.txt", channel, year, month, day)
|
||||
|
||||
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue