From aa324cef42c4cfc0ecb8c8b07cab4a818c231317 Mon Sep 17 00:00:00 2001 From: jim800121chen Date: Sun, 12 Apr 2026 22:03:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(local-tool):=20flash=20=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=AA=94=E6=A1=88=E6=89=BE=E4=B8=8D=E5=88=B0=20=E2=80=94=20?= =?UTF-8?q?=E7=9B=B8=E5=B0=8D=E8=B7=AF=E5=BE=91=E6=9C=AA=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:models.json 的 filePath 是相對路徑("data/nef/kl520/xxx.nef"), 但 server working directory 是 {app}\bin\(app.go 設 cmd.Dir = binary 目錄), 所以 server 在 {app}\bin\data\nef\ 找 .nef 檔,找不到。 實際位置:{app}\data\nef\(installer 裝的位置),對應 server 的 --data-dir 由 Wails app 傳入的 %APPDATA%\visiona-local(或 fallback 到 /../data)。 修法: - flash.NewService 新增 dataDir 參數 - StartFlash 中把相對 filePath 用 dataDir 拼接成絕對路徑: "data/nef/..." → 去掉 "data/" 前綴 → dataDir + "/nef/..." - main.go 傳 dataDir 給 flash.NewService Co-Authored-By: Claude Opus 4.6 (1M context) --- local-tool/server/internal/flash/service.go | 16 +++++++++++++++- local-tool/server/main.go | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) 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