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
This commit is contained in:
tobi 2021-12-20 15:19:53 +01:00 committed by GitHub
commit cb8688f429
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 310 additions and 408 deletions

View file

@ -29,7 +29,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
func (p *processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
@ -57,7 +57,7 @@ func (p *processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel
block.Account = requestingAccount
block.TargetAccountID = targetAccountID
block.TargetAccount = targetAccount
block.URI = util.GenerateURIForBlock(requestingAccount.Username, newBlockID)
block.URI = uris.GenerateURIForBlock(requestingAccount.Username, newBlockID)
// whack it in the database
if err := p.db.Put(ctx, block); err != nil {

View file

@ -29,7 +29,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
func (p *processor) FollowCreate(ctx context.Context, requestingAccount *gtsmodel.Account, form *apimodel.AccountFollowRequest) (*apimodel.Relationship, gtserror.WithCode) {
@ -76,7 +76,7 @@ func (p *processor) FollowCreate(ctx context.Context, requestingAccount *gtsmode
AccountID: requestingAccount.ID,
TargetAccountID: form.ID,
ShowReblogs: true,
URI: util.GenerateURIForFollow(requestingAccount.Username, newFollowID),
URI: uris.GenerateURIForFollow(requestingAccount.Username, newFollowID),
Notify: false,
}
if form.Reblogs != nil {

View file

@ -159,7 +159,7 @@ func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHead
}
// do the setting
avatarInfo, err := p.mediaHandler.ProcessHeaderOrAvatar(ctx, buf.Bytes(), accountID, media.Avatar, "")
avatarInfo, err := p.mediaHandler.ProcessHeaderOrAvatar(ctx, buf.Bytes(), accountID, media.TypeAvatar, "")
if err != nil {
return nil, fmt.Errorf("error processing avatar: %s", err)
}
@ -193,7 +193,7 @@ func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHead
}
// do the setting
headerInfo, err := p.mediaHandler.ProcessHeaderOrAvatar(ctx, buf.Bytes(), accountID, media.Header, "")
headerInfo, err := p.mediaHandler.ProcessHeaderOrAvatar(ctx, buf.Bytes(), accountID, media.TypeHeader, "")
if err != nil {
return nil, fmt.Errorf("error processing header: %s", err)
}

View file

@ -27,7 +27,7 @@ import (
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
func (p *processor) GetUser(ctx context.Context, requestedUsername string, requestURL *url.URL) (interface{}, gtserror.WithCode) {
@ -39,13 +39,13 @@ func (p *processor) GetUser(ctx context.Context, requestedUsername string, reque
var requestedPerson vocab.ActivityStreamsPerson
switch {
case util.IsPublicKeyPath(requestURL):
case uris.IsPublicKeyPath(requestURL):
// if it's a public key path, we don't need to authenticate but we'll only serve the bare minimum user profile needed for the public key
requestedPerson, err = p.tc.AccountToASMinimal(ctx, requestedAccount)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
case util.IsUserPath(requestURL):
case uris.IsUserPath(requestURL):
// if it's a user path, we want to fully authenticate the request before we serve any data, and then we can serve a more complete profile
requestingAccountURI, authenticated, err := p.federator.AuthenticateFederatedRequest(ctx, requestedUsername)
if err != nil || !authenticated {

View file

@ -22,11 +22,11 @@ import (
"context"
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/ap"
)
func (p *processor) PostInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (bool, error) {
// pass the fromFederator channel through to postInbox, since it'll be needed later
contextWithChannel := context.WithValue(ctx, util.APFromFederatorChanKey, p.fromFederator)
contextWithChannel := context.WithValue(ctx, ap.ContextFromFederatorChan, p.fromFederator)
return p.federator.FederatingActor().PostInbox(contextWithChannel, w, r)
}

View file

@ -72,7 +72,7 @@ func (p *processor) GetFile(ctx context.Context, account *gtsmodel.Account, form
content := &apimodel.Content{}
var storagePath string
switch mediaType {
case media.Emoji:
case media.TypeEmoji:
e := &gtsmodel.Emoji{}
if err := p.db.GetByID(ctx, wantedMediaID, e); err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("emoji %s could not be taken from the db: %s", wantedMediaID, err))
@ -81,16 +81,16 @@ func (p *processor) GetFile(ctx context.Context, account *gtsmodel.Account, form
return nil, gtserror.NewErrorNotFound(fmt.Errorf("emoji %s has been disabled", wantedMediaID))
}
switch mediaSize {
case media.Original:
case media.SizeOriginal:
content.ContentType = e.ImageContentType
storagePath = e.ImagePath
case media.Static:
case media.SizeStatic:
content.ContentType = e.ImageStaticContentType
storagePath = e.ImageStaticPath
default:
return nil, gtserror.NewErrorNotFound(fmt.Errorf("media size %s not recognized for emoji", mediaSize))
}
case media.Attachment, media.Header, media.Avatar:
case media.TypeAttachment, media.TypeHeader, media.TypeAvatar:
a, err := p.db.GetAttachmentByID(ctx, wantedMediaID)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("attachment %s could not be taken from the db: %s", wantedMediaID, err))
@ -99,10 +99,10 @@ func (p *processor) GetFile(ctx context.Context, account *gtsmodel.Account, form
return nil, gtserror.NewErrorNotFound(fmt.Errorf("attachment %s is not owned by %s", wantedMediaID, form.AccountID))
}
switch mediaSize {
case media.Original:
case media.SizeOriginal:
content.ContentType = a.File.ContentType
storagePath = a.File.Path
case media.Small:
case media.SizeSmall:
content.ContentType = a.Thumbnail.ContentType
storagePath = a.Thumbnail.Path
default:

View file

@ -30,17 +30,17 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/text"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, gtserror.WithCode) {
uris := util.GenerateURIsForAccount(account.Username)
accountURIs := uris.GenerateURIsForAccount(account.Username)
thisStatusID, err := id.NewULID()
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
thisStatusURI := fmt.Sprintf("%s/%s", uris.StatusesURI, thisStatusID)
thisStatusURL := fmt.Sprintf("%s/%s", uris.StatusesURL, thisStatusID)
thisStatusURI := fmt.Sprintf("%s/%s", accountURIs.StatusesURI, thisStatusID)
thisStatusURL := fmt.Sprintf("%s/%s", accountURIs.StatusesURL, thisStatusID)
newStatus := &gtsmodel.Status{
ID: thisStatusID,

View file

@ -30,7 +30,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
func (p *processor) Fave(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
@ -76,7 +76,7 @@ func (p *processor) Fave(ctx context.Context, requestingAccount *gtsmodel.Accoun
TargetAccount: targetStatus.Account,
StatusID: targetStatus.ID,
Status: targetStatus,
URI: util.GenerateURIForLike(requestingAccount.Username, thisFaveID),
URI: uris.GenerateURIForLike(requestingAccount.Username, thisFaveID),
}
if err := p.db.Put(ctx, gtsFave); err != nil {

View file

@ -31,7 +31,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
var (
@ -53,7 +53,7 @@ func (p *processor) SendConfirmEmail(ctx context.Context, user *gtsmodel.User, u
// equivalent to the odds of creating a few tens of trillions of UUIDs in a
// year and having one duplicate.
confirmationToken := uuid.NewString()
confirmationLink := util.GenerateURIForEmailConfirm(confirmationToken)
confirmationLink := uris.GenerateURIForEmailConfirm(confirmationToken)
// pull our instance entry from the database so we can greet the user nicely in the email
instance := &gtsmodel.Instance{}