refactor(dav): Pass UID from UploadHome to UploadFolder and CleanupService

Signed-off-by: provokateurin <kate@provokateurin.de>
This commit is contained in:
provokateurin 2025-04-14 15:44:59 +02:00
parent 7f0953d520
commit 8813df9623
No known key found for this signature in database
3 changed files with 27 additions and 15 deletions

View file

@ -10,20 +10,18 @@ namespace OCA\DAV\Upload;
use OCA\DAV\BackgroundJob\UploadCleanup;
use OCP\BackgroundJob\IJobList;
use OCP\IUserSession;
class CleanupService {
public function __construct(
private IUserSession $userSession,
private IJobList $jobList,
) {
}
public function addJob(string $folder) {
$this->jobList->add(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]);
public function addJob(string $uid, string $folder) {
$this->jobList->add(UploadCleanup::class, ['uid' => $uid, 'folder' => $folder]);
}
public function removeJob(string $folder) {
$this->jobList->remove(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]);
public function removeJob(string $uid, string $folder) {
$this->jobList->remove(UploadCleanup::class, ['uid' => $uid, 'folder' => $folder]);
}
}

View file

@ -21,6 +21,7 @@ class UploadFolder implements ICollection {
private Directory $node,
private CleanupService $cleanupService,
private IStorage $storage,
private string $uid,
) {
}
@ -89,7 +90,7 @@ class UploadFolder implements ICollection {
$this->node->delete();
// Background cleanup job is not needed anymore
$this->cleanupService->removeJob($this->getName());
$this->cleanupService->removeJob($this->uid, $this->getName());
}
public function getName() {

View file

@ -17,6 +17,7 @@ use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\ICollection;
class UploadHome implements ICollection {
private string $uid;
private ?Folder $uploadFolder = null;
public function __construct(
@ -25,6 +26,12 @@ class UploadHome implements ICollection {
private readonly IRootFolder $rootFolder,
private readonly IUserSession $userSession,
) {
$user = $this->userSession->getUser();
if (!$user) {
throw new Forbidden('Not logged in');
}
$this->uid = $user->getUID();
}
public function createFile($name, $data = null) {
@ -35,16 +42,26 @@ class UploadHome implements ICollection {
$this->impl()->createDirectory($name);
// Add a cleanup job
$this->cleanupService->addJob($name);
$this->cleanupService->addJob($this->uid, $name);
}
public function getChild($name): UploadFolder {
return new UploadFolder($this->impl()->getChild($name), $this->cleanupService, $this->getStorage());
return new UploadFolder(
$this->impl()->getChild($name),
$this->cleanupService,
$this->getStorage(),
$this->uid,
);
}
public function getChildren(): array {
return array_map(function ($node) {
return new UploadFolder($node, $this->cleanupService, $this->getStorage());
return new UploadFolder(
$node,
$this->cleanupService,
$this->getStorage(),
$this->uid,
);
}, $this->impl()->getChildren());
}
@ -71,11 +88,7 @@ class UploadHome implements ICollection {
private function getUploadFolder(): Folder {
if ($this->uploadFolder === null) {
$user = $this->userSession->getUser();
if (!$user) {
throw new Forbidden('Not logged in');
}
$path = '/' . $user->getUID() . '/uploads';
$path = '/' . $this->uid . '/uploads';
try {
$folder = $this->rootFolder->get($path);
if (!$folder instanceof Folder) {