diff --git a/local-tool/server/internal/flash/service.go b/local-tool/server/internal/flash/service.go index 80fa41b..676cce2 100644 --- a/local-tool/server/internal/flash/service.go +++ b/local-tool/server/internal/flash/service.go @@ -66,13 +66,15 @@ func resolveModelPath(filePath string, deviceType string) string { type Service struct { deviceMgr *device.Manager modelRepo *model.Repository + dataDir string tracker *ProgressTracker } -func NewService(deviceMgr *device.Manager, modelRepo *model.Repository) *Service { +func NewService(deviceMgr *device.Manager, modelRepo *model.Repository, dataDir string) *Service { return &Service{ deviceMgr: deviceMgr, modelRepo: modelRepo, + dataDir: dataDir, tracker: NewProgressTracker(), } } @@ -106,6 +108,18 @@ func (s *Service) StartFlash(deviceID, modelID string) (string, <-chan driver.Fl return "", nil, fmt.Errorf("model %s has no .nef file path", modelID) } + // models.json 的 filePath 是相對路徑(例如 "data/nef/kl520/xxx.nef")。 + // 如果不是絕對路徑,用 dataDir 解析: + // "data/nef/..." → 去掉 "data/" 前綴 → dataDir + "/nef/..." + // 其他相對路徑 → dataDir + "/" + filePath + if !filepath.IsAbs(modelPath) { + if strings.HasPrefix(modelPath, "data/") || strings.HasPrefix(modelPath, "data\\") { + modelPath = filepath.Join(s.dataDir, modelPath[len("data/"):]) + } else { + modelPath = filepath.Join(s.dataDir, modelPath) + } + } + modelPath = resolveModelPath(modelPath, deviceInfo.Type) taskID := fmt.Sprintf("flash-%s-%s", deviceID, modelID) diff --git a/local-tool/server/main.go b/local-tool/server/main.go index 87fd4c9..3c77b2c 100644 --- a/local-tool/server/main.go +++ b/local-tool/server/main.go @@ -139,7 +139,7 @@ func main() { cameraMgr := camera.NewManager(cfg.MockCamera) // Initialize services - flashSvc := flash.NewService(deviceMgr, modelRepo) + flashSvc := flash.NewService(deviceMgr, modelRepo, dataDir) inferenceSvc := inference.NewService(deviceMgr) // Determine static file system for embedded frontend