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
|
||||||
@ -124,10 +122,10 @@ func (suite *AccountCreateTestSuite) SetupSuite() {
|
|||||||
MaxImageSize: 2 << 20,
|
MaxImageSize: 2 << 20,
|
||||||
}
|
}
|
||||||
c.StorageConfig = &config.StorageConfig{
|
c.StorageConfig = &config.StorageConfig{
|
||||||
Backend: "local",
|
Backend: "local",
|
||||||
BasePath: "/tmp",
|
BasePath: "/tmp",
|
||||||
ServeProtocol: "http",
|
ServeProtocol: "http",
|
||||||
ServeHost: "localhost",
|
ServeHost: "localhost",
|
||||||
ServeBasePath: "/fileserver/media",
|
ServeBasePath: "/fileserver/media",
|
||||||
}
|
}
|
||||||
suite.config = c
|
suite.config = c
|
||||||
|
|||||||
@ -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,11 +137,10 @@ 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
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,
|
||||||
|
|||||||
@ -187,64 +187,64 @@ type KeyedFlags interface {
|
|||||||
// Flags is used for storing the names of the various flags used for
|
// Flags is used for storing the names of the various flags used for
|
||||||
// initializing and storing urfavecli flag variables.
|
// initializing and storing urfavecli flag variables.
|
||||||
type Flags struct {
|
type Flags struct {
|
||||||
LogLevel string
|
LogLevel string
|
||||||
ApplicationName string
|
ApplicationName string
|
||||||
ConfigPath string
|
ConfigPath string
|
||||||
Host string
|
Host string
|
||||||
Protocol string
|
Protocol string
|
||||||
|
|
||||||
DbType string
|
DbType string
|
||||||
DbAddress string
|
DbAddress string
|
||||||
DbPort string
|
DbPort string
|
||||||
DbUser string
|
DbUser string
|
||||||
DbPassword string
|
DbPassword string
|
||||||
DbDatabase string
|
DbDatabase string
|
||||||
|
|
||||||
TemplateBaseDir string
|
TemplateBaseDir string
|
||||||
|
|
||||||
AccountsOpenRegistration string
|
AccountsOpenRegistration string
|
||||||
AccountsRequireApproval string
|
AccountsRequireApproval string
|
||||||
|
|
||||||
MediaMaxImageSize string
|
MediaMaxImageSize string
|
||||||
MediaMaxVideoSize string
|
MediaMaxVideoSize string
|
||||||
|
|
||||||
StorageBackend string
|
StorageBackend string
|
||||||
StorageBasePath string
|
StorageBasePath string
|
||||||
StorageServeProtocol string
|
StorageServeProtocol string
|
||||||
StorageServeHost string
|
StorageServeHost string
|
||||||
StorageServeBasePath string
|
StorageServeBasePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFlagNames returns a struct containing the names of the various flags used for
|
// GetFlagNames returns a struct containing the names of the various flags used for
|
||||||
// initializing and storing urfavecli flag variables.
|
// initializing and storing urfavecli flag variables.
|
||||||
func GetFlagNames() Flags {
|
func GetFlagNames() Flags {
|
||||||
return Flags{
|
return Flags{
|
||||||
LogLevel: "log-level",
|
LogLevel: "log-level",
|
||||||
ApplicationName: "application-name",
|
ApplicationName: "application-name",
|
||||||
ConfigPath: "config-path",
|
ConfigPath: "config-path",
|
||||||
Host: "host",
|
Host: "host",
|
||||||
Protocol: "protocol",
|
Protocol: "protocol",
|
||||||
|
|
||||||
DbType: "db-type",
|
DbType: "db-type",
|
||||||
DbAddress: "db-address",
|
DbAddress: "db-address",
|
||||||
DbPort: "db-port",
|
DbPort: "db-port",
|
||||||
DbUser: "db-user",
|
DbUser: "db-user",
|
||||||
DbPassword: "db-password",
|
DbPassword: "db-password",
|
||||||
DbDatabase: "db-database",
|
DbDatabase: "db-database",
|
||||||
|
|
||||||
TemplateBaseDir: "template-basedir",
|
TemplateBaseDir: "template-basedir",
|
||||||
|
|
||||||
AccountsOpenRegistration: "accounts-open-registration",
|
AccountsOpenRegistration: "accounts-open-registration",
|
||||||
AccountsRequireApproval: "accounts-require-approval",
|
AccountsRequireApproval: "accounts-require-approval",
|
||||||
|
|
||||||
MediaMaxImageSize: "media-max-image-size",
|
MediaMaxImageSize: "media-max-image-size",
|
||||||
MediaMaxVideoSize: "media-max-video-size",
|
MediaMaxVideoSize: "media-max-video-size",
|
||||||
|
|
||||||
StorageBackend: "storage-backend",
|
StorageBackend: "storage-backend",
|
||||||
StorageBasePath: "storage-base-path",
|
StorageBasePath: "storage-base-path",
|
||||||
StorageServeProtocol: "storage-serve-protocol",
|
StorageServeProtocol: "storage-serve-protocol",
|
||||||
StorageServeHost: "storage-serve-host",
|
StorageServeHost: "storage-serve-host",
|
||||||
StorageServeBasePath: "storage-serve-base-path",
|
StorageServeBasePath: "storage-serve-base-path",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,31 +252,31 @@ func GetFlagNames() Flags {
|
|||||||
// initializing and storing urfavecli flag variables.
|
// initializing and storing urfavecli flag variables.
|
||||||
func GetEnvNames() Flags {
|
func GetEnvNames() Flags {
|
||||||
return Flags{
|
return Flags{
|
||||||
LogLevel: "GTS_LOG_LEVEL",
|
LogLevel: "GTS_LOG_LEVEL",
|
||||||
ApplicationName: "GTS_APPLICATION_NAME",
|
ApplicationName: "GTS_APPLICATION_NAME",
|
||||||
ConfigPath: "GTS_CONFIG_PATH",
|
ConfigPath: "GTS_CONFIG_PATH",
|
||||||
Host: "GTS_HOST",
|
Host: "GTS_HOST",
|
||||||
Protocol: "GTS_PROTOCOL",
|
Protocol: "GTS_PROTOCOL",
|
||||||
|
|
||||||
DbType: "GTS_DB_TYPE",
|
DbType: "GTS_DB_TYPE",
|
||||||
DbAddress: "GTS_DB_ADDRESS",
|
DbAddress: "GTS_DB_ADDRESS",
|
||||||
DbPort: "GTS_DB_PORT",
|
DbPort: "GTS_DB_PORT",
|
||||||
DbUser: "GTS_DB_USER",
|
DbUser: "GTS_DB_USER",
|
||||||
DbPassword: "GTS_DB_PASSWORD",
|
DbPassword: "GTS_DB_PASSWORD",
|
||||||
DbDatabase: "GTS_DB_DATABASE",
|
DbDatabase: "GTS_DB_DATABASE",
|
||||||
|
|
||||||
TemplateBaseDir: "GTS_TEMPLATE_BASEDIR",
|
TemplateBaseDir: "GTS_TEMPLATE_BASEDIR",
|
||||||
|
|
||||||
AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION",
|
AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION",
|
||||||
AccountsRequireApproval: "GTS_ACCOUNTS_REQUIRE_APPROVAL",
|
AccountsRequireApproval: "GTS_ACCOUNTS_REQUIRE_APPROVAL",
|
||||||
|
|
||||||
MediaMaxImageSize: "GTS_MEDIA_MAX_IMAGE_SIZE",
|
MediaMaxImageSize: "GTS_MEDIA_MAX_IMAGE_SIZE",
|
||||||
MediaMaxVideoSize: "GTS_MEDIA_MAX_VIDEO_SIZE",
|
MediaMaxVideoSize: "GTS_MEDIA_MAX_VIDEO_SIZE",
|
||||||
|
|
||||||
StorageBackend: "GTS_STORAGE_BACKEND",
|
StorageBackend: "GTS_STORAGE_BACKEND",
|
||||||
StorageBasePath: "GTS_STORAGE_BASE_PATH",
|
StorageBasePath: "GTS_STORAGE_BASE_PATH",
|
||||||
StorageServeProtocol: "GTS_STORAGE_SERVE_PROTOCOL",
|
StorageServeProtocol: "GTS_STORAGE_SERVE_PROTOCOL",
|
||||||
StorageServeHost: "GTS_STORAGE_SERVE_HOST",
|
StorageServeHost: "GTS_STORAGE_SERVE_HOST",
|
||||||
StorageServeBasePath: "GTS_STORAGE_SERVE_BASE_PATH",
|
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")
|
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)
|
||||||
|
|||||||
@ -70,10 +70,10 @@ func (suite *MediaTestSuite) SetupSuite() {
|
|||||||
MaxImageSize: 2 << 20,
|
MaxImageSize: 2 << 20,
|
||||||
}
|
}
|
||||||
c.StorageConfig = &config.StorageConfig{
|
c.StorageConfig = &config.StorageConfig{
|
||||||
Backend: "local",
|
Backend: "local",
|
||||||
BasePath: "/tmp",
|
BasePath: "/tmp",
|
||||||
ServeProtocol: "http",
|
ServeProtocol: "http",
|
||||||
ServeHost: "localhost",
|
ServeHost: "localhost",
|
||||||
ServeBasePath: "/fileserver/media",
|
ServeBasePath: "/fileserver/media",
|
||||||
}
|
}
|
||||||
suite.config = c
|
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.
|
// 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
|
||||||
|
|||||||
@ -249,6 +249,6 @@ func New(database db.DB, log *logrus.Logger) Server {
|
|||||||
srv.SetClientInfoHandler(server.ClientFormHandler)
|
srv.SetClientInfoHandler(server.ClientFormHandler)
|
||||||
return &s{
|
return &s{
|
||||||
server: srv,
|
server: srv,
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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