MCPcopy Create free account
hub / github.com/error311/FileRise / countVisibleRemote

Method countVisibleRemote

src/FileRise/Domain/FolderModel.php:355–463  ·  view source on GitHub ↗
(string $folder, string $user, array $perms)

Source from the content-addressed store, hash-verified

353 }
354
355 private static function countVisibleRemote(string $folder, string $user, array $perms): array
356 {
357 $storage = self::storage();
358
359 $canViewFolder = ACL::isAdmin($perms)
360 || ACL::canRead($user, $perms, $folder)
361 || ACL::canReadOwn($user, $perms, $folder);
362 if (!$canViewFolder) {
363 return ['folders' => 0, 'files' => 0, 'bytes' => 0];
364 }
365
366 $hasFullRead = ACL::isAdmin($perms) || ACL::canRead($user, $perms, $folder);
367
368 $base = rtrim(self::uploadRoot(), "/\\");
369 if ($base === '') {
370 return ['folders' => 0, 'files' => 0, 'bytes' => 0];
371 }
372
373 $dirPath = ($folder === 'root')
374 ? $base
375 : $base . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $folder);
376
377 $entries = $storage->list($dirPath);
378 if (!$entries) {
379 return ['folders' => 0, 'files' => 0, 'bytes' => 0];
380 }
381
382 $SKIP = FS::SKIP();
383
384 $folderCount = 0;
385 $fileCount = 0;
386 $totalBytes = 0;
387 $earliestUploaded = null;
388 $latestMtime = null;
389
390 foreach ($entries as $name) {
391 if ($name === '.' || $name === '..' || $name === '') {
392 continue;
393 }
394 if ($name[0] === '.') {
395 continue;
396 }
397 if (FS::shouldIgnoreEntry($name, $folder)) {
398 continue;
399 }
400 if (!FS::isSafeSegment($name)) {
401 continue;
402 }
403 if (in_array(strtolower($name), $SKIP, true)) {
404 continue;
405 }
406
407 $full = $dirPath . DIRECTORY_SEPARATOR . $name;
408 $stat = $storage->stat($full);
409 if (!$stat) {
410 continue;
411 }
412

Callers 1

countVisibleMethod · 0.95

Calls 10

storageMethod · 0.95
uploadRootMethod · 0.95
canReadMethod · 0.80
canReadOwnMethod · 0.80
SKIPMethod · 0.80
shouldIgnoreEntryMethod · 0.80
isAdminMethod · 0.45
listMethod · 0.45
isSafeSegmentMethod · 0.45
statMethod · 0.45

Tested by

no test coverage detected