Tidying and linting
This commit is contained in:
parent
e497794059
commit
1d017d0563
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -187,64 +187,64 @@ type KeyedFlags interface {
|
|||
// Flags is used for storing the names of the various flags used for
|
||||
// initializing and storing urfavecli flag variables.
|
||||
type Flags struct {
|
||||
LogLevel string
|
||||
ApplicationName string
|
||||
ConfigPath string
|
||||
Host string
|
||||
Protocol string
|
||||
LogLevel string
|
||||
ApplicationName string
|
||||
ConfigPath string
|
||||
Host string
|
||||
Protocol string
|
||||
|
||||
DbType string
|
||||
DbAddress string
|
||||
DbPort string
|
||||
DbUser string
|
||||
DbPassword string
|
||||
DbDatabase string
|
||||
DbType string
|
||||
DbAddress string
|
||||
DbPort string
|
||||
DbUser string
|
||||
DbPassword string
|
||||
DbDatabase string
|
||||
|
||||
TemplateBaseDir string
|
||||
TemplateBaseDir string
|
||||
|
||||
AccountsOpenRegistration string
|
||||
AccountsRequireApproval string
|
||||
|
||||
MediaMaxImageSize string
|
||||
MediaMaxVideoSize string
|
||||
MediaMaxImageSize string
|
||||
MediaMaxVideoSize string
|
||||
|
||||
StorageBackend string
|
||||
StorageBasePath string
|
||||
StorageServeProtocol string
|
||||
StorageServeHost string
|
||||
StorageServeBasePath string
|
||||
StorageBackend string
|
||||
StorageBasePath string
|
||||
StorageServeProtocol string
|
||||
StorageServeHost string
|
||||
StorageServeBasePath string
|
||||
}
|
||||
|
||||
// GetFlagNames returns a struct containing the names of the various flags used for
|
||||
// initializing and storing urfavecli flag variables.
|
||||
func GetFlagNames() Flags {
|
||||
return Flags{
|
||||
LogLevel: "log-level",
|
||||
ApplicationName: "application-name",
|
||||
ConfigPath: "config-path",
|
||||
Host: "host",
|
||||
Protocol: "protocol",
|
||||
LogLevel: "log-level",
|
||||
ApplicationName: "application-name",
|
||||
ConfigPath: "config-path",
|
||||
Host: "host",
|
||||
Protocol: "protocol",
|
||||
|
||||
DbType: "db-type",
|
||||
DbAddress: "db-address",
|
||||
DbPort: "db-port",
|
||||
DbUser: "db-user",
|
||||
DbPassword: "db-password",
|
||||
DbDatabase: "db-database",
|
||||
DbType: "db-type",
|
||||
DbAddress: "db-address",
|
||||
DbPort: "db-port",
|
||||
DbUser: "db-user",
|
||||
DbPassword: "db-password",
|
||||
DbDatabase: "db-database",
|
||||
|
||||
TemplateBaseDir: "template-basedir",
|
||||
TemplateBaseDir: "template-basedir",
|
||||
|
||||
AccountsOpenRegistration: "accounts-open-registration",
|
||||
AccountsRequireApproval: "accounts-require-approval",
|
||||
|
||||
MediaMaxImageSize: "media-max-image-size",
|
||||
MediaMaxVideoSize: "media-max-video-size",
|
||||
MediaMaxImageSize: "media-max-image-size",
|
||||
MediaMaxVideoSize: "media-max-video-size",
|
||||
|
||||
StorageBackend: "storage-backend",
|
||||
StorageBasePath: "storage-base-path",
|
||||
StorageServeProtocol: "storage-serve-protocol",
|
||||
StorageServeHost: "storage-serve-host",
|
||||
StorageServeBasePath: "storage-serve-base-path",
|
||||
StorageBackend: "storage-backend",
|
||||
StorageBasePath: "storage-base-path",
|
||||
StorageServeProtocol: "storage-serve-protocol",
|
||||
StorageServeHost: "storage-serve-host",
|
||||
StorageServeBasePath: "storage-serve-base-path",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,31 +252,31 @@ func GetFlagNames() Flags {
|
|||
// initializing and storing urfavecli flag variables.
|
||||
func GetEnvNames() Flags {
|
||||
return Flags{
|
||||
LogLevel: "GTS_LOG_LEVEL",
|
||||
ApplicationName: "GTS_APPLICATION_NAME",
|
||||
ConfigPath: "GTS_CONFIG_PATH",
|
||||
Host: "GTS_HOST",
|
||||
Protocol: "GTS_PROTOCOL",
|
||||
LogLevel: "GTS_LOG_LEVEL",
|
||||
ApplicationName: "GTS_APPLICATION_NAME",
|
||||
ConfigPath: "GTS_CONFIG_PATH",
|
||||
Host: "GTS_HOST",
|
||||
Protocol: "GTS_PROTOCOL",
|
||||
|
||||
DbType: "GTS_DB_TYPE",
|
||||
DbAddress: "GTS_DB_ADDRESS",
|
||||
DbPort: "GTS_DB_PORT",
|
||||
DbUser: "GTS_DB_USER",
|
||||
DbPassword: "GTS_DB_PASSWORD",
|
||||
DbDatabase: "GTS_DB_DATABASE",
|
||||
DbType: "GTS_DB_TYPE",
|
||||
DbAddress: "GTS_DB_ADDRESS",
|
||||
DbPort: "GTS_DB_PORT",
|
||||
DbUser: "GTS_DB_USER",
|
||||
DbPassword: "GTS_DB_PASSWORD",
|
||||
DbDatabase: "GTS_DB_DATABASE",
|
||||
|
||||
TemplateBaseDir: "GTS_TEMPLATE_BASEDIR",
|
||||
TemplateBaseDir: "GTS_TEMPLATE_BASEDIR",
|
||||
|
||||
AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION",
|
||||
AccountsRequireApproval: "GTS_ACCOUNTS_REQUIRE_APPROVAL",
|
||||
|
||||
MediaMaxImageSize: "GTS_MEDIA_MAX_IMAGE_SIZE",
|
||||
MediaMaxVideoSize: "GTS_MEDIA_MAX_VIDEO_SIZE",
|
||||
MediaMaxImageSize: "GTS_MEDIA_MAX_IMAGE_SIZE",
|
||||
MediaMaxVideoSize: "GTS_MEDIA_MAX_VIDEO_SIZE",
|
||||
|
||||
StorageBackend: "GTS_STORAGE_BACKEND",
|
||||
StorageBasePath: "GTS_STORAGE_BASE_PATH",
|
||||
StorageServeProtocol: "GTS_STORAGE_SERVE_PROTOCOL",
|
||||
StorageServeHost: "GTS_STORAGE_SERVE_HOST",
|
||||
StorageServeBasePath: "GTS_STORAGE_SERVE_BASE_PATH",
|
||||
StorageBackend: "GTS_STORAGE_BACKEND",
|
||||
StorageBasePath: "GTS_STORAGE_BASE_PATH",
|
||||
StorageServeProtocol: "GTS_STORAGE_SERVE_PROTOCOL",
|
||||
StorageServeHost: "GTS_STORAGE_SERVE_HOST",
|
||||
StorageServeBasePath: "GTS_STORAGE_SERVE_BASE_PATH",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string
|
|||
return nil, errors.New("header or avatar not selected")
|
||||
}
|
||||
|
||||
clean := []byte{}
|
||||
var clean []byte
|
||||
var err error
|
||||
|
||||
switch contentType {
|
||||
|
@ -152,7 +152,7 @@ func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string
|
|||
extension := strings.Split(contentType, "/")[1]
|
||||
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...
|
||||
originalPath := fmt.Sprintf("%s/%s/%s/original/%s.%s", base, accountID, headerOrAvi, newMediaID, extension)
|
||||
|
|
|
@ -70,10 +70,10 @@ func (suite *MediaTestSuite) 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
|
||||
|
|
|
@ -73,7 +73,7 @@ func supportedImageType(mimeType string) bool {
|
|||
// purgeExif is a little wrapper for the action of removing exif data from an image.
|
||||
// Only pass pngs or jpegs to this function.
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ func purgeExif(b []byte) ([]byte, error) {
|
|||
if err != nil {
|
||||
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 clean, nil
|
||||
|
|
|
@ -249,6 +249,6 @@ func New(database db.DB, log *logrus.Logger) Server {
|
|||
srv.SetClientInfoHandler(server.ClientFormHandler)
|
||||
return &s{
|
||||
server: srv,
|
||||
log: log,
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ func (suite *ValidationTestSuite) TestValidateUsername() {
|
|||
weirdChars := "thisusername&&&&&&&istooweird!!"
|
||||
leadingSpace := " see_that_leading_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"
|
||||
var err error
|
||||
|
||||
|
|
Loading…
Reference in New Issue