This commit is contained in:
		
							parent
							
								
									4c2e559bab
								
							
						
					
					
						commit
						472a6da5a6
					
				| @ -2,7 +2,8 @@ | |||||||
|     "name": "multi-downloader-client", |     "name": "multi-downloader-client", | ||||||
|     "image": "rg.fr-par.scw.cloud/kubernetes/devcontainer:php-8.3", |     "image": "rg.fr-par.scw.cloud/kubernetes/devcontainer:php-8.3", | ||||||
|     "containerEnv": { |     "containerEnv": { | ||||||
|         "MULTI_DOWNLOADER_API_KEY": "YOUR_API_KEY" |         "MULTI_DOWNLOADER_API_KEY": "YOUR_API_KEY", | ||||||
|  |         "MULTI_DOWNLOADER_URL": "https://multi-dl.kub.nwb.fr" | ||||||
|     }, |     }, | ||||||
|     "customizations": { |     "customizations": { | ||||||
|         "vscode": { |         "vscode": { | ||||||
|  | |||||||
							
								
								
									
										54
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								README.md
									
									
									
									
									
								
							| @ -1,10 +1,8 @@ | |||||||
| # multi-downloader-client | # multi-downloader-client | ||||||
| 
 | 
 | ||||||
| ## Utilisation |  | ||||||
| 
 |  | ||||||
| ## Installation | ## Installation | ||||||
| ### Composer | 
 | ||||||
| Ajouter les modules communs dans composer.json | Add repository in composer.json | ||||||
| ```json | ```json | ||||||
| { | { | ||||||
|     "repositories": [{ |     "repositories": [{ | ||||||
| @ -14,7 +12,53 @@ Ajouter les modules communs dans composer.json | |||||||
|     ] |     ] | ||||||
| } | } | ||||||
| ``` | ``` | ||||||
| Lancer la commande | Then run composer require | ||||||
| ```bash | ```bash | ||||||
| composer require nwb/multi-downloader-client | composer require nwb/multi-downloader-client | ||||||
| ``` | ``` | ||||||
|  | 
 | ||||||
|  | ## Env | ||||||
|  | The following env variables are used by default | ||||||
|  | ```dotenv | ||||||
|  | MULTI_DOWNLOADER_API_KEY | ||||||
|  | MULTI_DOWNLOADER_URL | ||||||
|  | ``` | ||||||
|  | They can be overriden in the constructor | ||||||
|  | ```php | ||||||
|  | use Nwb\MultiDownloaderClient\MultiDownloaderClient; | ||||||
|  | 
 | ||||||
|  | $client = new MultiDownloaderClient([ | ||||||
|  |     'apiKey' => '', | ||||||
|  |     'url' => '', | ||||||
|  | ]) | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | ## Usage | ||||||
|  | 
 | ||||||
|  | Ajouter des fichiers | ||||||
|  | ```php | ||||||
|  | use Nwb\MultiDownloaderClient\MultiDownloaderClient; | ||||||
|  | use Nwb\MultiDownloaderClient\FileRequest; | ||||||
|  | 
 | ||||||
|  | $client = new MultiDownloaderClient(); | ||||||
|  | 
 | ||||||
|  | $client->addFiles([ | ||||||
|  |     new FileRequest('http://example.com/image.png') | ||||||
|  |     new FileRequest('http://example.com/image1.png') | ||||||
|  | ]); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Get zip as string | ||||||
|  | ```php | ||||||
|  | $zip = $client->downloadAsString(); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Save zip to file (stream) | ||||||
|  | ```php | ||||||
|  | $client->downloadTo('/tmp/my-zip.zip'); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Get html form | ||||||
|  | ```php | ||||||
|  | $form = $client->htmlForm(); | ||||||
|  | ``` | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ namespace Nwb\MultiDownloaderClient; | |||||||
| 
 | 
 | ||||||
| class MultiDownloaderClient | class MultiDownloaderClient | ||||||
| { | { | ||||||
|     private string $apiUrl = 'https://multi-dl.kub.nwb.fr'; |     private string $url; | ||||||
|     private string $apiKey; |     private string $apiKey; | ||||||
| 
 | 
 | ||||||
|     private array $files = []; |     private array $files = []; | ||||||
| @ -19,9 +19,13 @@ class MultiDownloaderClient | |||||||
| 
 | 
 | ||||||
|         $this->apiKey = $apiKey; |         $this->apiKey = $apiKey; | ||||||
| 
 | 
 | ||||||
|         if (!empty($options['apiUrl'])) { |         $url = $options['url'] ?? getenv('MULTI_DOWNLOADER_URL'); | ||||||
|             $this->apiUrl = $options['apiUrl']; | 
 | ||||||
|  |         if (!$url) { | ||||||
|  |             throw new \InvalidArgumentException('API URL is required'); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         $this->url = $url; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function setFiles(array $files) |     public function setFiles(array $files) | ||||||
| @ -82,7 +86,7 @@ class MultiDownloaderClient | |||||||
|         $ch = curl_init(); |         $ch = curl_init(); | ||||||
| 
 | 
 | ||||||
|         $options = array_replace($options, [ |         $options = array_replace($options, [ | ||||||
|             CURLOPT_URL => $this->apiUrl . '/v2/zip', |             CURLOPT_URL => $this->url . '/v2/zip', | ||||||
|             CURLOPT_RETURNTRANSFER => true, |             CURLOPT_RETURNTRANSFER => true, | ||||||
|             CURLOPT_POST => true, |             CURLOPT_POST => true, | ||||||
|             CURLOPT_POSTFIELDS => json_encode($this->buildRequest()), |             CURLOPT_POSTFIELDS => json_encode($this->buildRequest()), | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ use Nwb\MultiDownloaderClient\MultiDownloaderClient; | |||||||
| 
 | 
 | ||||||
| <body> | <body> | ||||||
|     <div id="button_div" class="modal-dialog-buttons"> |     <div id="button_div" class="modal-dialog-buttons"> | ||||||
|         <form name="f" id="f" method="POST" action="<?= $this->apiUrl ?>/v2/form/zip" enctype="multipart/form-data"> |         <form name="f" id="f" method="POST" action="<?= $this->url ?>/v2/form/zip" enctype="multipart/form-data"> | ||||||
|             <input type="hidden" name="json" value="<?= json_encode($this->buildRequest()) ?>" /> |             <input type="hidden" name="json" value="<?= json_encode($this->buildRequest()) ?>" /> | ||||||
| 
 | 
 | ||||||
|             <noscript> |             <noscript> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user