2024-11-06 15:35:54 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-11-14 17:04:30 +01:00
|
|
|
namespace OCA\WebTransfer\Controller;
|
2024-11-06 15:35:54 +01:00
|
|
|
|
2024-11-14 17:04:30 +01:00
|
|
|
use OCA\WebTransfer\AppInfo\Application;
|
2024-11-06 15:35:54 +01:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
|
|
|
|
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
|
|
|
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
|
|
|
use OCP\AppFramework\Http\Attribute\OpenAPI;
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2024-11-19 14:15:09 +01:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IResponse;
|
2024-11-19 15:29:48 +01:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2024-11-06 15:35:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-suppress UnusedClass
|
|
|
|
*/
|
|
|
|
class PageController extends Controller {
|
|
|
|
#[NoCSRFRequired]
|
|
|
|
#[NoAdminRequired]
|
|
|
|
#[OpenAPI(OpenAPI::SCOPE_IGNORE)]
|
|
|
|
#[FrontpageRoute(verb: 'GET', url: '/')]
|
|
|
|
public function index(): TemplateResponse {
|
|
|
|
return new TemplateResponse(
|
|
|
|
Application::APP_ID,
|
|
|
|
'index',
|
|
|
|
);
|
|
|
|
}
|
2024-11-19 14:15:09 +01:00
|
|
|
|
|
|
|
#[NoCSRFRequired]
|
2024-11-19 15:29:48 +01:00
|
|
|
#[NoAdminRequired]
|
2024-12-04 14:05:11 +01:00
|
|
|
#[OpenAPI(OpenAPI::SCOPE_IGNORE)]
|
|
|
|
#[FrontpageRoute(verb: 'POST', url: '/zipDrop')]
|
|
|
|
public function zipDrop() {
|
|
|
|
$subUrl = $this->request->getParam('subUrl');
|
|
|
|
if (!$subUrl) {
|
|
|
|
return new JSONResponse(['error' => 'subUrl is required'], 400); // Retourner une réponse d'erreur 400 si le paramètre est manquant
|
|
|
|
}
|
|
|
|
|
|
|
|
$parameters = array('archiveUrl' => $subUrl);
|
|
|
|
|
|
|
|
// Créer une réponse basée sur un template
|
|
|
|
$response = new TemplateResponse(
|
2024-11-19 15:42:44 +01:00
|
|
|
Application::APP_ID,
|
|
|
|
'index',
|
|
|
|
$parameters
|
|
|
|
);
|
2024-12-04 14:05:11 +01:00
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[NoCSRFRequired]
|
|
|
|
#[NoAdminRequired]
|
|
|
|
#[OpenAPI(OpenAPI::SCOPE_IGNORE)]
|
|
|
|
#[FrontpageRoute(verb: 'POST', url: '/getZipFile')]
|
|
|
|
public function getZipFile() {
|
|
|
|
// Récupérer les données envoyées dans la requête POST
|
|
|
|
$requestData = $this->request->getParams(); // Accéder aux paramètres envoyés
|
|
|
|
$zipUrl = $requestData['subUrl'] ?? null; // Récupérer 'subUrl' ou null si absent
|
|
|
|
|
|
|
|
// Valider l'URL
|
|
|
|
if (!$zipUrl || filter_var($zipUrl, FILTER_VALIDATE_URL) === false) {
|
|
|
|
return new \OCP\AppFramework\Http\DataResponse(['error' => 'Invalid URL'], 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Utiliser cURL pour récupérer le fichier ZIP à l'URL fournie
|
|
|
|
/*$ch = curl_init($zipUrl);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$fileContent = curl_exec($ch);
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Récupérer le code HTTP
|
|
|
|
curl_close($ch);*/
|
|
|
|
|
|
|
|
// Vérifier si le fichier est récupéré avec succès
|
|
|
|
/*if ($fileContent !== false && $httpCode === 200) {
|
|
|
|
$response = new \OCP\AppFramework\Http\DownloadResponse($fileContent);
|
|
|
|
$response->setContentDisposition('attachment', 'yourfile.zip');
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gérer les erreurs si le fichier ne peut pas être récupéré
|
|
|
|
return new \OCP\AppFramework\Http\DataResponse(['error' => 'File not found'], 404);
|
|
|
|
|
|
|
|
new JSONResponse(['error' => 'subUrl is required'], 400);
|
|
|
|
*/
|
|
|
|
try {
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $zipUrl);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
|
|
|
if (curl_errno($ch)) {
|
|
|
|
return new JSONResponse(['feur' => curl_error($ch)], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new JSONResponse(['feur' => $response], 200);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return new JSONResponse(['feur' => $e->getMessage()], 500);
|
|
|
|
}
|
2024-11-19 14:15:09 +01:00
|
|
|
}
|
2024-11-06 15:35:54 +01:00
|
|
|
}
|