Client
1 year ago
.htaccess
1 year ago
ChunkedDownload.php
1 year ago
ChunkedUpload.php
1 year ago
DirIterator.php
1 year ago
DropBox.php
1 year ago
index.html
1 year ago
web.config
1 year ago
ChunkedUpload.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Destination\Vendors\DropBox; |
| 4 | |
| 5 | use JetBackup\Destination\Integration\DestinationChunkedUpload; |
| 6 | use JetBackup\Destination\Vendors\DropBox\Client\Client; |
| 7 | use JetBackup\Exception\IOException; |
| 8 | use JetBackup\Web\File\FileChunk; |
| 9 | use JetBackup\Web\File\FileStream; |
| 10 | |
| 11 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 12 | |
| 13 | class ChunkedUpload implements DestinationChunkedUpload { |
| 14 | |
| 15 | private Client $_client; |
| 16 | private string $_source; |
| 17 | private string $_destination; |
| 18 | private object $_data; |
| 19 | |
| 20 | public function __construct(Client $client, $source, $destination) { |
| 21 | $this->_client = $client; |
| 22 | $this->_source = $source; |
| 23 | $this->_destination = $destination; |
| 24 | $this->_data = new \stdClass(); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @return object |
| 29 | */ |
| 30 | public function prepare():object { |
| 31 | return $this->_client->startUploadSession()->Body; |
| 32 | } |
| 33 | |
| 34 | public function setData(object $data):void { |
| 35 | $this->_data = $data; |
| 36 | } |
| 37 | |
| 38 | public function getOffset():int { |
| 39 | if(!isset($this->_data->session_id)) throw new IOException("No session id was found"); |
| 40 | return $this->_client->getUploadSessionOffset($this->_data->session_id); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @return int|null |
| 45 | */ |
| 46 | public function getChunkSize():?int { return null; } |
| 47 | |
| 48 | /** |
| 49 | * @param FileChunk $chunk |
| 50 | * |
| 51 | * @return void |
| 52 | */ |
| 53 | public function upload(FileChunk $chunk):void { |
| 54 | if(!isset($this->_data->session_id)) throw new IOException("No session id was found"); |
| 55 | $this->_client->appendUploadSession($chunk, $this->_data->session_id); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return void |
| 60 | */ |
| 61 | public function finalize():void { |
| 62 | if(!isset($this->_data->session_id)) throw new IOException("No session id was found"); |
| 63 | $this->_client->finishUploadSession($this->_data->session_id, $this->getOffset(), $this->_destination); |
| 64 | } |
| 65 | } |