debut logique pour post sur la route
This commit is contained in:
parent
5a6990faa1
commit
b78154c582
@ -2,6 +2,7 @@
|
||||
return [
|
||||
'routes' => [
|
||||
['name' => 'page#main', 'url' => '/', 'verb' => 'GET'],
|
||||
['name' => 'page#post', 'url' => '/post', 'verb' => 'POST'],
|
||||
['name' => 'page#zipDrop', 'url' => '/zipDrop', 'verb' => 'GET'],
|
||||
['name' => 'page#getZipFile', 'url' => '/getZipFile', 'verb' => 'POST']
|
||||
]
|
||||
];
|
||||
|
@ -33,15 +33,73 @@ class PageController extends Controller {
|
||||
|
||||
#[NoCSRFRequired]
|
||||
#[NoAdminRequired]
|
||||
#[FrontpageRoute(verb: 'POST', url: '/zipDeposit')]
|
||||
public function post($archiveUrl, $token) {
|
||||
$request = $this->request;
|
||||
$parameters = array('archiveUrl' => $archiveUrl, 'token' => $token);
|
||||
|
||||
return new TemplateResponse(
|
||||
#[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(
|
||||
Application::APP_ID,
|
||||
'index',
|
||||
$parameters
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
<!-- Première section -->
|
||||
<div
|
||||
class="w-full sm:w-1/3 max-sm:h-2/5 p-4 sm:m-6 sm:mr-0 rounded-xl dark:bg-NcBlack/40 bg-white/80">
|
||||
<WebContentViewer :translate="translate" @zip-upload="handleZipUpload" @file-upload="handleFileUpload" @dragEnded="toggleDragEnded" zipUrl="http://localhost:8000/dummyZip.zip"/>
|
||||
<WebContentViewer :translate="translate" @zip-upload="handleZipUpload" @file-upload="handleFileUpload" @dragEnded="toggleDragEnded" :zipUrl="zipUrl"/>
|
||||
</div>
|
||||
<!-- Deuxième section -->
|
||||
<div
|
||||
@ -38,7 +38,11 @@ export default {
|
||||
WebContentViewer
|
||||
},
|
||||
data() {
|
||||
console.log('feur')
|
||||
let zipUrl = document.getElementById('archiveInfos').getAttribute('dataarchiveurl');
|
||||
console.log(zipUrl)
|
||||
return {
|
||||
zipUrl,
|
||||
sharedFile: null,
|
||||
zip: null,
|
||||
dragEnded: false,
|
||||
|
@ -166,7 +166,20 @@ export default {
|
||||
methods: {
|
||||
async loadZipContent() {
|
||||
try {
|
||||
const response = await fetch(this.zipUrl);
|
||||
var baseUrl = OC.generateUrl('/apps/webtransfer/getZipFile');
|
||||
var postData = {
|
||||
subUrl: this.zipUrl
|
||||
};
|
||||
|
||||
let response = await fetch(baseUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json' // Type de contenu JSON
|
||||
},
|
||||
body: JSON.stringify(postData) // Convertir les données en JSON
|
||||
})
|
||||
|
||||
console.log('response: ', await response.json())
|
||||
const zipData = await response.blob();
|
||||
this.zipName = this.zipUrl.split('/').pop();
|
||||
const zip = await JSZip.loadAsync(zipData);
|
||||
|
@ -7,14 +7,12 @@ use OCP\Util;
|
||||
Util::addScript(OCA\WebTransfer\AppInfo\Application::APP_ID, 'main');
|
||||
|
||||
$archiveUrl = isset($_['archiveUrl']) ? $_['archiveUrl'] : ''; // Valeur par défaut vide si non définie
|
||||
$token = isset($_['token']) ? $_['token'] : ''; // Valeur par défaut vide si non définie
|
||||
?>
|
||||
|
||||
<div id="webtransfer">
|
||||
</div>
|
||||
|
||||
<div id="archiveInfos"
|
||||
data-archive-url="<?php echo htmlspecialchars($archiveUrl); ?>"
|
||||
data-token="<?php echo htmlspecialchars($token); ?>"
|
||||
dataarchiveurl="<?php echo htmlspecialchars($archiveUrl); ?>"
|
||||
>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user