Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ary82 committed Jun 23, 2024
1 parent e5efddb commit e506d98
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/cron/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *cronService) Start() error {
}

_, err = scheduler.NewJob(
gocron.DurationJob(15*time.Second),
gocron.DurationJob(10*time.Second),
gocron.NewTask(s.sseJob),
gocron.WithSingletonMode(gocron.LimitModeReschedule),
)
Expand Down
5 changes: 4 additions & 1 deletion internal/post/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const (
SELECT_RANDOM_POST_QUERY string = "SELECT id, body, author, type, created_at FROM submissions WHERE type = $1 ORDER BY RANDOM() LIMIT 1"
)

const ALLOWED_CHARS string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.'-_ !"
const (
ALLOWED_CHARS string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.'-_ !"
RESERVED_NAME string = "ary82"
)

const SQLSTATE_ERR_NOT_UNIQUE string = "23505"
4 changes: 4 additions & 0 deletions internal/post/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (s *postService) CreatePost(post *Post) error {
return fmt.Errorf("author name too short")
}

if strings.ReplaceAll(post.Author, " ", "") == RESERVED_NAME {
return fmt.Errorf("that's my name.")
}

for i, v := range post.Body {
if !strings.ContainsRune(ALLOWED_CHARS, v) {
return fmt.Errorf("body contains invalid characters at index: %d", i)
Expand Down
5 changes: 1 addition & 4 deletions internal/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ func (s *FiberServer) sse(c *fiber.Ctx) error {
negMsg := html.EscapeString(s.CurrentNegativePosts.Body)
negAuthor := html.EscapeString(s.CurrentNegativePosts.Author)

_ = posAuthor
_ = negAuthor

fmt.Fprintf(w,
"event: positive_body\ndata: %s\n\nevent: positive_author\ndata: %s\n\nevent: negative_body\ndata: %s\n\nevent: negative_author\ndata: %s\n\n",
posMsg, posAuthor,
Expand All @@ -35,7 +32,7 @@ func (s *FiberServer) sse(c *fiber.Ctx) error {

err := w.Flush()
if err != nil {
fmt.Printf("Error while flushing: %v. Closing http connection.\n", err)
fmt.Printf("%v. Closing http connection.\n", err)
break
}
time.Sleep(3 * time.Second)
Expand Down

0 comments on commit e506d98

Please sign in to comment.