-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: nabim777 <[email protected]>
- Loading branch information
Showing
4 changed files
with
20 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* ownCloud | ||
* | ||
* @author Nabin Magar <[email protected]> | ||
* @copyright Copyright (c) 2017 Nabin Magar [email protected] | ||
* @copyright Copyright (c) 2025 Nabin Magar [email protected] | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, | ||
|
@@ -23,54 +23,17 @@ | |
namespace TestHelpers; | ||
|
||
use Carbon\Carbon; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use TusPhp\Exception\FileException; | ||
use GuzzleHttp\Exception\ClientException; | ||
use Psr\Http\Message\ResponseInterface; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use Symfony\Component\HttpFoundation\Response as HttpResponse; | ||
use ReflectionException; | ||
use TusPhp\Tus\Client; | ||
|
||
/** | ||
* A helper class where TUS is wrapped and done API requests | ||
* A TUS client based on TusPhp\Tus\Client | ||
*/ | ||
|
||
class TusClientWrapper extends Client { | ||
public $client; | ||
|
||
/** | ||
* Constructor for the TusClientWrapper. | ||
* | ||
* @param string $baseUri | ||
* @param array $options | ||
* | ||
* @throws ReflectionException | ||
*/ | ||
public function __construct(string $baseUri, array $options = []) { | ||
parent::__construct($baseUri, $options); | ||
$this->client = new Client($baseUri, $options); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return self | ||
*/ | ||
public function setKey(string $key): self { | ||
$this->client->setKey($key); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* @param string|null $name | ||
* | ||
* @return self | ||
*/ | ||
public function file(string $file, string $name = null): self { | ||
$this->client->file($file, $name); | ||
return $this; | ||
} | ||
class TusClient extends Client { | ||
|
||
/** | ||
* @param string $key | ||
|
@@ -82,15 +45,15 @@ public function file(string $file, string $name = null): self { | |
public function createUploadWithResponse(string $key, int $bytes = -1): ResponseInterface { | ||
$bytes = $bytes < 0 ? $this->fileSize : $bytes; | ||
$headers = $this->headers + [ | ||
'Upload-Length' => $this->client->fileSize, | ||
'Upload-Length' => $this->fileSize, | ||
'Upload-Key' => $key, | ||
'Upload-Checksum' => $this->client->getUploadChecksumHeader(), | ||
'Upload-Metadata' => $this->client->getUploadMetadataHeader(), | ||
'Upload-Checksum' => $this->getUploadChecksumHeader(), | ||
'Upload-Metadata' => $this->getUploadMetadataHeader(), | ||
]; | ||
|
||
$data = ''; | ||
if ($bytes > 0) { | ||
$data = $this->client->getData(0, $bytes); | ||
$data = $this->getData(0, $bytes); | ||
|
||
$headers += [ | ||
'Content-Type' => self::HEADER_CONTENT_TYPE, | ||
|
@@ -103,7 +66,7 @@ public function createUploadWithResponse(string $key, int $bytes = -1): Response | |
} | ||
|
||
try { | ||
$response = $this->client->getClient()->post( | ||
$response = $this->getClient()->post( | ||
$this->apiPath, | ||
[ | ||
'body' => $data, | ||
|
@@ -123,7 +86,7 @@ public function createUploadWithResponse(string $key, int $bytes = -1): Response | |
$uploadLocation = current($response->getHeader('location')); | ||
|
||
$this->getCache()->set( | ||
$this->client->getKey(), | ||
$this->getKey(), | ||
[ | ||
'location' => $uploadLocation, | ||
'expires_at' => Carbon::now()->addSeconds($this->getCache()->getTtl())->format($this->getCache()::RFC_7231), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters