Tidying and linting

This commit is contained in:
tsmethurst
2021-04-01 20:44:54 +02:00
parent e497794059
commit 1d017d0563
11 changed files with 85 additions and 92 deletions

View File

@ -57,8 +57,6 @@ type AccountCreateTestSuite struct {
config *config.Config
log *logrus.Logger
testAccountLocal *model.Account
testAccountRemote *model.Account
testUser *model.User
testApplication *model.Application
testToken oauth2.TokenInfo
mockOauthServer *oauth.MockServer
@ -124,10 +122,10 @@ func (suite *AccountCreateTestSuite) SetupSuite() {
MaxImageSize: 2 << 20,
}
c.StorageConfig = &config.StorageConfig{
Backend: "local",
BasePath: "/tmp",
Backend: "local",
BasePath: "/tmp",
ServeProtocol: "http",
ServeHost: "localhost",
ServeHost: "localhost",
ServeBasePath: "/fileserver/media",
}
suite.config = c

View File

@ -33,19 +33,18 @@ import (
func (m *accountModule) accountGETHandler(c *gin.Context) {
targetAcctID := c.Param(idKey)
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
}
targetAccount := &model.Account{}
if err := m.db.GetByID(targetAcctID, targetAccount); err != nil {
if _, ok := err.(db.ErrNoEntries); ok {
c.JSON(http.StatusNotFound, gin.H{"error":"Record not found"})
return
} else {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
c.JSON(http.StatusNotFound, gin.H{"error": "Record not found"})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
acctInfo, err := m.db.AccountToMastoPublic(targetAccount)

View File

@ -137,11 +137,10 @@ func (m *accountModule) accountUpdateCredentialsPATCHHandler(c *gin.Context) {
if err := util.ValidateLanguage(*form.Source.Language); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
} else {
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()})
return
}
}
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()})
return
}
}
@ -156,18 +155,17 @@ func (m *accountModule) accountUpdateCredentialsPATCHHandler(c *gin.Context) {
if err := util.ValidatePrivacy(*form.Source.Privacy); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
} else {
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()})
return
}
}
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()})
return
}
}
}
if form.FieldsAttributes != nil {
// TODO: parse fields attributes nicely and update
}
// if form.FieldsAttributes != nil {
// // TODO: parse fields attributes nicely and update
// }
// fetch the account with all updated values set
updatedAccount := &model.Account{}

View File

@ -53,8 +53,6 @@ type AccountUpdateTestSuite struct {
config *config.Config
log *logrus.Logger
testAccountLocal *model.Account
testAccountRemote *model.Account
testUser *model.User
testApplication *model.Application
testToken oauth2.TokenInfo
mockOauthServer *oauth.MockServer

View File

@ -25,7 +25,7 @@ type fileServer struct {
// New returns a new fileServer module
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{
config: config,