filename = $filename; $this->branchId = $branchId; } public function handle(): void { $path = $this->filename; if (!file_exists($path)) { Log::error("❌ SQLite 檔案不存在: {$path}"); return; } $user = \App\Models\User::find(2); $token = $user->api_plain_token; $branches = $this->branchId ? Branch::where('id', $this->branchId)->get() : Branch::where('enable', true)->cursor(); foreach ($branches as $branch) { $client = new ApiClient($branch->external_ip , $token ); $response = $client->upload('/api/upload-sqlite', ['file' => $path]); if ($response->successful()) { Log::info("✅ $branch->name 檔案 {$path} 傳送成功"); } else { Log::error("❌ $branch->name 傳送失敗:HTTP {$response->status()}"); Log::error($response->body()); } } if (file_exists($path)) { sleep(1); // 小延遲避免未立即釋放 if (@unlink($path)) { Log::info("🧹 Temp SQLite file deleted: {$path}"); } else { Log::error("❌ 無法刪除 SQLite 檔案:{$path}"); } } } }