feat: added working rendering with plugins
This commit is contained in:
parent
fbdaf218eb
commit
1ebea8cb73
7 changed files with 139 additions and 81 deletions
|
|
@ -20,8 +20,8 @@ func (s *Service) Download() http.HandlerFunc {
|
|||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
path = s.PathForData() + strings.TrimPrefix(r.URL.Path, "/download")
|
||||
pluginNames = r.URL.Query()["plugins"]
|
||||
profileIDs = r.URL.Query()["profiles"]
|
||||
pluginNames = strings.Split(r.URL.Query().Get("plugins"), ",")
|
||||
profileIDs = strings.Split(r.URL.Query().Get("profiles"), ",")
|
||||
|
||||
fileInfo os.FileInfo
|
||||
out *os.File
|
||||
|
|
@ -126,38 +126,42 @@ func (s *Service) Download() http.HandlerFunc {
|
|||
log.Error().Errs("errs", errs).Msg("errors occurred loading plugins")
|
||||
errs = []error{}
|
||||
}
|
||||
if len(hooks) > 0 {
|
||||
|
||||
// run pre-hooks to modify the contents of the file before archiving
|
||||
log.Debug().Int("hook_count", len(hooks)).Msg("running hooks")
|
||||
for _, hook := range hooks {
|
||||
log.Debug().Any("hook", map[string]any{
|
||||
"data": hook.Data,
|
||||
"args": hook.Args,
|
||||
"plugin": map[string]string{
|
||||
"name": hook.Plugin.Name(),
|
||||
"description": hook.Plugin.Description(),
|
||||
"version": hook.Plugin.Version(),
|
||||
},
|
||||
}).Send()
|
||||
err = hook.Run()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("plugin", hook.Plugin.Name()).Msg("failed to run plugin")
|
||||
continue
|
||||
// run pre-hooks to modify the contents of the file before archiving
|
||||
log.Debug().Int("hook_count", len(hooks)).Msg("running hooks")
|
||||
for _, hook := range hooks {
|
||||
log.Debug().Any("hook", map[string]any{
|
||||
"store": hook.Data,
|
||||
"args": hook.Args,
|
||||
"plugin": map[string]string{
|
||||
"name": hook.Plugin.Name(),
|
||||
"description": hook.Plugin.Description(),
|
||||
"version": hook.Plugin.Version(),
|
||||
},
|
||||
}).Send()
|
||||
err = hook.Run()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("plugin", hook.Plugin.Name()).Msg("failed to run plugin")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// take the contents from the last hook and update files
|
||||
var (
|
||||
hook = hooks[len(hooks)-1]
|
||||
data any
|
||||
)
|
||||
data, err = hook.Data.Get("out")
|
||||
if err != nil {
|
||||
s.writeErrorResponse(w, fmt.Sprintf("failed to get data from hook: %v", err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write([]byte(data.(string)))
|
||||
} else {
|
||||
w.Write(contents)
|
||||
}
|
||||
|
||||
// take the contents from the last hook and update files
|
||||
var (
|
||||
hook = hooks[len(hooks)-1]
|
||||
data any
|
||||
)
|
||||
data, err = hook.Data.Get("out")
|
||||
if err != nil {
|
||||
s.writeErrorResponse(w, fmt.Sprintf("failed to get data from hook: %v", err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(data.(string)))
|
||||
}
|
||||
} else {
|
||||
s.writeErrorResponse(w, err.Error(), http.StatusBadRequest)
|
||||
|
|
@ -228,6 +232,7 @@ func (s *Service) GetStatus(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func (s *Service) loadProfiles(profileIDs []string, store storage.KVStore, errs []error) []error {
|
||||
// load data from profiles into the data store
|
||||
var profiles = make(makeshift.ProfileMap, len(profileIDs))
|
||||
for i, profileID := range profileIDs {
|
||||
var (
|
||||
profilePath = s.PathForProfileWithID(profileID)
|
||||
|
|
@ -251,8 +256,9 @@ func (s *Service) loadProfiles(profileIDs []string, store storage.KVStore, errs
|
|||
errs = append(errs, err)
|
||||
continue
|
||||
}
|
||||
store.Set(profileID, profile)
|
||||
profiles[profileID] = profile
|
||||
}
|
||||
store.Set("profiles", profiles)
|
||||
|
||||
return errs
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue