Market import: fill entries in from their websites
A list of just websites and relationships (url:, website:, or a bare address) can be imported with "Fill in the empty boxes from each website": each entry is filled in as on New entry, in the background a few at a time, and saved straight into the Market. Entries already there, by name or website, are skipped before their site is read; the plan's limit is kept. The import page shows the progress and each entry's result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -200,9 +200,19 @@ func (s *Server) inventoryDelete(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) inventoryImportPage(w http.ResponseWriter, r *http.Request) {
|
||||
s.render(w, r, "import", page{Title: "Import into the Market", Nav: "inventory", Data: map[string]any{
|
||||
s.render(w, r, "import", page{Title: "Import into the Market", Nav: "inventory", Data: s.importData(r, nil)})
|
||||
}
|
||||
|
||||
// importData is the import page's: the form, and the last list filled in
|
||||
// from the websites.
|
||||
func (s *Server) importData(r *http.Request, res *inventory.ImportResult) map[string]any {
|
||||
return map[string]any{
|
||||
"Relationships": inventory.Relationships,
|
||||
}})
|
||||
"Result": res,
|
||||
"YAML": r.FormValue("yaml"),
|
||||
"NoAI": !s.aiReady(),
|
||||
"Fill": s.marketFill(),
|
||||
}
|
||||
}
|
||||
|
||||
const maxImportBytes = 4 << 20
|
||||
@@ -216,11 +226,7 @@ func (s *Server) inventoryImport(w http.ResponseWriter, r *http.Request) {
|
||||
rel := r.FormValue("relationship")
|
||||
overwrite := r.FormValue("overwrite") == "on"
|
||||
show := func(errMsg string, res *inventory.ImportResult) {
|
||||
s.render(w, r, "import", page{Title: "Import into the Market", Nav: "inventory", Error: errMsg, Data: map[string]any{
|
||||
"Relationships": inventory.Relationships,
|
||||
"Result": res,
|
||||
"YAML": r.FormValue("yaml"),
|
||||
}})
|
||||
s.render(w, r, "import", page{Title: "Import into the Market", Nav: "inventory", Error: errMsg, Data: s.importData(r, res)})
|
||||
}
|
||||
|
||||
var data []byte
|
||||
@@ -252,6 +258,20 @@ func (s *Server) inventoryImport(w http.ResponseWriter, r *http.Request) {
|
||||
show(err.Error(), nil)
|
||||
return
|
||||
}
|
||||
if r.FormValue("fill") == "on" && r.FormValue("example") == "" {
|
||||
if err := s.startMarketFill(entries, overwrite); err != nil {
|
||||
show(err.Error(), nil)
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/market/import", "filling")
|
||||
return
|
||||
}
|
||||
for _, e := range entries {
|
||||
if strings.TrimSpace(e.Name) == "" && len(e.Websites) > 0 {
|
||||
show(`Some entries have only a website: tick "Fill in the empty boxes from each website" to have the AI fill them in.`, nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
res := inventory.Import(s.DB, entries, overwrite)
|
||||
show("", &res)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user