1 | <?php |
||
18 | class RequestHelper { |
||
19 | |||
20 | /** |
||
21 | * @var IRequest |
||
22 | */ |
||
23 | private $request; |
||
24 | |||
25 | 4 | public function __construct(IRequest $request) { |
|
28 | |||
29 | /** |
||
30 | * Get current upload size |
||
31 | * returns null for chunks and when there is no upload |
||
32 | * |
||
33 | * @param string $path |
||
34 | * |
||
35 | * @return int|null |
||
36 | */ |
||
37 | 3 | public function getUploadSize($path) { |
|
38 | 3 | $uploadSize = null; |
|
39 | |||
40 | 3 | $requestMethod = $this->request->getMethod(); |
|
41 | 3 | $isRemoteScript = $this->isScriptName('remote.php'); |
|
42 | 3 | $isPublicScript = $this->isScriptName('public.php'); |
|
43 | // Are we uploading anything? |
||
44 | 3 | if (\in_array($requestMethod, ['MOVE', 'PUT']) && $isRemoteScript) { |
|
45 | // v1 && v2 Chunks are not scanned |
||
46 | 1 | if ($requestMethod === 'PUT' && \strpos($path, 'uploads/') === 0) { |
|
47 | 1 | return null; |
|
48 | } |
||
49 | |||
50 | if (\OC_FileChunking::isWebdavChunk() && \strpos($path, 'cache/') === 0) { |
||
51 | return null; |
||
52 | } |
||
53 | |||
54 | if ($requestMethod === 'PUT') { |
||
55 | $uploadSize = (int)$this->request->getHeader('CONTENT_LENGTH'); |
||
56 | } else { |
||
57 | $uploadSize = (int)$this->request->getHeader('OC_TOTAL_LENGTH'); |
||
58 | } |
||
59 | 2 | } else if ($requestMethod === 'PUT' && $isPublicScript) { |
|
60 | 1 | $uploadSize = (int)$this->request->getHeader('CONTENT_LENGTH'); |
|
61 | 1 | } |
|
62 | |||
63 | 2 | return $uploadSize; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * |
||
68 | * @param string $string |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 3 | public function isScriptName($string) { |
|
76 | } |
||
77 |