diff options
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/monaco-io/request/build.go | 18 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/model.go | 2 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/constants/constants.go | 2 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/ocs/message.go | 3 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/room/room.go | 28 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/user/user.go | 58 | ||||
-rw-r--r-- | vendor/modules.txt | 4 |
7 files changed, 75 insertions, 40 deletions
diff --git a/vendor/github.com/monaco-io/request/build.go b/vendor/github.com/monaco-io/request/build.go index c2b1287b..56323d16 100644 --- a/vendor/github.com/monaco-io/request/build.go +++ b/vendor/github.com/monaco-io/request/build.go @@ -14,17 +14,18 @@ func (c *Client) buildRequest() (err error) { return } - c.transport = &http.Transport{} - c.applyHTTPHeader() c.applyBasicAuth() c.applyClient() c.applyTimeout() c.applyCookies() + // Apply transport needs to be called before TLSConfig as TLSConfig modifies + // the http transport + c.applyTransport() c.applyTLSConfig() err = c.applyProxy() - c.client.Transport = c.transport + c.client.Transport = c.Transport return } @@ -84,15 +85,20 @@ func (c *Client) applyProxy() (err error) { if proxy, err = url.Parse(c.ProxyURL); err != nil { return } else if proxy != nil { - c.transport.Proxy = http.ProxyURL(proxy) + c.Transport.Proxy = http.ProxyURL(proxy) } } return } func (c *Client) applyTLSConfig() { - // &tls.Config{InsecureSkipVerify: true} if c.TLSConfig != nil { - c.transport.TLSClientConfig = c.TLSConfig + c.Transport.TLSClientConfig = c.TLSConfig + } +} + +func (c *Client) applyTransport() { + if c.Transport == nil { + c.Transport = &http.Transport{} } } diff --git a/vendor/github.com/monaco-io/request/model.go b/vendor/github.com/monaco-io/request/model.go index 56016477..2a3041e3 100644 --- a/vendor/github.com/monaco-io/request/model.go +++ b/vendor/github.com/monaco-io/request/model.go @@ -39,12 +39,12 @@ type Client struct { ContentType ContentType Cookies []*http.Cookie TLSConfig *tls.Config + Transport *http.Transport // private client *http.Client requestURL requestURL req *http.Request - transport *http.Transport } // BasicAuth Add Username:Password as Basic Auth diff --git a/vendor/gomod.garykim.dev/nc-talk/constants/constants.go b/vendor/gomod.garykim.dev/nc-talk/constants/constants.go index c70e4daa..44473546 100644 --- a/vendor/gomod.garykim.dev/nc-talk/constants/constants.go +++ b/vendor/gomod.garykim.dev/nc-talk/constants/constants.go @@ -21,5 +21,5 @@ const ( // RemoteDavEndpoint returns the endpoint for the Dav API for Nextcloud func RemoteDavEndpoint(username string, davType string) string { - return "/remote.php/dav/" + username + "/" + davType + "/" + return "/remote.php/dav/" + davType + "/" + username + "/" } diff --git a/vendor/gomod.garykim.dev/nc-talk/ocs/message.go b/vendor/gomod.garykim.dev/nc-talk/ocs/message.go index 9de28b47..d4766006 100644 --- a/vendor/gomod.garykim.dev/nc-talk/ocs/message.go +++ b/vendor/gomod.garykim.dev/nc-talk/ocs/message.go @@ -43,7 +43,10 @@ const ( ) // TalkRoomMessageData describes the data part of a ocs response for a Talk room message +// +// Error will be set if a message request ran into an error. type TalkRoomMessageData struct { + Error error `json:"-"` Message string `json:"message"` ID int `json:"id"` ActorType ActorType `json:"actorType"` diff --git a/vendor/gomod.garykim.dev/nc-talk/room/room.go b/vendor/gomod.garykim.dev/nc-talk/room/room.go index b53b01fc..1ee73740 100644 --- a/vendor/gomod.garykim.dev/nc-talk/room/room.go +++ b/vendor/gomod.garykim.dev/nc-talk/room/room.go @@ -33,10 +33,14 @@ var ( ErrEmptyToken = errors.New("given an empty token") // ErrRoomNotFound is returned when a room with the given token could not be found ErrRoomNotFound = errors.New("room could not be found") + // ErrUnauthorized is returned when the room could not be accessed due to being unauthorized + ErrUnauthorized = errors.New("unauthorized error when accessing room") // ErrNotModeratorInLobby is returned when the room is in lobby mode but the user is not a moderator ErrNotModeratorInLobby = errors.New("room is in lobby mode but user is not a moderator") // ErrUnexpectedReturnCode is returned when the server did not respond with an expected return code ErrUnexpectedReturnCode = errors.New("unexpected return code") + // ErrTooManyRequests is returned if the server returns a 429 + ErrTooManyRequests = errors.New("too many requests") ) // TalkRoom represents a room in Nextcloud Talk @@ -62,7 +66,7 @@ func NewTalkRoom(tuser *user.TalkUser, token string) (*TalkRoom, error) { // SendMessage sends a message in the Talk room func (t *TalkRoom) SendMessage(msg string) (*ocs.TalkRoomMessageData, error) { - url := t.User.NextcloudURL + constants.BaseEndpoint + "/chat/" + t.Token + url := t.User.NextcloudURL + constants.BaseEndpoint + "chat/" + t.Token requestParams := map[string]string{ "message": msg, } @@ -93,7 +97,7 @@ func (t *TalkRoom) ReceiveMessages(ctx context.Context) (chan ocs.TalkRoomMessag if err != nil { return nil, err } - url := t.User.NextcloudURL + constants.BaseEndpoint + "/chat/" + t.Token + url := t.User.NextcloudURL + constants.BaseEndpoint + "chat/" + t.Token requestParam := map[string]string{ "lookIntoFuture": "1", "includeLastKnown": "0", @@ -127,6 +131,24 @@ func (t *TalkRoom) ReceiveMessages(ctx context.Context) (chan ocs.TalkRoomMessag if err != nil { continue } + + // If it seems that we no longer have access to the chat for one reason or another, stop the goroutine and set error in the next return. + if res.StatusCode == 404 { + _ = res.Body.Close() + c <- ocs.TalkRoomMessageData{Error: ErrRoomNotFound} + return + } + if res.StatusCode == 401 { + _ = res.Body.Close() + c <- ocs.TalkRoomMessageData{Error: ErrUnauthorized} + return + } + if res.StatusCode == 429 { + _ = res.Body.Close() + c <- ocs.TalkRoomMessageData{Error: ErrTooManyRequests} + return + } + if res.StatusCode == 200 { lastKnown = res.Header.Get("X-Chat-Last-Given") data, err := ioutil.ReadAll(res.Body) @@ -154,7 +176,7 @@ func (t *TalkRoom) TestConnection() error { if t.Token == "" { return ErrEmptyToken } - url := t.User.NextcloudURL + constants.BaseEndpoint + "/chat/" + t.Token + url := t.User.NextcloudURL + constants.BaseEndpoint + "chat/" + t.Token requestParam := map[string]string{ "lookIntoFuture": "0", "includeLastKnown": "0", diff --git a/vendor/gomod.garykim.dev/nc-talk/user/user.go b/vendor/gomod.garykim.dev/nc-talk/user/user.go index 08c01e33..2b42dacf 100644 --- a/vendor/gomod.garykim.dev/nc-talk/user/user.go +++ b/vendor/gomod.garykim.dev/nc-talk/user/user.go @@ -87,38 +87,38 @@ type Capabilities struct { // RoomInfo contains information about a room type RoomInfo struct { - Token string `json:"token"` - Name string `json:"name"` - DisplayName string `json:"displayName"` - SessionID string `json:"sessionId"` - ObjectType string `json:"objectType"` - ObjectID string `json:"objectId"` - Type int `json:"type"` - ParticipantType int `json:"participantType"` - ParticipantFlags int `json:"participantFlags"` - ReadOnly int `json:"readOnly"` - LastPing int `json:"lastPing"` - LastActivity int `json:"lastActivity"` - NotificationLevel int `json:"notificationLevel"` - LobbyState int `json:"lobbyState"` - LobbyTimer int `json:"lobbyTimer"` - UnreadMessages int `json:"unreadMessages"` - LastReadMessage int `json:"lastReadMessage"` - HasPassword bool `json:"hasPassword"` - HasCall bool `json:"hasCall"` - CanStartCall bool `json:"canStartCall"` - CanDeleteConversation bool `json:"canDeleteConversation"` - CanLeaveConversation bool `json:"canLeaveConversation"` - IsFavorite bool `json:"isFavorite"` - UnreadMention bool `json:"unreadMention"` - LastMessage ocs.TalkRoomMessageData `json:"lastMessage"` + Token string `json:"token"` + Name string `json:"name"` + DisplayName string `json:"displayName"` + SessionID string `json:"sessionId"` + ObjectType string `json:"objectType"` + ObjectID string `json:"objectId"` + Type int `json:"type"` + ParticipantType int `json:"participantType"` + ParticipantFlags int `json:"participantFlags"` + ReadOnly int `json:"readOnly"` + LastPing int `json:"lastPing"` + LastActivity int `json:"lastActivity"` + NotificationLevel int `json:"notificationLevel"` + LobbyState int `json:"lobbyState"` + LobbyTimer int `json:"lobbyTimer"` + UnreadMessages int `json:"unreadMessages"` + LastReadMessage int `json:"lastReadMessage"` + HasPassword bool `json:"hasPassword"` + HasCall bool `json:"hasCall"` + CanStartCall bool `json:"canStartCall"` + CanDeleteConversation bool `json:"canDeleteConversation"` + CanLeaveConversation bool `json:"canLeaveConversation"` + IsFavorite bool `json:"isFavorite"` + UnreadMention bool `json:"unreadMention"` + LastMessage *ocs.TalkRoomMessageData `json:"lastMessage"` } // NewUser returns a TalkUser instance // The url should be the full URL of the Nextcloud instance (e.g. https://cloud.mydomain.me) func NewUser(url string, username string, password string, config *TalkUserConfig) (*TalkUser, error) { return &TalkUser{ - NextcloudURL: url, + NextcloudURL: strings.TrimSuffix(url, "/"), User: username, Pass: password, Config: config, @@ -143,7 +143,11 @@ func (t *TalkUser) RequestClient(client request.Client) *request.Client { // Set Nextcloud URL if there is no host if !strings.HasPrefix(client.URL, t.NextcloudURL) { - client.URL = t.NextcloudURL + "/" + client.URL + if strings.HasPrefix(client.URL, "/") { + client.URL = t.NextcloudURL + client.URL + } else { + client.URL = t.NextcloudURL + "/" + client.URL + } } // Set TLS Config diff --git a/vendor/modules.txt b/vendor/modules.txt index 0db6fba4..0d0117c3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -180,7 +180,7 @@ github.com/mgutz/ansi github.com/missdeer/golib/ic # github.com/mitchellh/mapstructure v1.3.3 github.com/mitchellh/mapstructure -# github.com/monaco-io/request v1.0.4 +# github.com/monaco-io/request v1.0.5 github.com/monaco-io/request # github.com/mreiferson/go-httpclient v0.0.0-20160630210159-31f0106b4474 ## explicit @@ -362,7 +362,7 @@ golang.org/x/text/transform golang.org/x/text/unicode/bidi golang.org/x/text/unicode/norm golang.org/x/text/width -# gomod.garykim.dev/nc-talk v0.1.6 +# gomod.garykim.dev/nc-talk v0.1.7 ## explicit gomod.garykim.dev/nc-talk/constants gomod.garykim.dev/nc-talk/ocs |