Skip to content

Commit

Permalink
Eliminate model.ValidationNone
Browse files Browse the repository at this point in the history
  • Loading branch information
hhrutter committed Feb 28, 2024
1 parent d5fd063 commit b4af9ea
Show file tree
Hide file tree
Showing 30 changed files with 71 additions and 188 deletions.
36 changes: 12 additions & 24 deletions pkg/api/annotation.go
Expand Up @@ -92,10 +92,8 @@ func AddAnnotations(rs io.ReadSeeker, w io.Writer, selectedPages []string, ann m
log.Stats.Printf("XRefTable:\n%s\n", ctx)
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down Expand Up @@ -142,10 +140,8 @@ func AddAnnotationsAsIncrement(rws io.ReadWriteSeeker, selectedPages []string, a
log.Stats.Printf("XRefTable:\n%s\n", ctx)
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

if _, err = rws.Seek(0, io.SeekEnd); err != nil {
Expand Down Expand Up @@ -237,10 +233,8 @@ func AddAnnotationsMap(rs io.ReadSeeker, w io.Writer, m map[int][]model.Annotati
log.Stats.Printf("XRefTable:\n%s\n", ctx)
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down Expand Up @@ -282,10 +276,8 @@ func AddAnnotationsMapAsIncrement(rws io.ReadWriteSeeker, m map[int][]model.Anno
log.Stats.Printf("XRefTable:\n%s\n", ctx)
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

if _, err = rws.Seek(0, io.SeekEnd); err != nil {
Expand Down Expand Up @@ -384,10 +376,8 @@ func RemoveAnnotations(rs io.ReadSeeker, w io.Writer, selectedPages, idsAndTypes
log.Stats.Printf("XRefTable:\n%s\n", ctx)
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down Expand Up @@ -435,10 +425,8 @@ func RemoveAnnotationsAsIncrement(rws io.ReadWriteSeeker, selectedPages, idsAndT
log.Stats.Printf("XRefTable:\n%s\n", ctx)
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

if _, err = rws.Seek(0, io.SeekEnd); err != nil {
Expand Down
5 changes: 0 additions & 5 deletions pkg/api/api.go
Expand Up @@ -151,11 +151,6 @@ func readAndValidate(rs io.ReadSeeker, conf *model.Configuration, from1 time.Tim

dur1 = time.Since(from1).Seconds()

if conf.ValidationMode == model.ValidationNone {
// Bypass validation
return ctx, 0, 0, nil
}

from2 := time.Now()

if ctx.Version() == model.V20 {
Expand Down
6 changes: 2 additions & 4 deletions pkg/api/booklet.go
Expand Up @@ -102,10 +102,8 @@ func Booklet(rs io.ReadSeeker, w io.Writer, imgFiles, selectedPages []string, nu
}
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

if err = WriteContext(ctx, w); err != nil {
Expand Down
18 changes: 6 additions & 12 deletions pkg/api/box.go
Expand Up @@ -99,10 +99,8 @@ func AddBoxes(rs io.ReadSeeker, w io.Writer, selectedPages []string, pb *model.P
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down Expand Up @@ -182,10 +180,8 @@ func RemoveBoxes(rs io.ReadSeeker, w io.Writer, selectedPages []string, pb *mode
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down Expand Up @@ -266,10 +262,8 @@ func Crop(rs io.ReadSeeker, w io.Writer, selectedPages []string, b *model.Box, c
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down
6 changes: 2 additions & 4 deletions pkg/api/collect.go
Expand Up @@ -57,10 +57,8 @@ func Collect(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *model.
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctxDest); err != nil {
return err
}
if err = ValidateContext(ctxDest); err != nil {
return err
}

return WriteContext(ctxDest, w)
Expand Down
6 changes: 2 additions & 4 deletions pkg/api/create.go
Expand Up @@ -75,10 +75,8 @@ func Create(rs io.ReadSeeker, rd io.Reader, w io.Writer, conf *model.Configurati
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down
19 changes: 7 additions & 12 deletions pkg/api/cut.go
Expand Up @@ -99,11 +99,10 @@ func Poster(rs io.ReadSeeker, outDir, fileName string, selectedPages []string, c
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctxDest); err != nil {
return err
}
if err = ValidateContext(ctxDest); err != nil {
return err
}

}

return nil
Expand Down Expand Up @@ -166,10 +165,8 @@ func NDown(rs io.ReadSeeker, outDir, fileName string, selectedPages []string, n
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctxDest); err != nil {
return err
}
if err = ValidateContext(ctxDest); err != nil {
return err
}
}

Expand Down Expand Up @@ -269,10 +266,8 @@ func Cut(rs io.ReadSeeker, outDir, fileName string, selectedPages []string, cut
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctxDest); err != nil {
return err
}
if err = ValidateContext(ctxDest); err != nil {
return err
}
}

Expand Down
42 changes: 13 additions & 29 deletions pkg/api/form.go
Expand Up @@ -95,10 +95,8 @@ func RemoveFormFields(rs io.ReadSeeker, w io.Writer, fieldIDsOrNames []string, c
return ErrNoFormFieldsAffected
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down Expand Up @@ -172,10 +170,8 @@ func LockFormFields(rs io.ReadSeeker, w io.Writer, fieldIDsOrNames []string, con
return ErrNoFormFieldsAffected
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down Expand Up @@ -249,10 +245,8 @@ func UnlockFormFields(rs io.ReadSeeker, w io.Writer, fieldIDsOrNames []string, c
return ErrNoFormFieldsAffected
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down Expand Up @@ -326,10 +320,8 @@ func ResetFormFields(rs io.ReadSeeker, w io.Writer, fieldIDsOrNames []string, co
return ErrNoFormFieldsAffected
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

return WriteContext(ctx, w)
Expand Down Expand Up @@ -537,11 +529,7 @@ func fillPostProc(ctx *model.Context, pp []*model.Page, conf *model.Configuratio
return err
}

if conf.ValidationMode != model.ValidationNone {
return ValidateContext(ctx)
}

return nil
return ValidateContext(ctx)
}

// FillForm populates the form rs with data from rd and writes the result to w.
Expand Down Expand Up @@ -745,10 +733,8 @@ func multiFillFormJSON(inFilePDF string, rd io.Reader, outDir, fileName string,
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

outFile := filepath.Join(outDir, fmt.Sprintf("%s_%02d.pdf", fileName, i+1))
Expand Down Expand Up @@ -844,10 +830,8 @@ func multiFillFormCSV(inFilePDF string, rd io.Reader, outDir, fileName string, m
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

outFile := filepath.Join(outDir, fmt.Sprintf("%s_%02d.pdf", fileName, i+1))
Expand Down
6 changes: 2 additions & 4 deletions pkg/api/importImage.go
Expand Up @@ -88,10 +88,8 @@ func ImportImages(rs io.ReadSeeker, w io.Writer, imgs []io.Reader, imp *pdfcpu.I
ctx.PageCount++
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

if err = WriteContext(ctx, w); err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/api/info.go
Expand Up @@ -34,7 +34,6 @@ func PDFInfo(rs io.ReadSeeker, fileName string, selectedPages []string, conf *mo
if conf == nil {
conf = model.NewDefaultConfiguration()
} else {
// Validation loads infodict.
conf.ValidationMode = model.ValidationRelaxed
}
conf.Cmd = model.LISTINFO
Expand Down
3 changes: 0 additions & 3 deletions pkg/api/keyword.go
Expand Up @@ -35,7 +35,6 @@ func Keywords(rs io.ReadSeeker, conf *model.Configuration) ([]string, error) {
if conf == nil {
conf = model.NewDefaultConfiguration()
} else {
// Validation loads infodict.
conf.ValidationMode = model.ValidationRelaxed
}
conf.Cmd = model.LISTKEYWORDS
Expand All @@ -57,7 +56,6 @@ func AddKeywords(rs io.ReadSeeker, w io.Writer, files []string, conf *model.Conf
if conf == nil {
conf = model.NewDefaultConfiguration()
} else {
// Validation loads infodict.
conf.ValidationMode = model.ValidationRelaxed
}
conf.Cmd = model.ADDKEYWORDS
Expand Down Expand Up @@ -135,7 +133,6 @@ func RemoveKeywords(rs io.ReadSeeker, w io.Writer, keywords []string, conf *mode
if conf == nil {
conf = model.NewDefaultConfiguration()
} else {
// Validation loads infodict.
conf.ValidationMode = model.ValidationRelaxed
}
conf.Cmd = model.REMOVEKEYWORDS
Expand Down
6 changes: 2 additions & 4 deletions pkg/api/nup.go
Expand Up @@ -136,10 +136,8 @@ func NUp(rs io.ReadSeeker, w io.Writer, imgFiles, selectedPages []string, nup *m

}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

if err = WriteContext(ctx, w); err != nil {
Expand Down
12 changes: 4 additions & 8 deletions pkg/api/page.go
Expand Up @@ -66,10 +66,8 @@ func InsertPages(rs io.ReadSeeker, w io.Writer, selectedPages []string, before b
log.Stats.Printf("XRefTable:\n%s\n", ctx)
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctx); err != nil {
return err
}
if err = ValidateContext(ctx); err != nil {
return err
}

if err = WriteContext(ctx, w); err != nil {
Expand Down Expand Up @@ -170,10 +168,8 @@ func RemovePages(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *mo
return err
}

if conf.ValidationMode != model.ValidationNone {
if err = ValidateContext(ctxDest); err != nil {
return err
}
if err = ValidateContext(ctxDest); err != nil {
return err
}

return WriteContext(ctxDest, w)
Expand Down

0 comments on commit b4af9ea

Please sign in to comment.