1 | <?php |
||
24 | class RequestHelper { |
||
25 | /** |
||
26 | * @var IRequest |
||
27 | */ |
||
28 | private $request; |
||
29 | |||
30 | /** |
||
31 | * @var CappedMemoryCache |
||
32 | */ |
||
33 | private $fileSizeCache; |
||
34 | |||
35 | /** |
||
36 | * RequestHelper constructor. |
||
37 | * |
||
38 | * @param IRequest $request |
||
39 | */ |
||
40 | 4 | public function __construct(IRequest $request) { |
|
41 | 4 | $this->request = $request; |
|
42 | 4 | $this->fileSizeCache = new CappedMemoryCache(); |
|
43 | 4 | } |
|
44 | |||
45 | /** |
||
46 | * @param string $path |
||
47 | * @param string $size |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | public function setSizeForPath($path, $size) { |
||
54 | |||
55 | /** |
||
56 | * Get current upload size |
||
57 | * returns null for chunks and when there is no upload |
||
58 | * |
||
59 | * @param string $path |
||
60 | * |
||
61 | * @return int|null |
||
62 | */ |
||
63 | 3 | public function getUploadSize($path) { |
|
64 | 3 | $cachedSize = $this->fileSizeCache->get($path); |
|
65 | 3 | if ($cachedSize > 0) { |
|
66 | return $cachedSize; |
||
67 | } |
||
68 | |||
69 | 3 | $requestMethod = $this->request->getMethod(); |
|
70 | // Are we uploading anything? |
||
71 | 3 | if ($requestMethod !== 'PUT') { |
|
72 | 1 | return null; |
|
73 | } |
||
74 | 2 | $isRemoteScript = $this->isScriptName('remote.php'); |
|
75 | 2 | $isPublicScript = $this->isScriptName('public.php'); |
|
76 | 2 | if (!$isRemoteScript && !$isPublicScript) { |
|
77 | return null; |
||
78 | } |
||
79 | |||
80 | 2 | if ($isRemoteScript) { |
|
81 | // v1 && v2 Chunks are not scanned |
||
82 | 1 | if (\strpos($path, 'uploads/') === 0) { |
|
83 | 1 | return null; |
|
84 | } |
||
85 | |||
86 | if (\OC_FileChunking::isWebdavChunk() |
||
87 | && \strpos($path, 'cache/') === 0 |
||
88 | ) { |
||
89 | return null; |
||
90 | } |
||
91 | } |
||
92 | 1 | $uploadSize = (int)$this->request->getHeader('CONTENT_LENGTH'); |
|
93 | |||
94 | 1 | return $uploadSize; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * |
||
99 | * @param string $string |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | 2 | public function isScriptName($string) { |
|
107 | } |
||
108 |