Tidying and linting
This commit is contained in:
@ -57,8 +57,6 @@ type AccountCreateTestSuite struct {
|
|||||||
config *config.Config
|
config *config.Config
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
testAccountLocal *model.Account
|
testAccountLocal *model.Account
|
||||||
testAccountRemote *model.Account
|
|
||||||
testUser *model.User
|
|
||||||
testApplication *model.Application
|
testApplication *model.Application
|
||||||
testToken oauth2.TokenInfo
|
testToken oauth2.TokenInfo
|
||||||
mockOauthServer *oauth.MockServer
|
mockOauthServer *oauth.MockServer
|
||||||
|
|||||||
@ -33,19 +33,18 @@ import (
|
|||||||
func (m *accountModule) accountGETHandler(c *gin.Context) {
|
func (m *accountModule) accountGETHandler(c *gin.Context) {
|
||||||
targetAcctID := c.Param(idKey)
|
targetAcctID := c.Param(idKey)
|
||||||
if targetAcctID == "" {
|
if targetAcctID == "" {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error":"no account id specified"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "no account id specified"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
targetAccount := &model.Account{}
|
targetAccount := &model.Account{}
|
||||||
if err := m.db.GetByID(targetAcctID, targetAccount); err != nil {
|
if err := m.db.GetByID(targetAcctID, targetAccount); err != nil {
|
||||||
if _, ok := err.(db.ErrNoEntries); ok {
|
if _, ok := err.(db.ErrNoEntries); ok {
|
||||||
c.JSON(http.StatusNotFound, gin.H{"error":"Record not found"})
|
c.JSON(http.StatusNotFound, gin.H{"error": "Record not found"})
|
||||||
return
|
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
acctInfo, err := m.db.AccountToMastoPublic(targetAccount)
|
acctInfo, err := m.db.AccountToMastoPublic(targetAccount)
|
||||||
|
|||||||
@ -137,13 +137,12 @@ func (m *accountModule) accountUpdateCredentialsPATCHHandler(c *gin.Context) {
|
|||||||
if err := util.ValidateLanguage(*form.Source.Language); err != nil {
|
if err := util.ValidateLanguage(*form.Source.Language); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
if err := m.db.UpdateOneByID(authed.Account.ID, "language", *form.Source.Language, &model.Account{}); err != nil {
|
if err := m.db.UpdateOneByID(authed.Account.ID, "language", *form.Source.Language, &model.Account{}); err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if form.Source.Sensitive != nil {
|
if form.Source.Sensitive != nil {
|
||||||
if err := m.db.UpdateOneByID(authed.Account.ID, "locked", *form.Locked, &model.Account{}); err != nil {
|
if err := m.db.UpdateOneByID(authed.Account.ID, "locked", *form.Locked, &model.Account{}); err != nil {
|
||||||
@ -156,18 +155,17 @@ func (m *accountModule) accountUpdateCredentialsPATCHHandler(c *gin.Context) {
|
|||||||
if err := util.ValidatePrivacy(*form.Source.Privacy); err != nil {
|
if err := util.ValidatePrivacy(*form.Source.Privacy); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
if err := m.db.UpdateOneByID(authed.Account.ID, "privacy", *form.Source.Privacy, &model.Account{}); err != nil {
|
if err := m.db.UpdateOneByID(authed.Account.ID, "privacy", *form.Source.Privacy, &model.Account{}); err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if form.FieldsAttributes != nil {
|
// if form.FieldsAttributes != nil {
|
||||||
// TODO: parse fields attributes nicely and update
|
// // TODO: parse fields attributes nicely and update
|
||||||
}
|
// }
|
||||||
|
|
||||||
// fetch the account with all updated values set
|
// fetch the account with all updated values set
|
||||||
updatedAccount := &model.Account{}
|
updatedAccount := &model.Account{}
|
||||||
|
|||||||
@ -53,8 +53,6 @@ type AccountUpdateTestSuite struct {
|
|||||||
config *config.Config
|
config *config.Config
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
testAccountLocal *model.Account
|
testAccountLocal *model.Account
|
||||||
testAccountRemote *model.Account
|
|
||||||
testUser *model.User
|
|
||||||
testApplication *model.Application
|
testApplication *model.Application
|
||||||
testToken oauth2.TokenInfo
|
testToken oauth2.TokenInfo
|
||||||
mockOauthServer *oauth.MockServer
|
mockOauthServer *oauth.MockServer
|
||||||
|
|||||||
@ -25,7 +25,7 @@ type fileServer struct {
|
|||||||
// New returns a new fileServer module
|
// New returns a new fileServer module
|
||||||
func New(config *config.Config, db db.DB, storage storage.Storage, log *logrus.Logger) apimodule.ClientAPIModule {
|
func New(config *config.Config, db db.DB, storage storage.Storage, log *logrus.Logger) apimodule.ClientAPIModule {
|
||||||
|
|
||||||
storageBase := fmt.Sprintf("%s", config.StorageConfig.BasePath) // TODO: do this properly
|
storageBase := config.StorageConfig.BasePath // TODO: do this properly
|
||||||
|
|
||||||
return &fileServer{
|
return &fileServer{
|
||||||
config: config,
|
config: config,
|
||||||
|
|||||||
@ -120,7 +120,7 @@ func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string
|
|||||||
return nil, errors.New("header or avatar not selected")
|
return nil, errors.New("header or avatar not selected")
|
||||||
}
|
}
|
||||||
|
|
||||||
clean := []byte{}
|
var clean []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch contentType {
|
switch contentType {
|
||||||
@ -152,7 +152,7 @@ func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string
|
|||||||
extension := strings.Split(contentType, "/")[1]
|
extension := strings.Split(contentType, "/")[1]
|
||||||
newMediaID := uuid.NewString()
|
newMediaID := uuid.NewString()
|
||||||
|
|
||||||
base := fmt.Sprintf("%s://%s%s", mh.config.StorageConfig.ServeProtocol, mh.config.StorageConfig.ServeHost, mh.config.StorageConfig.ServeBasePath, )
|
base := fmt.Sprintf("%s://%s%s", mh.config.StorageConfig.ServeProtocol, mh.config.StorageConfig.ServeHost, mh.config.StorageConfig.ServeBasePath)
|
||||||
|
|
||||||
// we store the original...
|
// we store the original...
|
||||||
originalPath := fmt.Sprintf("%s/%s/%s/original/%s.%s", base, accountID, headerOrAvi, newMediaID, extension)
|
originalPath := fmt.Sprintf("%s/%s/%s/original/%s.%s", base, accountID, headerOrAvi, newMediaID, extension)
|
||||||
|
|||||||
@ -73,7 +73,7 @@ func supportedImageType(mimeType string) bool {
|
|||||||
// purgeExif is a little wrapper for the action of removing exif data from an image.
|
// purgeExif is a little wrapper for the action of removing exif data from an image.
|
||||||
// Only pass pngs or jpegs to this function.
|
// Only pass pngs or jpegs to this function.
|
||||||
func purgeExif(b []byte) ([]byte, error) {
|
func purgeExif(b []byte) ([]byte, error) {
|
||||||
if b == nil || len(b) == 0 {
|
if len(b) == 0 {
|
||||||
return nil, errors.New("passed image was not valid")
|
return nil, errors.New("passed image was not valid")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ func purgeExif(b []byte) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not purge exif from image: %s", err)
|
return nil, fmt.Errorf("could not purge exif from image: %s", err)
|
||||||
}
|
}
|
||||||
if clean == nil || len(clean) == 0 {
|
if len(clean) == 0 {
|
||||||
return nil, errors.New("purged image was not valid")
|
return nil, errors.New("purged image was not valid")
|
||||||
}
|
}
|
||||||
return clean, nil
|
return clean, nil
|
||||||
|
|||||||
@ -90,7 +90,7 @@ func (suite *ValidationTestSuite) TestValidateUsername() {
|
|||||||
weirdChars := "thisusername&&&&&&&istooweird!!"
|
weirdChars := "thisusername&&&&&&&istooweird!!"
|
||||||
leadingSpace := " see_that_leading_space"
|
leadingSpace := " see_that_leading_space"
|
||||||
trailingSpace := "thisusername_ends_with_a_space "
|
trailingSpace := "thisusername_ends_with_a_space "
|
||||||
newlines := fmt.Sprintf("this_is\n_almost_ok")
|
newlines := "this_is\n_almost_ok"
|
||||||
goodUsername := "this_is_a_good_username"
|
goodUsername := "this_is_a_good_username"
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user