feat(delete): real deletes — adapters seeded once into adapter_dir (existing dir is authoritative), sources removed from config.yaml on delete; drop tombstone mechanism for both. Docs: multi-key architecture, gateway_keys as seed

This commit is contained in:
root
2026-08-10 11:52:51 +08:00
parent e2dd4d9727
commit f46b02089c
8 changed files with 184 additions and 67 deletions

View File

@ -239,13 +239,9 @@ func (c *Core) Config() *config.Config { return c.cfg }
// mergedSources = base YAML sources + runtime sources (runtime wins by name).
func (c *Core) mergedSources() []config.Source {
deleted := c.store.DeletedSources()
byName := map[string]config.Source{}
order := []string{}
for _, s := range c.cfg.Sources {
if deleted[s.Name] {
continue
}
byName[s.Name] = s
order = append(order, s.Name)
}
@ -313,15 +309,7 @@ func (c *Core) Reload() error {
// ---- adapter management (web UI) ----
func (c *Core) ListAdapters() []lua.APIAdapter {
deleted := c.store.DeletedAdapters()
list := c.vm.ListAdapters()
out := make([]lua.APIAdapter, 0, len(list))
for _, a := range list {
if !deleted[a.Name] {
out = append(out, a)
}
}
return out
return c.vm.ListAdapters()
}
// UploadAdapter saves a new Lua adapter script to the adapter dir and loads it.
@ -336,18 +324,17 @@ func (c *Core) UploadAdapter(name, code string) error {
if err := os.WriteFile(path, []byte(code), 0644); err != nil {
return err
}
if err := c.vm.LoadAdapter(path); err != nil {
return fmt.Errorf("load adapter: %w", err)
}
return c.store.RestoreAdapter(name)
return c.vm.LoadAdapter(path)
}
// RemoveAdapter deletes an adapter script and evicts it from the VM.
// RemoveAdapter deletes an adapter script and evicts it from the VM. The file
// is removed for real (adapter dir is authoritative after first run), so the
// adapter stays gone across restarts.
func (c *Core) RemoveAdapter(name string) error {
path := filepath.Join(c.cfg.AdapterDir, name+".lua")
_ = os.Remove(path)
c.vm.RemoveAdapter(name)
return c.store.DeleteAdapter(name)
return nil
}
// ---- source management (web UI) ----
@ -363,12 +350,31 @@ func (c *Core) AddSource(src config.Source) error {
}
func (c *Core) RemoveSource(name string) error {
for _, s := range c.cfg.Sources {
if s.Name == name {
if err := config.RemoveSourceFromYAML(c.cfg.Path, name); err != nil {
return err
}
c.cfg.Sources = c.removeCfgSource(name)
break
}
}
if _, err := c.store.Remove(name); err != nil {
return err
}
return c.rebuildRegistry()
}
func (c *Core) removeCfgSource(name string) []config.Source {
out := c.cfg.Sources[:0]
for _, s := range c.cfg.Sources {
if s.Name != name {
out = append(out, s)
}
}
return out
}
func (c *Core) Sources() []config.Source { return c.mergedSources() }
func normalizeSource(s *config.Source) error {