diff --git a/internal/git/output_parser.go b/internal/git/output_parser.go index 8e95779..c7d02a6 100644 --- a/internal/git/output_parser.go +++ b/internal/git/output_parser.go @@ -8,9 +8,9 @@ import ( ) type File struct { - Filename string `validate:"excludes=\x2f,excludes=\x5c,max=50"` - OldFilename string `validate:"excludes=\x2f,excludes=\x5c,max=50"` - Content string `validate:"required"` + Filename string + OldFilename string + Content string Truncated bool IsCreated bool IsDeleted bool diff --git a/internal/models/gist.go b/internal/models/gist.go index 6f54eb0..421eaf1 100644 --- a/internal/models/gist.go +++ b/internal/models/gist.go @@ -226,7 +226,7 @@ func (gist *Gist) NbCommits() (string, error) { return git.GetNumberOfCommitsOfRepository(gist.User.Username, gist.Uuid) } -func (gist *Gist) AddAndCommitFiles(files *[]git.File) error { +func (gist *Gist) AddAndCommitFiles(files *[]FileDTO) error { if err := git.CloneTmp(gist.User.Username, gist.Uuid, gist.Uuid); err != nil { return err } @@ -263,10 +263,15 @@ func (gist *Gist) RPC(service string) ([]byte, error) { // -- DTO -- // type GistDTO struct { - Title string `validate:"max=50" form:"title"` - Description string `validate:"max=150" form:"description"` - Private bool `form:"private"` - Files []git.File `validate:"min=1,dive"` + Title string `validate:"max=50" form:"title"` + Description string `validate:"max=150" form:"description"` + Private bool `form:"private"` + Files []FileDTO `validate:"min=1,dive"` +} + +type FileDTO struct { + Filename string `validate:"excludes=\x2f,excludes=\x5c,max=50"` + Content string `validate:"required"` } func (dto *GistDTO) ToGist() *Gist { diff --git a/internal/web/gist.go b/internal/web/gist.go index e2e33e0..de0705e 100644 --- a/internal/web/gist.go +++ b/internal/web/gist.go @@ -10,7 +10,6 @@ import ( "html/template" "net/url" "opengist/internal/config" - "opengist/internal/git" "opengist/internal/models" "strconv" "strings" @@ -208,7 +207,7 @@ func processCreate(ctx echo.Context) error { return errorRes(400, "Cannot bind data", err) } - dto.Files = make([]git.File, 0) + dto.Files = make([]models.FileDTO, 0) for i := 0; i < len(ctx.Request().PostForm["content"]); i++ { name := ctx.Request().PostForm["name"][i] content := ctx.Request().PostForm["content"][i] @@ -222,7 +221,7 @@ func processCreate(ctx echo.Context) error { return errorRes(400, "Invalid character unescaped", err) } - dto.Files = append(dto.Files, git.File{ + dto.Files = append(dto.Files, models.FileDTO{ Filename: name, Content: escapedValue, })