fix(vikon): all FM files go to files/ dir, matching original PHP getFsPathByModule

Original vikon_core Path::getFsPathByModule() returns moduleRoot/files/,
not moduleRoot. Root FM files, 3-letter subdirs, and new files all go
under files/ directory. index.html etc come from core ZIP, not FM sync.
This commit is contained in:
F4ilji
2026-07-04 23:02:43 +05:00
parent cccdbbbbd8
commit b538b4119f
2 changed files with 12 additions and 15 deletions
@@ -27,13 +27,13 @@ class SyncFilesAction
$synced = 0; $synced = 0;
$synced += $this->syncRootDir($moduleId, $modulePath, $accessToken); $synced += $this->syncRootDir($moduleId, $filesDir, $accessToken);
foreach ($dirIds as $dirId) { foreach ($dirIds as $dirId) {
$synced += $this->syncSubDir($dirId, $moduleId, $filesDir, $accessToken); $synced += $this->syncSubDir($dirId, $moduleId, $filesDir, $accessToken);
} }
$newSynced = $this->syncNewFiles($moduleId, $accessToken, $modulePath); $newSynced = $this->syncNewFiles($moduleId, $accessToken, $filesDir);
$total = $synced + $newSynced; $total = $synced + $newSynced;
Log::info('Vikon FM: sync complete', ['downloaded' => $synced, 'new' => $newSynced]); Log::info('Vikon FM: sync complete', ['downloaded' => $synced, 'new' => $newSynced]);
@@ -61,7 +61,7 @@ class SyncFilesAction
return $body['directories'] ?? []; return $body['directories'] ?? [];
} }
private function syncRootDir(int $moduleId, string $modulePath, string $accessToken): int private function syncRootDir(int $moduleId, string $filesDir, string $accessToken): int
{ {
$response = $this->http->getWithToken( $response = $this->http->getWithToken(
"sync/getFileNamesFromRootDirectoryByModule?moduleId={$moduleId}", "sync/getFileNamesFromRootDirectoryByModule?moduleId={$moduleId}",
@@ -84,7 +84,7 @@ class SyncFilesAction
$accessToken, $accessToken,
'filemanager' 'filemanager'
); );
file_put_contents($modulePath . '/' . $name, $content); file_put_contents($filesDir . '/' . $name, $content);
$synced++; $synced++;
} catch (\Throwable $e) { } catch (\Throwable $e) {
Log::warning('Vikon FM: root download failed', ['identity' => $identity, 'error' => $e->getMessage()]); Log::warning('Vikon FM: root download failed', ['identity' => $identity, 'error' => $e->getMessage()]);
@@ -128,7 +128,7 @@ class SyncFilesAction
return $synced; return $synced;
} }
private function syncNewFiles(int $moduleId, string $accessToken, string $modulePath): int private function syncNewFiles(int $moduleId, string $accessToken, string $filesDir): int
{ {
$synced = 0; $synced = 0;
@@ -148,10 +148,7 @@ class SyncFilesAction
$filename = $body['file_name']; $filename = $body['file_name'];
$directory = $body['dir_name'] ?? null; $directory = $body['dir_name'] ?? null;
$targetDir = $modulePath; $targetDir = $directory ? $filesDir . '/' . $directory : $filesDir;
if ($directory) {
$targetDir = $modulePath . '/' . $directory;
}
$content = $this->http->downloadWithToken( $content = $this->http->downloadWithToken(
"sync/downloadFileBinary?identity={$identity}", "sync/downloadFileBinary?identity={$identity}",
@@ -78,18 +78,18 @@ class UpdateCoreAction
$synced = 0; $synced = 0;
$synced += $this->syncRootDir($moduleId, $modulePath, $accessToken); $synced += $this->syncRootDir($moduleId, $filesDir, $accessToken);
foreach ($dirIds as $dirId) { foreach ($dirIds as $dirId) {
$synced += $this->syncSubDir($dirId, $moduleId, $filesDir, $accessToken); $synced += $this->syncSubDir($dirId, $moduleId, $filesDir, $accessToken);
} }
$newSynced = $this->syncNewFiles($moduleId, $accessToken, $modulePath); $newSynced = $this->syncNewFiles($moduleId, $accessToken, $filesDir);
Log::info('Vikon FM: sync done', ['synced' => $synced, 'new' => $newSynced]); Log::info('Vikon FM: sync done', ['synced' => $synced, 'new' => $newSynced]);
} }
private function syncRootDir(int $moduleId, string $modulePath, string $accessToken): int private function syncRootDir(int $moduleId, string $filesDir, string $accessToken): int
{ {
$response = $this->http->getWithToken( $response = $this->http->getWithToken(
"sync/getFileNamesFromRootDirectoryByModule?moduleId={$moduleId}", "sync/getFileNamesFromRootDirectoryByModule?moduleId={$moduleId}",
@@ -112,7 +112,7 @@ class UpdateCoreAction
$accessToken, $accessToken,
'filemanager' 'filemanager'
); );
file_put_contents($modulePath . '/' . $name, $content); file_put_contents($filesDir . '/' . $name, $content);
$synced++; $synced++;
} catch (\Throwable $e) { } catch (\Throwable $e) {
Log::warning('Vikon FM: root download failed', ['identity' => $identity, 'error' => $e->getMessage()]); Log::warning('Vikon FM: root download failed', ['identity' => $identity, 'error' => $e->getMessage()]);
@@ -156,7 +156,7 @@ class UpdateCoreAction
return $synced; return $synced;
} }
private function syncNewFiles(int $moduleId, string $accessToken, string $modulePath): int private function syncNewFiles(int $moduleId, string $accessToken, string $filesDir): int
{ {
$synced = 0; $synced = 0;
while (true) { while (true) {
@@ -173,7 +173,7 @@ class UpdateCoreAction
$filename = $body['file_name']; $filename = $body['file_name'];
$directory = $body['dir_name'] ?? null; $directory = $body['dir_name'] ?? null;
$targetDir = $directory ? $modulePath . '/' . $directory : $modulePath; $targetDir = $directory ? $filesDir . '/' . $directory : $filesDir;
try { try {
$content = $this->http->downloadWithToken( $content = $this->http->downloadWithToken(