Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
- replace 404 error with explicit json in some cases
- OPTIONS method hook removed
- other trivial changes
  • Loading branch information
kstefanini committed Apr 29, 2016
1 parent 7bcc607 commit ddae1d8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 43 deletions.
66 changes: 25 additions & 41 deletions CumulusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,15 @@ public function __construct() {
* Renvoie plusieurs résultats $results dans un objet JSON, en remplaçant
* les chemins de stockage par des liens de téléchargement
*/
protected function sendMultipleResults($results, $errorMessage="no results", $errorCode=404) {
if ($results == false) {
$this->sendError($errorMessage, $errorCode);
} else {
// création des liens de téléchargement
$this->buildLinksAndRemoveStoragePaths($results);
$this->sendJson(
array(
"count" => count($results),
"results" => $results
)
);
}
protected function sendMultipleResults($results) {
// création des liens de téléchargement
$this->buildLinksAndRemoveStoragePaths($results);
$this->sendJson(
array(
"count" => count($results),
"results" => $results
)
);
}

/**
Expand Down Expand Up @@ -679,22 +675,27 @@ protected function post() {
$jsonData = json_decode($requestBody, true);

// extraction des paramètres
$file = $this->getParam('file', null, $jsonData);
$newname = $this->getParam('newname', null, $jsonData);
$newpath = $this->getParam('newpath', null, $jsonData);
$keywords = $this->getParam('keywords', null, $jsonData);
$groups = $this->getParam('groups', null, $jsonData);
$permissions = $this->getParam('permissions', null, $jsonData);
$license = $this->getParam('license', null, $jsonData);
$meta = $this->getParam('meta', null, $jsonData);

// détection : fichier ou référence (URL) ?
if (! empty($jsonData['file']) && (preg_match(self::$REF_PATTERN, $jsonData['file']) != false)) {
// référence
$file = array(
'url' => $jsonData['file'],
'size' => count($jsonData['file'])
);
} else {
// copie du contenu base64 dans un fichier temporaire
$file = $this->copyBase64ToTmpFile($jsonData['file']);
if ($file) {
// détection : fichier ou référence (URL) ?
if (! empty($jsonData['file']) && (preg_match(self::$REF_PATTERN, $jsonData['file']) != false)) {
// référence
$file = array(
'url' => $jsonData['file'],
'size' => count($jsonData['file'])
);
} else {
// copie du contenu base64 dans un fichier temporaire
$file = $this->copyBase64ToTmpFile($jsonData['file']);
}
}
} else { // fichier dans le corps de la requête
$file = $this->copyRequestBodyToTmpFile();
Expand Down Expand Up @@ -733,21 +734,4 @@ protected function delete() {
$this->sendJson($info);
}
}

/**
* Renvoie les attributs d'un fichier, mais pas le fichier lui-même
*/
protected function options() {
$key = array_pop($this->resources);

//echo "options : [$key]\n";
$file = $this->lib->getAttributesByKey($key);

if ($file == false) {
$this->sendError("file not found", 404);
} else {
$this->buildLinkAndRemoveStoragePath($file);
$this->sendJson($file);
}
}
}
}
3 changes: 2 additions & 1 deletion adapters/storage/stockagetb/StockageDisque.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function stockerFichier($infosFichier, $cheminDossier, $nomFichier) {
*/
public function renommerFichier($ancienChemin, $ancienNom, $nouveauChemin, $nouveauNom) {
// préparation du dossier de destination
$ancienChemin = $this->preparerCheminDossier($ancienChemin);
$nouveauChemin = $this->preparerCheminDossier($nouveauChemin);

$ancienCheminComplet = $ancienChemin . $ancienNom;
Expand Down Expand Up @@ -157,4 +158,4 @@ protected function desinfecterNomFichier($nom) {

return $nom;
}
}
}
2 changes: 1 addition & 1 deletion adapters/storage/stockagetb/StockageTB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,4 +1015,4 @@ protected function deleteFileReference($key) {
public function getAttributesByKey($key ) {
return $this->getByKey($key);
}
}
}

0 comments on commit ddae1d8

Please sign in to comment.