123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- declare(strict_types=1);
- namespace OCA\Files_External\Controller;
- use OCA\Files_External\Lib\StorageConfig;
- use OCA\Files_External\ResponseDefinitions;
- use OCA\Files_External\Service\UserGlobalStoragesService;
- use OCA\Files_External\Service\UserStoragesService;
- use OCP\AppFramework\Http;
- use OCP\AppFramework\Http\Attribute\NoAdminRequired;
- use OCP\AppFramework\Http\DataResponse;
- use OCP\AppFramework\OCSController;
- use OCP\Constants;
- use OCP\IRequest;
- class ApiController extends OCSController {
- public function __construct(
- string $appName,
- IRequest $request,
- private UserGlobalStoragesService $userGlobalStoragesService,
- private UserStoragesService $userStoragesService,
- ) {
- parent::__construct($appName, $request);
- }
-
- private function formatMount(string $mountPoint, StorageConfig $mountConfig): array {
-
- $path = \dirname($mountPoint);
- if ($path === '.' || $path === '/') {
- $path = '';
- }
- $isSystemMount = $mountConfig->getType() === StorageConfig::MOUNT_TYPE_ADMIN;
- $permissions = Constants::PERMISSION_READ;
-
- if (!$isSystemMount) {
- $permissions |= Constants::PERMISSION_DELETE;
- }
- $entry = [
- 'id' => $mountConfig->getId(),
- 'type' => 'dir',
- 'name' => basename($mountPoint),
- 'path' => $path,
- 'permissions' => $permissions,
- 'scope' => $isSystemMount ? 'system' : 'personal',
- 'backend' => $mountConfig->getBackend()->getText(),
- 'class' => $mountConfig->getBackend()->getIdentifier(),
- 'config' => $mountConfig->jsonSerialize(true),
- ];
- return $entry;
- }
-
-
- public function getUserMounts(): DataResponse {
- $entries = [];
- $mountPoints = [];
- foreach ($this->userGlobalStoragesService->getStorages() as $storage) {
- $mountPoint = $storage->getMountPoint();
- $mountPoints[$mountPoint] = $storage;
- }
- foreach ($this->userStoragesService->getStorages() as $storage) {
- $mountPoint = $storage->getMountPoint();
- $mountPoints[$mountPoint] = $storage;
- }
- foreach ($mountPoints as $mountPoint => $mount) {
- $entries[] = $this->formatMount($mountPoint, $mount);
- }
- return new DataResponse($entries);
- }
- }
|