diff --git a/plugin/impl.go b/plugin/impl.go index 8f38166..34e1dc6 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -10,6 +10,7 @@ import ( "strings" "code.gitea.io/sdk/gitea" + "github.com/thegeeklab/wp-plugin-go/file" ) var ( @@ -53,13 +54,13 @@ func (p *Plugin) Validate() error { } if p.Settings.Note != "" { - if p.Settings.Note, _, err = readStringOrFile(p.Settings.Note); err != nil { + if p.Settings.Note, _, err = file.ReadStringOrFile(p.Settings.Note); err != nil { return fmt.Errorf("error while reading %s: %w", p.Settings.Note, err) } } if p.Settings.Title != "" { - if p.Settings.Title, _, err = readStringOrFile(p.Settings.Title); err != nil { + if p.Settings.Title, _, err = file.ReadStringOrFile(p.Settings.Title); err != nil { return fmt.Errorf("error while reading %s: %w", p.Settings.Title, err) } } diff --git a/plugin/utils.go b/plugin/utils.go index 6dd1793..ff58cb1 100644 --- a/plugin/utils.go +++ b/plugin/utils.go @@ -19,29 +19,6 @@ import ( var ErrHashMethodNotSupported = errors.New("hash method not supported") -//nolint:unparam -func readStringOrFile(input string) (string, bool, error) { - //nolint:gomnd - if len(input) > 255 { - return input, false, nil - } - - // Check if input is a file path - if _, err := os.Stat(input); err != nil && os.IsNotExist(err) { - // No file found => use input as result - return input, false, nil - } else if err != nil { - return "", false, err - } - - result, err := os.ReadFile(input) - if err != nil { - return "", true, err - } - - return string(result), true, nil -} - func checksum(r io.Reader, method string) (string, error) { b, err := io.ReadAll(r) if err != nil {