Add convert mode batch workflow with full progress
This commit is contained in:
@@ -32,17 +32,26 @@ type Server struct {
|
||||
result *models.AnalysisResult
|
||||
detectedVendor string
|
||||
rawExport *RawExportPackage
|
||||
convertJobs map[string]struct{}
|
||||
convertOutput map[string]ConvertArtifact
|
||||
|
||||
jobManager *JobManager
|
||||
collectors *collector.Registry
|
||||
}
|
||||
|
||||
type ConvertArtifact struct {
|
||||
Path string
|
||||
Summary string
|
||||
}
|
||||
|
||||
func New(cfg Config) *Server {
|
||||
s := &Server{
|
||||
config: cfg,
|
||||
mux: http.NewServeMux(),
|
||||
jobManager: NewJobManager(),
|
||||
collectors: collector.NewDefaultRegistry(),
|
||||
config: cfg,
|
||||
mux: http.NewServeMux(),
|
||||
jobManager: NewJobManager(),
|
||||
collectors: collector.NewDefaultRegistry(),
|
||||
convertJobs: make(map[string]struct{}),
|
||||
convertOutput: make(map[string]ConvertArtifact),
|
||||
}
|
||||
s.setupRoutes()
|
||||
return s
|
||||
@@ -72,6 +81,9 @@ func (s *Server) setupRoutes() {
|
||||
s.mux.HandleFunc("GET /api/export/csv", s.handleExportCSV)
|
||||
s.mux.HandleFunc("GET /api/export/json", s.handleExportJSON)
|
||||
s.mux.HandleFunc("GET /api/export/reanimator", s.handleExportReanimator)
|
||||
s.mux.HandleFunc("POST /api/convert", s.handleConvertReanimatorBatch)
|
||||
s.mux.HandleFunc("GET /api/convert/{id}", s.handleConvertStatus)
|
||||
s.mux.HandleFunc("GET /api/convert/{id}/download", s.handleConvertDownload)
|
||||
s.mux.HandleFunc("DELETE /api/clear", s.handleClear)
|
||||
s.mux.HandleFunc("POST /api/shutdown", s.handleShutdown)
|
||||
s.mux.HandleFunc("POST /api/collect", s.handleCollectStart)
|
||||
@@ -154,3 +166,47 @@ func (s *Server) GetDetectedVendor() string {
|
||||
defer s.mu.RUnlock()
|
||||
return s.detectedVendor
|
||||
}
|
||||
|
||||
func (s *Server) markConvertJob(id string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.convertJobs[id] = struct{}{}
|
||||
}
|
||||
|
||||
func (s *Server) isConvertJob(id string) bool {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
_, ok := s.convertJobs[id]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (s *Server) setConvertArtifact(id string, artifact ConvertArtifact) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.convertOutput[id] = artifact
|
||||
}
|
||||
|
||||
func (s *Server) getConvertArtifact(id string) (ConvertArtifact, bool) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
artifact, ok := s.convertOutput[id]
|
||||
return artifact, ok
|
||||
}
|
||||
|
||||
func (s *Server) clearConvertArtifact(id string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
delete(s.convertOutput, id)
|
||||
}
|
||||
|
||||
func (s *Server) clearAllConvertArtifacts() []ConvertArtifact {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
out := make([]ConvertArtifact, 0, len(s.convertOutput))
|
||||
for _, artifact := range s.convertOutput {
|
||||
out = append(out, artifact)
|
||||
}
|
||||
s.convertOutput = make(map[string]ConvertArtifact)
|
||||
s.convertJobs = make(map[string]struct{})
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user