diff --git a/api/message.go b/api/message.go index ca818109a..8c01a04bf 100644 --- a/api/message.go +++ b/api/message.go @@ -3,13 +3,13 @@ package api import ( "encoding/json" "errors" + "net/url" "strconv" "strings" "time" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" - "github.com/gotify/location" "github.com/gotify/server/v2/auth" "github.com/gotify/server/v2/model" ) @@ -104,13 +104,10 @@ func buildWithPaging(ctx *gin.Context, paging *pagingParams, messages []*model.M if len(messages) > paging.Limit { useMessages = messages[:len(messages)-1] since = useMessages[len(useMessages)-1].ID - url := location.Get(ctx) - url.Path = ctx.Request.URL.Path - query := url.Query() + query := url.Values{} query.Add("limit", strconv.Itoa(paging.Limit)) query.Add("since", strconv.FormatUint(uint64(since), 10)) - url.RawQuery = query.Encode() - next = url.String() + next = ctx.Request.URL.Path + "?" + query.Encode() } return &model.PagedMessages{ Paging: model.Paging{Size: len(useMessages), Limit: paging.Limit, Next: next, Since: since}, diff --git a/api/message_test.go b/api/message_test.go index 2a1d4a2b9..f3047a526 100644 --- a/api/message_test.go +++ b/api/message_test.go @@ -52,7 +52,7 @@ func (s *MessageSuite) Test_ensureCorrectJsonRepresentation() { t, _ := time.Parse("2006/01/02", "2017/01/02") actual := &model.PagedMessages{ - Paging: model.Paging{Limit: 5, Since: 122, Size: 5, Next: "http://example.com/message?limit=5&since=122"}, + Paging: model.Paging{Limit: 5, Since: 122, Size: 5, Next: "/message?limit=5&since=122"}, Messages: []*model.MessageExternal{{ID: 55, ApplicationID: 2, Message: "hi", Title: "hi", Date: t, Priority: intPtr(4), Extras: map[string]any{ "test::string": "string", "test::array": []any{1, 2, 3}, @@ -60,7 +60,7 @@ func (s *MessageSuite) Test_ensureCorrectJsonRepresentation() { "test::float": 0.5, }}}, } - test.JSONEquals(s.T(), actual, `{"paging": {"limit":5, "since": 122, "size": 5, "next": "http://example.com/message?limit=5&since=122"}, + test.JSONEquals(s.T(), actual, `{"paging": {"limit":5, "since": 122, "size": 5, "next": "/message?limit=5&since=122"}, "messages": [{"id":55,"appid":2,"message":"hi","title":"hi","priority":4,"date":"2017-01-02T00:00:00Z","extras":{"test::string":"string","test::array":[1,2,3],"test::int":1,"test::float":0.5}}]}`) } @@ -99,7 +99,7 @@ func (s *MessageSuite) Test_GetMessages_WithLimit_ReturnsNext() { // Since: entries with ids from 100 - 96 will be returned (5 entries) expected := &model.PagedMessages{ - Paging: model.Paging{Limit: 5, Size: 5, Since: 96, Next: "http://example.com/messages?limit=5&since=96"}, + Paging: model.Paging{Limit: 5, Size: 5, Since: 96, Next: "/messages?limit=5&since=96"}, Messages: toExternalMessages(messages[:5]), } @@ -123,7 +123,7 @@ func (s *MessageSuite) Test_GetMessages_WithLimit_WithSince_ReturnsNext() { // Since: entries with ids from 54 - 42 will be returned (13 entries) expected := &model.PagedMessages{ - Paging: model.Paging{Limit: 13, Size: 13, Since: 42, Next: "http://example.com/messages?limit=13&since=42"}, + Paging: model.Paging{Limit: 13, Size: 13, Since: 42, Next: "/messages?limit=13&since=42"}, Messages: toExternalMessages(messages[46 : 46+13]), } test.BodyEquals(s.T(), expected, s.recorder) @@ -189,7 +189,7 @@ func (s *MessageSuite) Test_GetMessagesWithToken_WithLimit_ReturnsNext() { // Since: entries with ids from 100 - 92 will be returned (9 entries) expected := &model.PagedMessages{ - Paging: model.Paging{Limit: 9, Size: 9, Since: 92, Next: "http://example.com/app/2/message?limit=9&since=92"}, + Paging: model.Paging{Limit: 9, Size: 9, Since: 92, Next: "/app/2/message?limit=9&since=92"}, Messages: toExternalMessages(messages[:9]), } @@ -212,7 +212,7 @@ func (s *MessageSuite) Test_GetMessagesWithToken_WithLimit_WithSince_ReturnsNext // Since: entries with ids from 54 - 42 will be returned (13 entries) expected := &model.PagedMessages{ - Paging: model.Paging{Limit: 13, Size: 13, Since: 42, Next: "http://example.com/app/2/message?limit=13&since=42"}, + Paging: model.Paging{Limit: 13, Size: 13, Since: 42, Next: "/app/2/message?limit=13&since=42"}, Messages: toExternalMessages(messages[46 : 46+13]), } test.BodyEquals(s.T(), expected, s.recorder) diff --git a/docs/spec.json b/docs/spec.json index 38261bb1b..a9f17989d 100644 --- a/docs/spec.json +++ b/docs/spec.json @@ -3211,11 +3211,11 @@ "example": 123 }, "next": { - "description": "The request url for the next page. Empty/Null when no next page is available.", + "description": "The relative path for the next page. Empty/Null when no next page is available. Should be combined with the gotify base url.", "type": "string", "x-go-name": "Next", "readOnly": true, - "example": "http://example.com/message?limit=50\u0026since=123456" + "example": "/message?limit=50\u0026since=123456" }, "since": { "description": "The ID of the last message returned in the current request. Use this as alternative to the next link.", diff --git a/model/paging.go b/model/paging.go index c198c13ba..117c3e605 100644 --- a/model/paging.go +++ b/model/paging.go @@ -6,11 +6,11 @@ package model // // swagger:model Paging type Paging struct { - // The request url for the next page. Empty/Null when no next page is available. + // The relative path for the next page. Empty/Null when no next page is available. Should be combined with the gotify base url. // // read only: true // required: false - // example: http://example.com/message?limit=50&since=123456 + // example: /message?limit=50&since=123456 Next string `json:"next,omitempty"` // The amount of messages that got returned in the current request. //