From c4314e2f4319479ab0459759456cf1a7be2b776b Mon Sep 17 00:00:00 2001 From: F4ilji Date: Sat, 4 Jul 2026 22:15:59 +0500 Subject: [PATCH] fix(vikon): use getFileByIdentityInfo dir_name for correct file paths --- .../Actions/UpdateCoreAction.php | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app/Containers/VikonIntegration/Actions/UpdateCoreAction.php b/app/Containers/VikonIntegration/Actions/UpdateCoreAction.php index 1334721..22f6341 100644 --- a/app/Containers/VikonIntegration/Actions/UpdateCoreAction.php +++ b/app/Containers/VikonIntegration/Actions/UpdateCoreAction.php @@ -99,34 +99,44 @@ class UpdateCoreAction $accessToken, 'filemanager' ); - $targetDir = $filesDir; } else { $response = $this->http->getWithToken( "sync/getFileNamesFromSubDirectoryByModule?dir={$dirId}&moduleId={$moduleId}", $accessToken, 'filemanager' ); - $targetDir = $filesDir . '/' . $dirId; } $files = $response->json()['files'] ?? []; if (empty($files)) return 0; - File::makeDirectory($targetDir, 0755, true, true); - $synced = 0; foreach ($files as $file) { - $name = $file['n'] ?? null; $identity = $file['i'] ?? null; - if (!$name || !$identity) continue; + if (!$identity) continue; try { + $infoResp = $this->http->getWithToken( + "sync/getFileByIdentityInfo?identity={$identity}", + $accessToken, + 'filemanager' + ); + $info = $infoResp->json(); + + $filename = $info['file_name'] ?? $file['n'] ?? null; + $dirName = $info['dir_name'] ?? null; + + if (!$filename) continue; + + $targetDir = $dirName ? $filesDir . '/' . $dirName : $filesDir; + File::makeDirectory($targetDir, 0755, true, true); + $content = $this->http->downloadWithToken( "sync/downloadFileBinaryForSync?identity={$identity}&moduleId={$moduleId}", $accessToken, 'filemanager' ); - file_put_contents($targetDir . '/' . $name, $content); + file_put_contents($targetDir . '/' . $filename, $content); $synced++; } catch (\Throwable $e) { Log::warning('Vikon FM: download failed', ['identity' => $identity, 'error' => $e->getMessage()]);