diff options
Diffstat (limited to 'internal/api/client/timelines/home.go')
-rw-r--r-- | internal/api/client/timelines/home.go | 58 |
1 files changed, 17 insertions, 41 deletions
diff --git a/internal/api/client/timelines/home.go b/internal/api/client/timelines/home.go index f63d14fd3..f64d61287 100644 --- a/internal/api/client/timelines/home.go +++ b/internal/api/client/timelines/home.go @@ -18,9 +18,7 @@ package timelines import ( - "fmt" "net/http" - "strconv" "github.com/gin-gonic/gin" apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" @@ -120,49 +118,27 @@ func (m *Module) HomeTimelineGETHandler(c *gin.Context) { return } - maxID := "" - maxIDString := c.Query(MaxIDKey) - if maxIDString != "" { - maxID = maxIDString - } - - sinceID := "" - sinceIDString := c.Query(SinceIDKey) - if sinceIDString != "" { - sinceID = sinceIDString - } - - minID := "" - minIDString := c.Query(MinIDKey) - if minIDString != "" { - minID = minIDString - } - - limit := 20 - limitString := c.Query(LimitKey) - if limitString != "" { - i, err := strconv.ParseInt(limitString, 10, 32) - if err != nil { - err := fmt.Errorf("error parsing %s: %s", LimitKey, err) - apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) - return - } - limit = int(i) + limit, errWithCode := apiutil.ParseLimit(c.Query(apiutil.LimitKey), 20) + if errWithCode != nil { + apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) + return } - local := false - localString := c.Query(LocalKey) - if localString != "" { - i, err := strconv.ParseBool(localString) - if err != nil { - err := fmt.Errorf("error parsing %s: %s", LocalKey, err) - apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) - return - } - local = i + local, errWithCode := apiutil.ParseLocal(c.Query(apiutil.LocalKey), false) + if errWithCode != nil { + apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) + return } - resp, errWithCode := m.processor.HomeTimelineGet(c.Request.Context(), authed, maxID, sinceID, minID, limit, local) + resp, errWithCode := m.processor.Timeline().HomeTimelineGet( + c.Request.Context(), + authed, + c.Query(MaxIDKey), + c.Query(SinceIDKey), + c.Query(MinIDKey), + limit, + local, + ) if errWithCode != nil { apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) return |