diff options
| author | 2023-01-02 13:10:50 +0100 | |
|---|---|---|
| committer | 2023-01-02 12:10:50 +0000 | |
| commit | 941893a774c83802afdc4cc76e1d30c59b6c5585 (patch) | |
| tree | 6e7296146dedfeac8e83655157270f41e190724b /internal/api/client/app | |
| parent | [chore]: Bump github.com/abema/go-mp4 from 0.8.0 to 0.9.0 (#1287) (diff) | |
| download | gotosocial-941893a774c83802afdc4cc76e1d30c59b6c5585.tar.xz | |
[chore] The Big Middleware and API Refactor (tm) (#1250)
* interim commit: start refactoring middlewares into package under router
* another interim commit, this is becoming a big job
* another fucking massive interim commit
* refactor bookmarks to new style
* ambassador, wiz zeze commits you are spoiling uz
* she compiles, we're getting there
* we're just normal men; we're just innocent men
* apiutil
* whoopsie
* i'm glad noone reads commit msgs haha :blob_sweat:
* use that weirdo go-bytesize library for maxMultipartMemory
* fix media module paths
Diffstat (limited to 'internal/api/client/app')
| -rw-r--r-- | internal/api/client/app/app.go | 48 | ||||
| -rw-r--r-- | internal/api/client/app/app_test.go | 21 | ||||
| -rw-r--r-- | internal/api/client/app/appcreate.go | 126 | 
3 files changed, 0 insertions, 195 deletions
| diff --git a/internal/api/client/app/app.go b/internal/api/client/app/app.go deleted file mode 100644 index 0bbeb6cc9..000000000 --- a/internal/api/client/app/app.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -   GoToSocial -   Copyright (C) 2021-2022 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 app - -import ( -	"net/http" - -	"github.com/superseriousbusiness/gotosocial/internal/api" -	"github.com/superseriousbusiness/gotosocial/internal/processing" -	"github.com/superseriousbusiness/gotosocial/internal/router" -) - -// BasePath is the base path for this api module -const BasePath = "/api/v1/apps" - -// Module implements the ClientAPIModule interface for requests relating to registering/removing applications -type Module struct { -	processor processing.Processor -} - -// New returns a new auth module -func New(processor processing.Processor) api.ClientModule { -	return &Module{ -		processor: processor, -	} -} - -// Route satisfies the RESTAPIModule interface -func (m *Module) Route(s router.Router) error { -	s.AttachHandler(http.MethodPost, BasePath, m.AppsPOSTHandler) -	return nil -} diff --git a/internal/api/client/app/app_test.go b/internal/api/client/app/app_test.go deleted file mode 100644 index 5c1981ba1..000000000 --- a/internal/api/client/app/app_test.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -   GoToSocial -   Copyright (C) 2021-2022 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 app_test - -// TODO: write tests diff --git a/internal/api/client/app/appcreate.go b/internal/api/client/app/appcreate.go deleted file mode 100644 index 6060c9480..000000000 --- a/internal/api/client/app/appcreate.go +++ /dev/null @@ -1,126 +0,0 @@ -/* -   GoToSocial -   Copyright (C) 2021-2022 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 app - -import ( -	"fmt" -	"net/http" - -	"github.com/gin-gonic/gin" -	"github.com/superseriousbusiness/gotosocial/internal/api" -	"github.com/superseriousbusiness/gotosocial/internal/api/model" -	"github.com/superseriousbusiness/gotosocial/internal/gtserror" -	"github.com/superseriousbusiness/gotosocial/internal/oauth" -) - -// these consts are used to ensure users can't spam huge entries into our database -const ( -	formFieldLen    = 1024 -	formRedirectLen = 2056 -) - -// AppsPOSTHandler swagger:operation POST /api/v1/apps appCreate -// -// Register a new application on this instance. -// -// The registered application can be used to obtain an application token. -// This can then be used to register a new account, or (through user auth) obtain an access token. -// -// The parameters can also be given in the body of the request, as JSON, if the content-type is set to 'application/json'. -// The parameters can also be given in the body of the request, as XML, if the content-type is set to 'application/xml'. -// -//	--- -//	tags: -//	- apps -// -//	consumes: -//	- application/json -//	- application/xml -//	- application/x-www-form-urlencoded -// -//	produces: -//	- application/json -// -//	responses: -//		'200': -//			description: "The newly-created application." -//			schema: -//				"$ref": "#/definitions/application" -//		'400': -//			description: bad request -//		'401': -//			description: unauthorized -//		'403': -//			description: forbidden -//		'404': -//			description: not found -//		'406': -//			description: not acceptable -//		'500': -//			description: internal server error -func (m *Module) AppsPOSTHandler(c *gin.Context) { -	authed, err := oauth.Authed(c, false, false, false, false) -	if err != nil { -		api.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) -		return -	} - -	if _, err := api.NegotiateAccept(c, api.JSONAcceptHeaders...); err != nil { -		api.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) -		return -	} - -	form := &model.ApplicationCreateRequest{} -	if err := c.ShouldBind(form); err != nil { -		api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) -		return -	} - -	if len([]rune(form.ClientName)) > formFieldLen { -		err := fmt.Errorf("client_name must be less than %d characters", formFieldLen) -		api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) -		return -	} - -	if len([]rune(form.RedirectURIs)) > formRedirectLen { -		err := fmt.Errorf("redirect_uris must be less than %d characters", formRedirectLen) -		api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) -		return -	} - -	if len([]rune(form.Scopes)) > formFieldLen { -		err := fmt.Errorf("scopes must be less than %d characters", formFieldLen) -		api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) -		return -	} - -	if len([]rune(form.Website)) > formFieldLen { -		err := fmt.Errorf("website must be less than %d characters", formFieldLen) -		api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) -		return -	} - -	apiApp, errWithCode := m.processor.AppCreate(c.Request.Context(), authed, form) -	if errWithCode != nil { -		api.ErrorHandler(c, errWithCode, m.processor.InstanceGet) -		return -	} - -	c.JSON(http.StatusOK, apiApp) -} | 
