PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.22.4
JetBackup – Backup, Restore & Migrate v3.1.22.4
3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Destination / Vendors / pCloud / ChunkedUpload.php
backup / src / JetBackup / Destination / Vendors / pCloud Last commit date
Client 1 year ago .htaccess 1 year ago ChunkedDownload.php 1 year ago ChunkedUpload.php 1 year ago DirIterator.php 1 year ago index.html 1 year ago pCloud.php 1 year ago web.config 1 year ago
ChunkedUpload.php
106 lines
1 <?php
2
3 namespace JetBackup\Destination\Vendors\pCloud;
4
5 use JetBackup\Destination\Integration\DestinationChunkedUpload;
6 use JetBackup\Exception\IOException;
7 use JetBackup\Web\File\FileChunk;
8
9 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
10
11 class ChunkedUpload implements DestinationChunkedUpload {
12
13 private pCloud $_client;
14 private string $_destination;
15 private object $_data;
16
17 public function __construct(pCloud $client, $destination) {
18 $this->_client = $client;
19 $this->_destination = $destination;
20 $this->_data = new \stdClass();
21 }
22
23 /**
24 * @return object
25 */
26 public function prepare():object {
27 return $this->_client->_retries(function() {
28 $response = $this->_client->getClient()->startUploadSession();
29
30 // Debugging: Log the full response
31 $this->_client->getlogController()->logDebug("[ChunkedUpload prepare] Response: " . json_encode($response));
32
33 if (!isset($response->uploadid)) {
34 throw new IOException("Upload session ID is missing from the response.");
35 }
36
37 $output = new \stdClass();
38 $output->id = $response->uploadid;
39 return $output;
40 }, "Failed creating upload session");
41 }
42
43 public function setData(object $data):void {
44 $this->_data = $data;
45 }
46
47 /**
48 * @return int
49 */
50 public function getOffset():int {
51 if(!isset($this->_data->id)) throw new IOException("No session id was found");
52
53 return $this->_client->_retries(function() {
54 $offset = $this->_client->getClient()->getUploadSession($this->_data->id)->size;
55 $this->_client->getlogController()->logDebug("[ChunkedUpload getOffset] Offset: $offset");
56 return max( $offset, 0 );
57 }, "Failed fetching upload offset");
58 }
59
60 /**
61 * @return int|null
62 */
63 public function getChunkSize():?int {
64 if (!isset($this->_data->part_size)) {
65 $this->_client->getlogController()->logDebug("[ChunkedUpload getChunkSize] part_size is missing in the session data. Returning default chunk size.");
66 return $this->_client->getChunkSize();
67 }
68 return $this->_data->part_size;
69 }
70
71 /**
72 * @param FileChunk $chunk
73 *
74 * @return void
75 */
76 public function upload(FileChunk $chunk): void {
77 if (!isset($this->_data->id)) {
78 throw new IOException("No session id was found");
79 }
80
81 $this->_client->_retries(function () use ($chunk) {
82 $this->_client->getClient()->appendUploadSession($this->_data->id, $chunk);
83 }, "Failed uploading chunk");
84 }
85
86
87 /**
88 * @return void
89 */
90 public function finalize(): void {
91 if (!isset($this->_data->id)) {
92 throw new IOException("No session id was found");
93 }
94
95 $this->_client->_retries(function () {
96 $response = $this->_client->getClient()->commitUploadSession($this->_data->id, $this->_destination);
97
98 if (!$response) {
99 $this->_client->getlogController()->logDebug("[ChunkedUpload finalize] Commit response is empty.");
100 } else {
101 $this->_client->getlogController()->logDebug("[ChunkedUpload finalize] Upload session committed successfully.");
102 }
103 }, "Failed committing upload session");
104 }
105
106 }