summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-12-20 15:19:53 +0100
committerLibravatar GitHub <noreply@github.com>2021-12-20 15:19:53 +0100
commitcb8688f4298a1a3ed5e28565004588be3c071df0 (patch)
tree038b196e914b949857bf8b7c00f22374408bc1ca /internal/api
parentreturn first offer when no accept header set (#351) (diff)
downloadgotosocial-cb8688f4298a1a3ed5e28565004588be3c071df0.tar.xz
Remove unnecessary storage config variables (#344)
* rewire config to not use extraneous serve vars * rename 'file' to 'local' for consistency * use Type and Size again
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/client/fileserver/fileserver.go15
-rw-r--r--internal/api/client/fileserver/servefile_test.go4
-rw-r--r--internal/api/s2s/user/common.go10
-rw-r--r--internal/api/s2s/user/user.go16
-rw-r--r--internal/api/s2s/webfinger/webfingerget.go6
-rw-r--r--internal/api/security/signaturecheck.go9
6 files changed, 31 insertions, 29 deletions
diff --git a/internal/api/client/fileserver/fileserver.go b/internal/api/client/fileserver/fileserver.go
index 092a15256..c7b08a8e1 100644
--- a/internal/api/client/fileserver/fileserver.go
+++ b/internal/api/client/fileserver/fileserver.go
@@ -22,14 +22,15 @@ import (
"fmt"
"net/http"
- "github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
+ "github.com/superseriousbusiness/gotosocial/internal/uris"
)
const (
+ // FileServeBasePath forms the first part of the fileserver path.
+ FileServeBasePath = "/" + uris.FileserverPath
// AccountIDKey is the url key for account id (an account ulid)
AccountIDKey = "account_id"
// MediaTypeKey is the url key for media type (usually something like attachment or header etc)
@@ -43,20 +44,20 @@ const (
// FileServer implements the RESTAPIModule interface.
// The goal here is to serve requested media files if the gotosocial server is configured to use local storage.
type FileServer struct {
- processor processing.Processor
- storageServeBasePath string
+ processor processing.Processor
}
// New returns a new fileServer module
func New(processor processing.Processor) api.ClientModule {
return &FileServer{
- processor: processor,
- storageServeBasePath: viper.GetString(config.Keys.StorageServeBasePath),
+ processor: processor,
}
}
// Route satisfies the RESTAPIModule interface
func (m *FileServer) Route(s router.Router) error {
- s.AttachHandler(http.MethodGet, fmt.Sprintf("%s/:%s/:%s/:%s/:%s", m.storageServeBasePath, AccountIDKey, MediaTypeKey, MediaSizeKey, FileNameKey), m.ServeFile)
+ // something like "/fileserver/:account_id/:media_type/:media_size/:file_name"
+ fileServePath := fmt.Sprintf("%s/:%s/:%s/:%s/:%s", FileServeBasePath, AccountIDKey, MediaTypeKey, MediaSizeKey, FileNameKey)
+ s.AttachHandler(http.MethodGet, fileServePath, m.ServeFile)
return nil
}
diff --git a/internal/api/client/fileserver/servefile_test.go b/internal/api/client/fileserver/servefile_test.go
index cf05ebbf1..92646640a 100644
--- a/internal/api/client/fileserver/servefile_test.go
+++ b/internal/api/client/fileserver/servefile_test.go
@@ -134,11 +134,11 @@ func (suite *ServeFileTestSuite) TestServeOriginalFileSuccessful() {
},
gin.Param{
Key: fileserver.MediaTypeKey,
- Value: string(media.Attachment),
+ Value: string(media.TypeAttachment),
},
gin.Param{
Key: fileserver.MediaSizeKey,
- Value: string(media.Original),
+ Value: string(media.SizeOriginal),
},
gin.Param{
Key: fileserver.FileNameKey,
diff --git a/internal/api/s2s/user/common.go b/internal/api/s2s/user/common.go
index c03765bfb..39b78714a 100644
--- a/internal/api/s2s/user/common.go
+++ b/internal/api/s2s/user/common.go
@@ -22,21 +22,21 @@ import (
"context"
"github.com/gin-gonic/gin"
- "github.com/superseriousbusiness/gotosocial/internal/util"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
)
// transferContext transfers the signature verifier and signature from the gin context to the request context
func transferContext(c *gin.Context) context.Context {
ctx := c.Request.Context()
- verifier, signed := c.Get(string(util.APRequestingPublicKeyVerifier))
+ verifier, signed := c.Get(string(ap.ContextRequestingPublicKeyVerifier))
if signed {
- ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier)
+ ctx = context.WithValue(ctx, ap.ContextRequestingPublicKeyVerifier, verifier)
}
- signature, signed := c.Get(string(util.APRequestingPublicKeySignature))
+ signature, signed := c.Get(string(ap.ContextRequestingPublicKeySignature))
if signed {
- ctx = context.WithValue(ctx, util.APRequestingPublicKeySignature, signature)
+ ctx = context.WithValue(ctx, ap.ContextRequestingPublicKeySignature, signature)
}
return ctx
diff --git a/internal/api/s2s/user/user.go b/internal/api/s2s/user/user.go
index 891f2c1b1..d1d7d2f58 100644
--- a/internal/api/s2s/user/user.go
+++ b/internal/api/s2s/user/user.go
@@ -24,7 +24,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
- "github.com/superseriousbusiness/gotosocial/internal/util"
+ "github.com/superseriousbusiness/gotosocial/internal/uris"
)
const (
@@ -42,23 +42,23 @@ const (
PageKey = "page"
// UsersBasePath is the base path for serving information about Users eg https://example.org/users
- UsersBasePath = "/" + util.UsersPath
+ UsersBasePath = "/" + uris.UsersPath
// UsersBasePathWithUsername is just the users base path with the Username key in it.
// Use this anywhere you need to know the username of the user being queried.
// Eg https://example.org/users/:username
UsersBasePathWithUsername = UsersBasePath + "/:" + UsernameKey
// UsersPublicKeyPath is a path to a user's public key, for serving bare minimum AP representations.
- UsersPublicKeyPath = UsersBasePathWithUsername + "/" + util.PublicKeyPath
+ UsersPublicKeyPath = UsersBasePathWithUsername + "/" + uris.PublicKeyPath
// UsersInboxPath is for serving POST requests to a user's inbox with the given username key.
- UsersInboxPath = UsersBasePathWithUsername + "/" + util.InboxPath
+ UsersInboxPath = UsersBasePathWithUsername + "/" + uris.InboxPath
// UsersOutboxPath is for serving GET requests to a user's outbox with the given username key.
- UsersOutboxPath = UsersBasePathWithUsername + "/" + util.OutboxPath
+ UsersOutboxPath = UsersBasePathWithUsername + "/" + uris.OutboxPath
// UsersFollowersPath is for serving GET request's to a user's followers list, with the given username key.
- UsersFollowersPath = UsersBasePathWithUsername + "/" + util.FollowersPath
+ UsersFollowersPath = UsersBasePathWithUsername + "/" + uris.FollowersPath
// UsersFollowingPath is for serving GET request's to a user's following list, with the given username key.
- UsersFollowingPath = UsersBasePathWithUsername + "/" + util.FollowingPath
+ UsersFollowingPath = UsersBasePathWithUsername + "/" + uris.FollowingPath
// UsersStatusPath is for serving GET requests to a particular status by a user, with the given username key and status ID
- UsersStatusPath = UsersBasePathWithUsername + "/" + util.StatusesPath + "/:" + StatusIDKey
+ UsersStatusPath = UsersBasePathWithUsername + "/" + uris.StatusesPath + "/:" + StatusIDKey
// UsersStatusRepliesPath is for serving the replies collection of a status.
UsersStatusRepliesPath = UsersStatusPath + "/replies"
)
diff --git a/internal/api/s2s/webfinger/webfingerget.go b/internal/api/s2s/webfinger/webfingerget.go
index 6b0de69a9..465b6b7d3 100644
--- a/internal/api/s2s/webfinger/webfingerget.go
+++ b/internal/api/s2s/webfinger/webfingerget.go
@@ -27,9 +27,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/util"
)
// WebfingerGETRequest swagger:operation GET /.well-known/webfinger webfingerGet
@@ -107,9 +107,9 @@ func (m *Module) WebfingerGETRequest(c *gin.Context) {
// transfer the signature verifier from the gin context to the request context
ctx := c.Request.Context()
- verifier, signed := c.Get(string(util.APRequestingPublicKeyVerifier))
+ verifier, signed := c.Get(string(ap.ContextRequestingPublicKeyVerifier))
if signed {
- ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier)
+ ctx = context.WithValue(ctx, ap.ContextRequestingPublicKeyVerifier, verifier)
}
resp, err := m.processor.GetWebfingerAccount(ctx, username)
diff --git a/internal/api/security/signaturecheck.go b/internal/api/security/signaturecheck.go
index a0f79e44d..1dd6b5f79 100644
--- a/internal/api/security/signaturecheck.go
+++ b/internal/api/security/signaturecheck.go
@@ -1,13 +1,14 @@
package security
import (
- "github.com/sirupsen/logrus"
"net/http"
"net/url"
+ "github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
+
"github.com/gin-gonic/gin"
"github.com/go-fed/httpsig"
- "github.com/superseriousbusiness/gotosocial/internal/util"
)
// SignatureCheck checks whether an incoming http request has been signed. If so, it will check if the domain
@@ -42,10 +43,10 @@ func (m *Module) SignatureCheck(c *gin.Context) {
}
// set the verifier and signature on the context here to save some work further down the line
- c.Set(string(util.APRequestingPublicKeyVerifier), verifier)
+ c.Set(string(ap.ContextRequestingPublicKeyVerifier), verifier)
signature := c.GetHeader("Signature")
if signature != "" {
- c.Set(string(util.APRequestingPublicKeySignature), signature)
+ c.Set(string(ap.ContextRequestingPublicKeySignature), signature)
}
}
}