From ba899b5f5007883ce97819ac6f8e10a50d4918b4 Mon Sep 17 00:00:00 2001 From: Kyle Unverferth Date: Mon, 4 Sep 2023 11:05:48 -0600 Subject: [PATCH] Scripting and UI improvements --- app/lib/scripting/service.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/lib/scripting/service.go b/app/lib/scripting/service.go index 480e482..fc2abd7 100644 --- a/app/lib/scripting/service.go +++ b/app/lib/scripting/service.go @@ -2,12 +2,15 @@ package scripting import ( + "context" "path/filepath" "strings" "github.com/samber/lo" "github.com/kyleu/npn/app/lib/filesystem" + "github.com/kyleu/npn/app/lib/filter" + "github.com/kyleu/npn/app/lib/search/result" "github.com/kyleu/npn/app/util" ) @@ -67,3 +70,14 @@ func (s *Service) Size(scr string) int { } return int(st.Size) } + +func (s *Service) SearchScripts(ctx context.Context, ps filter.ParamSet, q string, logger util.Logger) (result.Results, error) { + return lo.FilterMap(s.ListScripts(logger), func(fn string, _ int) (*result.Result, bool) { + scr, _ := s.LoadScript(fn, logger) + res := result.NewResult("script", fn, "/admin/scripting/"+fn, fn, "file-code", scr, scr, q) + if len(res.Matches) > 0 { + return res, true + } + return nil, false + }), nil +}