diff options
Diffstat (limited to 'internal/api/client')
| -rw-r--r-- | internal/api/client/account/account.go | 17 | ||||
| -rw-r--r-- | internal/api/client/account/followers.go | 49 | ||||
| -rw-r--r-- | internal/api/client/account/statuses.go | 117 | 
3 files changed, 183 insertions, 0 deletions
diff --git a/internal/api/client/account/account.go b/internal/api/client/account/account.go index dce810202..1e4b716f5 100644 --- a/internal/api/client/account/account.go +++ b/internal/api/client/account/account.go @@ -32,6 +32,17 @@ import (  )  const ( +	// LimitKey is for setting the return amount limit for eg., requesting an account's statuses +	LimitKey = "limit" +	// ExcludeRepliesKey is for specifying whether to exclude replies in a list of returned statuses by an account. +	ExcludeRepliesKey = "exclude_replies" +	// PinnedKey is for specifying whether to include pinned statuses in a list of returned statuses by an account. +	PinnedKey = "pinned" +	// MaxIDKey is for specifying the maximum ID of the status to retrieve. +	MaxIDKey = "max_id" +	// MediaOnlyKey is for specifying that only statuses with media should be returned in a list of returned statuses by an account. +	MediaOnlyKey = "only_media" +  	// IDKey is the key to use for retrieving account ID in requests  	IDKey = "id"  	// BasePath is the base API path for this module @@ -42,6 +53,10 @@ const (  	VerifyPath = BasePath + "/verify_credentials"  	// UpdateCredentialsPath is for updating account credentials  	UpdateCredentialsPath = BasePath + "/update_credentials" +	// GetStatusesPath is for showing an account's statuses +	GetStatusesPath = BasePathWithID + "/statuses" +	// GetFollowersPath is for showing an account's followers +	GetFollowersPath = BasePathWithID + "/followers"  )  // Module implements the ClientAPIModule interface for account-related actions @@ -65,6 +80,8 @@ func (m *Module) Route(r router.Router) error {  	r.AttachHandler(http.MethodPost, BasePath, m.AccountCreatePOSTHandler)  	r.AttachHandler(http.MethodGet, BasePathWithID, m.muxHandler)  	r.AttachHandler(http.MethodPatch, BasePathWithID, m.muxHandler) +	r.AttachHandler(http.MethodGet, GetStatusesPath, m.AccountStatusesGETHandler) +	r.AttachHandler(http.MethodGet, GetFollowersPath, m.AccountFollowersGETHandler)  	return nil  } diff --git a/internal/api/client/account/followers.go b/internal/api/client/account/followers.go new file mode 100644 index 000000000..3401df24c --- /dev/null +++ b/internal/api/client/account/followers.go @@ -0,0 +1,49 @@ +/* +   GoToSocial +   Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + +   This program is free software: you can redistribute it and/or modify +   it under the terms of the GNU Affero General Public License as published by +   the Free Software Foundation, either version 3 of the License, or +   (at your option) any later version. + +   This program is distributed in the hope that it will be useful, +   but WITHOUT ANY WARRANTY; without even the implied warranty of +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +   GNU Affero General Public License for more details. + +   You should have received a copy of the GNU Affero General Public License +   along with this program.  If not, see <http://www.gnu.org/licenses/>. +*/ + +package account + +import ( +	"net/http" + +	"github.com/gin-gonic/gin" +	"github.com/superseriousbusiness/gotosocial/internal/oauth" +) + +// AccountFollowersGETHandler serves the followers of the requested account, if they're visible to the requester. +func (m *Module) AccountFollowersGETHandler(c *gin.Context) { +	authed, err := oauth.Authed(c, true, true, true, true) +	if err != nil { +		c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) +		return +	} + +	targetAcctID := c.Param(IDKey) +	if targetAcctID == "" { +		c.JSON(http.StatusBadRequest, gin.H{"error": "no account id specified"}) +		return +	} + +	followers, errWithCode := m.processor.AccountFollowersGet(authed, targetAcctID) +	if errWithCode != nil { +		c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()}) +		return +	} + +	c.JSON(http.StatusOK, followers) +} diff --git a/internal/api/client/account/statuses.go b/internal/api/client/account/statuses.go new file mode 100644 index 000000000..f03a942f3 --- /dev/null +++ b/internal/api/client/account/statuses.go @@ -0,0 +1,117 @@ +/* +   GoToSocial +   Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + +   This program is free software: you can redistribute it and/or modify +   it under the terms of the GNU Affero General Public License as published by +   the Free Software Foundation, either version 3 of the License, or +   (at your option) any later version. + +   This program is distributed in the hope that it will be useful, +   but WITHOUT ANY WARRANTY; without even the implied warranty of +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +   GNU Affero General Public License for more details. + +   You should have received a copy of the GNU Affero General Public License +   along with this program.  If not, see <http://www.gnu.org/licenses/>. +*/ + +package account + +import ( +	"net/http" +	"strconv" + +	"github.com/gin-gonic/gin" +	"github.com/superseriousbusiness/gotosocial/internal/oauth" +) + +// AccountStatusesGETHandler serves the statuses of the requested account, if they're visible to the requester. +// +// Several different filters might be passed into this function in the query: +// +// 	limit -- show only limit number of statuses +// 	exclude_replies -- exclude statuses that are a reply to another status +// 	max_id -- the maximum ID of the status to show +// 	pinned -- show only pinned statuses +// 	media_only -- show only statuses that have media attachments +func (m *Module) AccountStatusesGETHandler(c *gin.Context) { +	l := m.log.WithField("func", "AccountStatusesGETHandler") + +	authed, err := oauth.Authed(c, false, false, false, false) +	if err != nil { +		l.Debugf("error authing: %s", err) +		c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) +		return +	} + +	targetAcctID := c.Param(IDKey) +	if targetAcctID == "" { +		l.Debug("no account id specified in query") +		c.JSON(http.StatusBadRequest, gin.H{"error": "no account id specified"}) +		return +	} + +	limit := 30 +	limitString := c.Query(LimitKey) +	if limitString != "" { +		i, err := strconv.ParseInt(limitString, 10, 64) +		if err != nil { +			l.Debugf("error parsing limit string: %s", err) +			c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse limit query param"}) +			return +		} +		limit = int(i) +	} + +	excludeReplies := false +	excludeRepliesString := c.Query(ExcludeRepliesKey) +	if excludeRepliesString != "" { +		i, err := strconv.ParseBool(excludeRepliesString) +		if err != nil { +			l.Debugf("error parsing replies string: %s", err) +			c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse exclude replies query param"}) +			return +		} +		excludeReplies = i +	} + +	maxID := "" +	maxIDString := c.Query(MaxIDKey) +	if maxIDString != "" { +		maxID = maxIDString +	} + +	pinned := false +	pinnedString := c.Query(PinnedKey) +	if pinnedString != "" { +		i, err := strconv.ParseBool(pinnedString) +		if err != nil { +			l.Debugf("error parsing pinned string: %s", err) +			c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse pinned query param"}) +			return +		} +		pinned = i +	} + +	mediaOnly := false +	mediaOnlyString := c.Query(MediaOnlyKey) +	if mediaOnlyString != "" { +		i, err := strconv.ParseBool(mediaOnlyString) +		if err != nil { +			l.Debugf("error parsing media only string: %s", err) +			c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse media only query param"}) +			return +		} +		mediaOnly = i +	} + +	statuses, errWithCode := m.processor.AccountStatusesGet(authed, targetAcctID, limit, excludeReplies, maxID, pinned, mediaOnly) +	if errWithCode != nil { +		l.Debugf("error from processor account statuses get: %s", errWithCode) +		c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()}) +		return +	} + +	c.JSON(http.StatusOK, statuses) +}  | 
