1515
1616class BackupRemoteUploadController extends Controller
1717{
18- public const PART_SIZE = 5 * 1024 * 1024 * 1024 ;
18+ public const DEFAULT_MAX_PART_SIZE = 5 * 1024 * 1024 * 1024 ;
1919
2020 /**
2121 * @var \Pterodactyl\Repositories\Eloquent\BackupRepository
@@ -89,9 +89,12 @@ public function __invoke(Request $request, string $backup)
8989 // the other presigned urls.
9090 $ params ['UploadId ' ] = $ result ->get ('UploadId ' );
9191
92+ // Retrieve configured part size
93+ $ maxPartSize = $ this ->getConfiguredMaxPartSize ();
94+
9295 // Create as many UploadPart presigned urls as needed
9396 $ parts = [];
94- for ($ i = 0 ; $ i < ($ size / self :: PART_SIZE ); ++$ i ) {
97+ for ($ i = 0 ; $ i < ($ size / $ maxPartSize ); ++$ i ) {
9598 $ parts [] = $ client ->createPresignedRequest (
9699 $ client ->getCommand ('UploadPart ' , array_merge ($ params , ['PartNumber ' => $ i + 1 ])),
97100 $ expires
@@ -103,7 +106,30 @@ public function __invoke(Request $request, string $backup)
103106
104107 return new JsonResponse ([
105108 'parts ' => $ parts ,
106- 'part_size ' => self :: PART_SIZE ,
109+ 'part_size ' => $ maxPartSize ,
107110 ]);
108111 }
112+
113+ /**
114+ * Get the configured maximum size of a single part in the multipart uplaod.
115+ *
116+ * The function tries to retrieve a configured value from the configuration.
117+ * If no value is specified, a fallback value will be used.
118+ *
119+ * Note if the received config cannot be converted to int (0), is zero or is negative,
120+ * the fallback value will be used too.
121+ *
122+ * The fallback value is {@see BackupRemoteUploadController::DEFAULT_MAX_PART_SIZE}.
123+ *
124+ * @return int
125+ */
126+ private function getConfiguredMaxPartSize ()
127+ {
128+ $ maxPartSize = (int ) config ('backups.max_part_size ' , self ::DEFAULT_MAX_PART_SIZE );
129+ if ($ maxPartSize <= 0 ) {
130+ $ maxPartSize = self ::DEFAULT_MAX_PART_SIZE ;
131+ }
132+
133+ return $ maxPartSize ;
134+ }
109135}
0 commit comments