@@ -32,92 +32,92 @@ |
||
32 | 32 | use Sabre\DAV\ICollection; |
33 | 33 | |
34 | 34 | class UploadFolder implements ICollection { |
35 | - /** @var Directory */ |
|
36 | - private $node; |
|
37 | - /** @var CleanupService */ |
|
38 | - private $cleanupService; |
|
39 | - /** @var IStorage */ |
|
40 | - private $storage; |
|
41 | - |
|
42 | - public function __construct(Directory $node, CleanupService $cleanupService, IStorage $storage) { |
|
43 | - $this->node = $node; |
|
44 | - $this->cleanupService = $cleanupService; |
|
45 | - $this->storage = $storage; |
|
46 | - } |
|
47 | - |
|
48 | - public function createFile($name, $data = null) { |
|
49 | - // TODO: verify name - should be a simple number |
|
50 | - $this->node->createFile($name, $data); |
|
51 | - } |
|
52 | - |
|
53 | - public function createDirectory($name) { |
|
54 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
55 | - } |
|
56 | - |
|
57 | - public function getChild($name) { |
|
58 | - if ($name === '.file') { |
|
59 | - return new FutureFile($this->node, '.file'); |
|
60 | - } |
|
61 | - return new UploadFile($this->node->getChild($name)); |
|
62 | - } |
|
63 | - |
|
64 | - public function getChildren() { |
|
65 | - $tmpChildren = $this->node->getChildren(); |
|
66 | - |
|
67 | - $children = []; |
|
68 | - $children[] = new FutureFile($this->node, '.file'); |
|
69 | - |
|
70 | - foreach ($tmpChildren as $child) { |
|
71 | - $children[] = new UploadFile($child); |
|
72 | - } |
|
73 | - |
|
74 | - if ($this->storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
75 | - /** @var ObjectStoreStorage $storage */ |
|
76 | - $objectStore = $this->storage->getObjectStore(); |
|
77 | - if ($objectStore instanceof IObjectStoreMultiPartUpload) { |
|
78 | - $cache = \OC::$server->getMemCacheFactory()->createDistributed(ChunkingV2Plugin::CACHE_KEY); |
|
79 | - $uploadSession = $cache->get($this->getName()); |
|
80 | - if ($uploadSession) { |
|
81 | - $uploadId = $uploadSession[ChunkingV2Plugin::UPLOAD_ID]; |
|
82 | - $id = $uploadSession[ChunkingV2Plugin::UPLOAD_TARGET_ID]; |
|
83 | - $parts = $objectStore->getMultipartUploads($this->storage->getURN($id), $uploadId); |
|
84 | - foreach ($parts as $part) { |
|
85 | - $children[] = new PartFile($this->node, $part); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - return $children; |
|
92 | - } |
|
93 | - |
|
94 | - public function childExists($name) { |
|
95 | - if ($name === '.file') { |
|
96 | - return true; |
|
97 | - } |
|
98 | - return $this->node->childExists($name); |
|
99 | - } |
|
100 | - |
|
101 | - public function delete() { |
|
102 | - $this->node->delete(); |
|
103 | - |
|
104 | - // Background cleanup job is not needed anymore |
|
105 | - $this->cleanupService->removeJob($this->getName()); |
|
106 | - } |
|
107 | - |
|
108 | - public function getName() { |
|
109 | - return $this->node->getName(); |
|
110 | - } |
|
111 | - |
|
112 | - public function setName($name) { |
|
113 | - throw new Forbidden('Permission denied to rename this folder'); |
|
114 | - } |
|
115 | - |
|
116 | - public function getLastModified() { |
|
117 | - return $this->node->getLastModified(); |
|
118 | - } |
|
119 | - |
|
120 | - public function getStorage() { |
|
121 | - return $this->storage; |
|
122 | - } |
|
35 | + /** @var Directory */ |
|
36 | + private $node; |
|
37 | + /** @var CleanupService */ |
|
38 | + private $cleanupService; |
|
39 | + /** @var IStorage */ |
|
40 | + private $storage; |
|
41 | + |
|
42 | + public function __construct(Directory $node, CleanupService $cleanupService, IStorage $storage) { |
|
43 | + $this->node = $node; |
|
44 | + $this->cleanupService = $cleanupService; |
|
45 | + $this->storage = $storage; |
|
46 | + } |
|
47 | + |
|
48 | + public function createFile($name, $data = null) { |
|
49 | + // TODO: verify name - should be a simple number |
|
50 | + $this->node->createFile($name, $data); |
|
51 | + } |
|
52 | + |
|
53 | + public function createDirectory($name) { |
|
54 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
55 | + } |
|
56 | + |
|
57 | + public function getChild($name) { |
|
58 | + if ($name === '.file') { |
|
59 | + return new FutureFile($this->node, '.file'); |
|
60 | + } |
|
61 | + return new UploadFile($this->node->getChild($name)); |
|
62 | + } |
|
63 | + |
|
64 | + public function getChildren() { |
|
65 | + $tmpChildren = $this->node->getChildren(); |
|
66 | + |
|
67 | + $children = []; |
|
68 | + $children[] = new FutureFile($this->node, '.file'); |
|
69 | + |
|
70 | + foreach ($tmpChildren as $child) { |
|
71 | + $children[] = new UploadFile($child); |
|
72 | + } |
|
73 | + |
|
74 | + if ($this->storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
75 | + /** @var ObjectStoreStorage $storage */ |
|
76 | + $objectStore = $this->storage->getObjectStore(); |
|
77 | + if ($objectStore instanceof IObjectStoreMultiPartUpload) { |
|
78 | + $cache = \OC::$server->getMemCacheFactory()->createDistributed(ChunkingV2Plugin::CACHE_KEY); |
|
79 | + $uploadSession = $cache->get($this->getName()); |
|
80 | + if ($uploadSession) { |
|
81 | + $uploadId = $uploadSession[ChunkingV2Plugin::UPLOAD_ID]; |
|
82 | + $id = $uploadSession[ChunkingV2Plugin::UPLOAD_TARGET_ID]; |
|
83 | + $parts = $objectStore->getMultipartUploads($this->storage->getURN($id), $uploadId); |
|
84 | + foreach ($parts as $part) { |
|
85 | + $children[] = new PartFile($this->node, $part); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + return $children; |
|
92 | + } |
|
93 | + |
|
94 | + public function childExists($name) { |
|
95 | + if ($name === '.file') { |
|
96 | + return true; |
|
97 | + } |
|
98 | + return $this->node->childExists($name); |
|
99 | + } |
|
100 | + |
|
101 | + public function delete() { |
|
102 | + $this->node->delete(); |
|
103 | + |
|
104 | + // Background cleanup job is not needed anymore |
|
105 | + $this->cleanupService->removeJob($this->getName()); |
|
106 | + } |
|
107 | + |
|
108 | + public function getName() { |
|
109 | + return $this->node->getName(); |
|
110 | + } |
|
111 | + |
|
112 | + public function setName($name) { |
|
113 | + throw new Forbidden('Permission denied to rename this folder'); |
|
114 | + } |
|
115 | + |
|
116 | + public function getLastModified() { |
|
117 | + return $this->node->getLastModified(); |
|
118 | + } |
|
119 | + |
|
120 | + public function getStorage() { |
|
121 | + return $this->storage; |
|
122 | + } |
|
123 | 123 | } |
@@ -32,80 +32,80 @@ |
||
32 | 32 | use Sabre\DAV\ICollection; |
33 | 33 | |
34 | 34 | class UploadHome implements ICollection { |
35 | - /** @var array */ |
|
36 | - private $principalInfo; |
|
37 | - /** @var CleanupService */ |
|
38 | - private $cleanupService; |
|
39 | - |
|
40 | - public function __construct(array $principalInfo, CleanupService $cleanupService) { |
|
41 | - $this->principalInfo = $principalInfo; |
|
42 | - $this->cleanupService = $cleanupService; |
|
43 | - } |
|
44 | - |
|
45 | - public function createFile($name, $data = null) { |
|
46 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
47 | - } |
|
48 | - |
|
49 | - public function createDirectory($name) { |
|
50 | - $this->impl()->createDirectory($name); |
|
51 | - |
|
52 | - // Add a cleanup job |
|
53 | - $this->cleanupService->addJob($name); |
|
54 | - } |
|
55 | - |
|
56 | - public function getChild($name): UploadFolder { |
|
57 | - return new UploadFolder($this->impl()->getChild($name), $this->cleanupService, $this->getStorage()); |
|
58 | - } |
|
59 | - |
|
60 | - public function getChildren(): array { |
|
61 | - return array_map(function ($node) { |
|
62 | - return new UploadFolder($node, $this->cleanupService, $this->getStorage()); |
|
63 | - }, $this->impl()->getChildren()); |
|
64 | - } |
|
65 | - |
|
66 | - public function childExists($name): bool { |
|
67 | - return !is_null($this->getChild($name)); |
|
68 | - } |
|
69 | - |
|
70 | - public function delete() { |
|
71 | - $this->impl()->delete(); |
|
72 | - } |
|
73 | - |
|
74 | - public function getName() { |
|
75 | - [,$name] = \Sabre\Uri\split($this->principalInfo['uri']); |
|
76 | - return $name; |
|
77 | - } |
|
78 | - |
|
79 | - public function setName($name) { |
|
80 | - throw new Forbidden('Permission denied to rename this folder'); |
|
81 | - } |
|
82 | - |
|
83 | - public function getLastModified() { |
|
84 | - return $this->impl()->getLastModified(); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return Directory |
|
89 | - */ |
|
90 | - private function impl() { |
|
91 | - $view = $this->getView(); |
|
92 | - $rootInfo = $view->getFileInfo(''); |
|
93 | - return new Directory($view, $rootInfo); |
|
94 | - } |
|
95 | - |
|
96 | - private function getView() { |
|
97 | - $rootView = new View(); |
|
98 | - $user = \OC::$server->getUserSession()->getUser(); |
|
99 | - Filesystem::initMountPoints($user->getUID()); |
|
100 | - if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { |
|
101 | - $rootView->mkdir('/' . $user->getUID() . '/uploads'); |
|
102 | - } |
|
103 | - return new View('/' . $user->getUID() . '/uploads'); |
|
104 | - } |
|
105 | - |
|
106 | - private function getStorage() { |
|
107 | - $view = $this->getView(); |
|
108 | - $storage = $view->getFileInfo('')->getStorage(); |
|
109 | - return $storage; |
|
110 | - } |
|
35 | + /** @var array */ |
|
36 | + private $principalInfo; |
|
37 | + /** @var CleanupService */ |
|
38 | + private $cleanupService; |
|
39 | + |
|
40 | + public function __construct(array $principalInfo, CleanupService $cleanupService) { |
|
41 | + $this->principalInfo = $principalInfo; |
|
42 | + $this->cleanupService = $cleanupService; |
|
43 | + } |
|
44 | + |
|
45 | + public function createFile($name, $data = null) { |
|
46 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
47 | + } |
|
48 | + |
|
49 | + public function createDirectory($name) { |
|
50 | + $this->impl()->createDirectory($name); |
|
51 | + |
|
52 | + // Add a cleanup job |
|
53 | + $this->cleanupService->addJob($name); |
|
54 | + } |
|
55 | + |
|
56 | + public function getChild($name): UploadFolder { |
|
57 | + return new UploadFolder($this->impl()->getChild($name), $this->cleanupService, $this->getStorage()); |
|
58 | + } |
|
59 | + |
|
60 | + public function getChildren(): array { |
|
61 | + return array_map(function ($node) { |
|
62 | + return new UploadFolder($node, $this->cleanupService, $this->getStorage()); |
|
63 | + }, $this->impl()->getChildren()); |
|
64 | + } |
|
65 | + |
|
66 | + public function childExists($name): bool { |
|
67 | + return !is_null($this->getChild($name)); |
|
68 | + } |
|
69 | + |
|
70 | + public function delete() { |
|
71 | + $this->impl()->delete(); |
|
72 | + } |
|
73 | + |
|
74 | + public function getName() { |
|
75 | + [,$name] = \Sabre\Uri\split($this->principalInfo['uri']); |
|
76 | + return $name; |
|
77 | + } |
|
78 | + |
|
79 | + public function setName($name) { |
|
80 | + throw new Forbidden('Permission denied to rename this folder'); |
|
81 | + } |
|
82 | + |
|
83 | + public function getLastModified() { |
|
84 | + return $this->impl()->getLastModified(); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return Directory |
|
89 | + */ |
|
90 | + private function impl() { |
|
91 | + $view = $this->getView(); |
|
92 | + $rootInfo = $view->getFileInfo(''); |
|
93 | + return new Directory($view, $rootInfo); |
|
94 | + } |
|
95 | + |
|
96 | + private function getView() { |
|
97 | + $rootView = new View(); |
|
98 | + $user = \OC::$server->getUserSession()->getUser(); |
|
99 | + Filesystem::initMountPoints($user->getUID()); |
|
100 | + if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { |
|
101 | + $rootView->mkdir('/' . $user->getUID() . '/uploads'); |
|
102 | + } |
|
103 | + return new View('/' . $user->getUID() . '/uploads'); |
|
104 | + } |
|
105 | + |
|
106 | + private function getStorage() { |
|
107 | + $view = $this->getView(); |
|
108 | + $storage = $view->getFileInfo('')->getStorage(); |
|
109 | + return $storage; |
|
110 | + } |
|
111 | 111 | } |