Files
Kent Delante 7f70816ce4 feat(files_sharing): schedule external share scan job when accepted
Signed-off-by: Kent Delante <kent@delante.me>

Schedule a scan job on an external share when an account accepts it
to make file information available (e.g. size) without having to
interact with the share.
2026-07-15 15:43:11 +00:00

66 lines
1.7 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_Sharing\Controller;
use OCA\Files_Sharing\BackgroundJob\ExternalShareScanJob;
use OCA\Files_Sharing\External\Manager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\BackgroundJob\IJobList;
use OCP\IRequest;
/**
* Class ExternalSharesController
*
* @package OCA\Files_Sharing\Controller
*/
class ExternalSharesController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private readonly Manager $externalManager,
private IJobList $jobList,
) {
parent::__construct($appName, $request);
}
/**
* @NoOutgoingFederatedSharingRequired
*/
#[NoAdminRequired]
public function index(): JSONResponse {
return new JSONResponse($this->externalManager->getOpenShares());
}
/**
* @NoOutgoingFederatedSharingRequired
*/
#[NoAdminRequired]
public function create(string $id): JSONResponse {
$externalShare = $this->externalManager->getShare($id);
if ($externalShare !== false) {
$this->externalManager->acceptShare($externalShare);
$this->jobList->add(ExternalShareScanJob::class, [$externalShare->getUser(), $externalShare->getMountpoint()]);
}
return new JSONResponse();
}
/**
* @NoOutgoingFederatedSharingRequired
*/
#[NoAdminRequired]
public function destroy(string $id): JSONResponse {
$externalShare = $this->externalManager->getShare($id);
if ($externalShare !== false) {
$this->externalManager->declineShare($externalShare);
}
return new JSONResponse();
}
}