Adds attachment fetching/uploading
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
|
||||
"code.severnaya.net/kordophone-mock/v2/data"
|
||||
@@ -16,13 +19,14 @@ const (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
version string
|
||||
conversations []model.Conversation
|
||||
authTokens []model.AuthToken
|
||||
messageStore map[string][]model.Message
|
||||
updateItems map[int]model.UpdateItem
|
||||
updateChannels []chan []model.UpdateItem
|
||||
updateItemSeq int
|
||||
version string
|
||||
conversations []model.Conversation
|
||||
authTokens []model.AuthToken
|
||||
attachmentStore model.AttachmentStore
|
||||
messageStore map[string][]model.Message
|
||||
updateItems map[int]model.UpdateItem
|
||||
updateChannels []chan []model.UpdateItem
|
||||
updateItemSeq int
|
||||
}
|
||||
|
||||
type MessagesQuery struct {
|
||||
@@ -50,14 +54,17 @@ func (e *DatabaseError) Error() string {
|
||||
}
|
||||
|
||||
func NewServer() *Server {
|
||||
attachmentStorePath := path.Join(os.TempDir(), "kpmock", "attachments")
|
||||
|
||||
return &Server{
|
||||
version: VERSION,
|
||||
conversations: []model.Conversation{},
|
||||
authTokens: []model.AuthToken{},
|
||||
messageStore: make(map[string][]model.Message),
|
||||
updateItems: make(map[int]model.UpdateItem),
|
||||
updateChannels: []chan []model.UpdateItem{},
|
||||
updateItemSeq: 0,
|
||||
version: VERSION,
|
||||
conversations: []model.Conversation{},
|
||||
authTokens: []model.AuthToken{},
|
||||
attachmentStore: model.NewAttachmentStore(attachmentStorePath),
|
||||
messageStore: make(map[string][]model.Message),
|
||||
updateItems: make(map[int]model.UpdateItem),
|
||||
updateChannels: []chan []model.UpdateItem{},
|
||||
updateItemSeq: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,6 +294,18 @@ func (s *Server) MarkConversationAsRead(conversation *model.Conversation) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) FetchAttachment(guid string) (io.Reader, error) {
|
||||
return s.attachmentStore.FetchAttachment(guid)
|
||||
}
|
||||
|
||||
func (s *Server) UploadAttachment(filename string, reader io.Reader) (*string, error) {
|
||||
return s.attachmentStore.StoreAttachment(filename, reader)
|
||||
}
|
||||
|
||||
func (s *Server) DeleteAttachment(guid string) error {
|
||||
return s.attachmentStore.DeleteAttachment(guid)
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
func (s *Server) registerAuthToken(token *model.AuthToken) {
|
||||
|
||||
Reference in New Issue
Block a user