Browse Source

Changed max attachment size to 100MB, fixed problem with System user having invalid timestamp

master
parent
commit
a6a75c22a2
  1. 2
      src/api/limits.go
  2. 2
      src/api/message.go
  3. 2
      src/api/websocket.go
  4. 2
      src/main.go
  5. 6
      src/server/server.go
  6. 14
      src/server/userHandler.go
  7. 6
      src/server/websocketHandler.go

2
src/api/limits.go

@ -7,4 +7,4 @@ const MaxMessageContentLen uint = 500
const MaxMessagesRemembered uint = 50
// Max filesize to accept as attachment
const MaxAttachmentSize uint64 = 31457280 // 30MB
const MaxAttachmentSize uint64 = 104857600 // 100MB

2
src/api/message.go

@ -48,7 +48,7 @@ func (db *DB) AddMessage(message Message) error {
}
if count >= uint64(MaxMessagesRemembered) {
// remove the last one
// remove the last one if the max messages threshold has been exceeded
command = fmt.Sprintf("DELETE FROM %s WHERE timestamp = (SELECT MIN(timestamp) FROM %s)", MessagesTablename, MessagesTablename)
_, err := db.Exec(command)
if err != nil {

2
src/api/websocket.go

@ -70,6 +70,7 @@ func (holder *WSHolder) HandleNewWebSocketMessages(ws *WS, output chan Message)
holder.Remove(ws.User.Name)
disconnectionMessage := Message{
TimeStamp: uint64(time.Now().UnixMilli()),
From: UserSystem,
Contents: fmt.Sprintf("%s has disconnected", ws.User.Name),
}
@ -83,6 +84,7 @@ func (holder *WSHolder) HandleNewWebSocketMessages(ws *WS, output chan Message)
holder.Remove(ws.User.Name)
disconnectionMessage := Message{
TimeStamp: uint64(time.Now().UnixMilli()),
From: UserSystem,
Contents: fmt.Sprintf("%s has disconnected", ws.User.Name),
}

2
src/main.go

@ -26,7 +26,7 @@ import (
"unbewohnte/gochat/server"
)
const version string = "0.1.1"
const version string = "0.1.2"
var (
port *uint = flag.Uint("port", 8080, "Set working port")

6
src/server/server.go

@ -139,7 +139,11 @@ func (s *Server) Start() {
go s.BroadcastMessages()
// clean attachments storage from time to time
// max attachment filesize * 50 is the limit, check every 5 sec
go manageAttachmentsStorage(filepath.Join(s.workingDir, attachmentsDirName), api.MaxAttachmentSize*50, time.Second*5)
go manageAttachmentsStorage(
filepath.Join(s.workingDir, attachmentsDirName),
api.MaxAttachmentSize,
time.Second*5,
)
// fire up either a TLS or non-TLS server
if s.keyFile != "" && s.certFile != "" {

14
src/server/userHandler.go

@ -108,20 +108,6 @@ func (s *Server) HandlerUsers(w http.ResponseWriter, req *http.Request) {
w.Write(responseBytes)
}
// users, err := db.getAllUsers()
// if err != nil {
// http.Error(w, "", http.StatusInternalServerError)
// return
// }
// w.Header().Add("Content-type", "application/json")
// userBytes, err := json.Marshal(*users)
// if err != nil {
// break
// }
// w.Write(userBytes)
default:
http.Error(w, "wrong method", http.StatusMethodNotAllowed)
}

6
src/server/websocketHandler.go

@ -82,6 +82,7 @@ func (s *Server) HandlerWebsockets(w http.ResponseWriter, req *http.Request) {
// notify chat that a new user has connected
newConnectionMessage := api.Message{
TimeStamp: uint64(time.Now().UnixMilli()),
From: api.UserSystem,
Contents: fmt.Sprintf("%s has connected", newWS.User.Name),
}
@ -96,11 +97,6 @@ func (s *Server) BroadcastMessages() {
break
}
if message.From.Name == api.UserSystem.Name {
// add timestapm manually for the system user
message.TimeStamp = uint64(time.Now().Unix())
}
// add incoming message to the db
err := s.db.AddMessage(message)
if err != nil {

Loading…
Cancel
Save