readme
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Mathieu 2024-01-11 14:23:45 +00:00
parent 4c2e559bab
commit 472a6da5a6
4 changed files with 60 additions and 11 deletions

View File

@ -2,7 +2,8 @@
"name": "multi-downloader-client",
"image": "rg.fr-par.scw.cloud/kubernetes/devcontainer:php-8.3",
"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": {
"vscode": {

View File

@ -1,10 +1,8 @@
# multi-downloader-client
## Utilisation
## Installation
### Composer
Ajouter les modules communs dans composer.json
Add repository in composer.json
```json
{
"repositories": [{
@ -14,7 +12,53 @@ Ajouter les modules communs dans composer.json
]
}
```
Lancer la commande
Then run composer require
```bash
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();
```

View File

@ -4,7 +4,7 @@ namespace Nwb\MultiDownloaderClient;
class MultiDownloaderClient
{
private string $apiUrl = 'https://multi-dl.kub.nwb.fr';
private string $url;
private string $apiKey;
private array $files = [];
@ -19,9 +19,13 @@ class MultiDownloaderClient
$this->apiKey = $apiKey;
if (!empty($options['apiUrl'])) {
$this->apiUrl = $options['apiUrl'];
$url = $options['url'] ?? getenv('MULTI_DOWNLOADER_URL');
if (!$url) {
throw new \InvalidArgumentException('API URL is required');
}
$this->url = $url;
}
public function setFiles(array $files)
@ -82,7 +86,7 @@ class MultiDownloaderClient
$ch = curl_init();
$options = array_replace($options, [
CURLOPT_URL => $this->apiUrl . '/v2/zip',
CURLOPT_URL => $this->url . '/v2/zip',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($this->buildRequest()),

View File

@ -24,7 +24,7 @@ use Nwb\MultiDownloaderClient\MultiDownloaderClient;
<body>
<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()) ?>" />
<noscript>