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