Permalink
Browse files

Implement File API v2

  • Loading branch information...
1 parent 0a900e9 commit 0ffd5d21ca5bb45c5c3e815d0787958c33cbfb32 @cdujeu cdujeu committed May 18, 2016
Oops, something went wrong.
@@ -46,6 +46,12 @@
</serverCallback>
</processing>
</action>
+ <action name="fs_create_resource">
+ <rightsContext adminOnly="false" noUser="false" read="true" userLogged="true" write="true"/>
+ <processing>
+ <serverCallback methodName="createResourceAction"/>
+ </processing>
+ </action>
<action name="mkdir">
<gui text="154" title="155" src="folder_new.png" iconClass="mdi mdi-folder-plus" accessKey="folder_access_key" hasAccessKey="true">
<context selection="false" dir="true" recycle="hidden" actionBar="true"
@@ -19,6 +19,8 @@
* The latest code can be found at <http://pyd.io/>.
*/
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Filter\ContentFilter;
@@ -372,14 +374,12 @@ protected function toggleWatchOnSharedRepository($childRepoId, $userId, $toggle
/**************************/
/**
* Added as preprocessor on Download action to handle download Counter.
- * @param string $action
- * @param array $httpVars
- * @param array $fileVars
+ * @param ServerRequestInterface $requestInterface
+ * @param ResponseInterface $responseInterface
* @throws Exception
*/
- public function preProcessDownload($action, &$httpVars, &$fileVars){
+ public function preProcessDownload(ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface){
if(isSet($_SESSION["CURRENT_MINISITE"])){
- $this->logDebug(__FUNCTION__, "Do something here!");
$hash = $_SESSION["CURRENT_MINISITE"];
$share = $this->getShareStore()->loadShare($hash);
if(!empty($share)){
@@ -160,8 +160,9 @@ public function crossRepositoryCopy($httpVars)
$errorMessages = array();
foreach ($files as $file) {
+ $destFile = Utils::decodeSecureMagic($httpVars["dest"]) ."/". Utils::safeBasename($file);
$this->copyOrMoveFile(
- \Pydio\Core\Utils\Utils::decodeSecureMagic($httpVars["dest"]),
+ $destFile,
$file, $errorMessages, $messages, isSet($httpVars["moving_files"]) ? true: false,
$srcRepoData, $destRepoData);
@@ -183,18 +184,21 @@ public function crossRepositoryCopy($httpVars)
* @param array $srcRepoData Set of data concerning source repository: base_url, recycle option
* @param array $destRepoData Set of data concerning destination repository: base_url, chmod option
*/
- protected function copyOrMoveFile($destDir, $srcFile, &$error, &$success, $move = false, $srcRepoData = array(), $destRepoData = array())
+ protected function copyOrMoveFile($destFile, $srcFile, &$error, &$success, $move = false, $srcRepoData = array(), $destRepoData = array())
{
$srcUrlBase = $srcRepoData['base_url'];
$srcRecycle = $srcRepoData['recycle'];
$destUrlBase = $destRepoData['base_url'];
$mess = ConfService::getMessages();
+ /*
$bName = basename($srcFile);
$localName = '';
Controller::applyHook("dl.localname", array($srcFile, &$localName));
if(!empty($localName)) $bName = $localName;
- $destFile = $destUrlBase.$destDir."/".$bName;
+ */
+ $destDir = Utils:: safeDirname($destFile);
+ $destFile = $destUrlBase.$destFile;
$realSrcFile = $srcUrlBase.$srcFile;
if (is_dir(dirname($realSrcFile)) && (strpos($destFile, rtrim($realSrcFile, "/") . "/") === 0)) {
@@ -210,12 +214,13 @@ protected function copyOrMoveFile($destDir, $srcFile, &$error, &$success, $move
$size = filesize($realSrcFile);
\Pydio\Core\Controller\Controller::applyHook("node.before_create", array(new AJXP_Node($destFile), $size));
}
- if (dirname($realSrcFile)==dirname($destFile)) {
+ if (dirname($realSrcFile) == dirname($destFile) && basename($realSrcFile) == basename($destFile)) {
if ($move) {
$error[] = $mess[101];
return ;
} else {
$base = basename($srcFile);
+ $ext = "";
if (is_file($realSrcFile)) {
$dotPos = strrpos($base, ".");
if ($dotPos>-1) {
@@ -224,15 +229,16 @@ protected function copyOrMoveFile($destDir, $srcFile, &$error, &$success, $move
}
}
// auto rename file
+ $destDir = Utils::safeDirname($destFile);
$i = 1;
$newName = $base;
- while (file_exists($destUrlBase.$destDir."/".$newName)) {
+ while (file_exists($destDir."/".$newName)) {
$suffix = "-$i";
if(isSet($radic)) $newName = $radic . $suffix . $ext;
else $newName = $base.$suffix;
$i++;
}
- $destFile = $destUrlBase.$destDir."/".$newName;
+ $destFile = $destDir."/".$newName;
}
}
$srcNode = new AJXP_Node($realSrcFile);
@@ -295,9 +301,9 @@ protected function copyOrMoveFile($destDir, $srcFile, &$error, &$success, $move
RecycleBinManager::fileToRecycle($srcFile);
}
if (isSet($dirRes)) {
- $success[] = $mess[117]." ".TextEncoder::toUTF8(basename($srcFile))." ".$mess[73]." ".TextEncoder::toUTF8($destDir)." (".TextEncoder::toUTF8($dirRes)." ".$mess[116].")";
+ $success[] = $mess[117]." ".TextEncoder::toUTF8(basename($destFile))." ".$mess[73]." ".TextEncoder::toUTF8($destDir)." (".TextEncoder::toUTF8($dirRes)." ".$mess[116].")";
} else {
- $success[] = $mess[34]." ". \Pydio\Core\Utils\TextEncoder::toUTF8(basename($srcFile))." ".$mess[73]." ". \Pydio\Core\Utils\TextEncoder::toUTF8($destDir);
+ $success[] = $mess[34]." ". \Pydio\Core\Utils\TextEncoder::toUTF8(basename($destFile))." ".$mess[73]." ". \Pydio\Core\Utils\TextEncoder::toUTF8($destDir);
}
}
@@ -20,6 +20,8 @@
*/
namespace Pydio\Access\Core;
+use Pydio\Access\Core\Model\AJXP_Node;
+
defined('AJXP_EXEC') or die( 'Access not allowed');
/**
@@ -47,10 +49,12 @@ public function mkDir($path, $newDirName);
/**
* Creates an empty file
- * @param String $path
- * @param String $newDirName
+ * @param AJXP_Node $node
+ * @param string $content
+ * @param bool $forceCreation
+ * @return
*/
- public function createEmptyFile($path, $newDirName);
+ public function createEmptyFile(AJXP_Node $node, $content = "", $forceCreation = false);
/**
* @param String $from
@@ -137,6 +137,17 @@ public function initFromArray($array)
}
//return ;
}
+ if (isSet($array["path"])){
+ if(!is_array($array["path"])){
+ $array["path"] = [$array["path"]];
+ }
+ foreach ($array["path"] as $p){
+ $p = Utils::decodeSecureMagic($p);
+ // First part must be the repository ID
+ $p = "/".implode("/", array_slice(explode("/", trim($p, "/")), 1));
+ $this->files[] = $p;
+ }
+ }
if (isSet($array["nodes"]) && is_array($array["nodes"])) {
$this->files = array();
foreach($array["nodes"] as $value){
@@ -21,6 +21,7 @@
namespace Pydio\Access\Core;
use Pydio\Access\Core\Model\UserSelection;
+use Pydio\Core\Utils\Utils;
defined('AJXP_EXEC') or die( 'Access not allowed');
/**
@@ -79,34 +80,35 @@ public static function currentLocationIsRecycle($currentLocation)
{
return ($currentLocation == self::$rbmRelativeRecycle);
}
+
/**
* Transform delete/restore actions into move actino
* @static
* @param string $action
* @param UserSelection $selection
* @param string $currentLocation
* @param array $httpVars
- * @return array
*/
- public static function filterActions($action, $selection, $currentLocation, $httpVars = array())
+ public static function filterActions(&$action, $selection, &$httpVars)
{
- if(!self::recycleEnabled()) return array();
- $newArgs = array();
+ if(!self::recycleEnabled() || $selection->isEmpty()) {
+ return;
+ }
+ $currentLocation = Utils::safeDirname($selection->getUniqueFile());
// FILTER ACTION FOR DELETE
if ($action == "delete" && !self::currentLocationIsRecycle($currentLocation) && !isSet($httpVars["force_deletion"])) {
- $newArgs["action"] = "move";
- $newArgs["dest"] = self::$rbmRelativeRecycle;
+ $action = "move";
+ $httpVars["dest"] = self::$rbmRelativeRecycle;
}
// FILTER ACTION FOR RESTORE
if ($action == "restore" && self::currentLocationIsRecycle($currentLocation)) {
$originalRep = self::getFileOrigin($selection->getUniqueFile());
if ($originalRep != "") {
- $newArgs["action"] = "move";
- $newArgs["dest"] = $originalRep; // CHECK UTF8 HANDLING HERE
+ $action = "move";
+ $httpVars["dest"] = $originalRep; // CHECK UTF8 HANDLING HERE
}
}
- return $newArgs;
}
/**
@@ -71,7 +71,7 @@ protected function initDirAndSelection($httpVars, $additionnalPathes = array(),
$recycle = $repo->getOption("RECYCLE_BIN");
if ($recycle != "") {
RecycleBinManager::init($urlBase, "/".$recycle);
- $result["RECYCLE"] = RecycleBinManager::filterActions($httpVars["get_action"], $userSelection, $httpVars["dir"], $httpVars);
+ $result["RECYCLE"] = RecycleBinManager::filterActions($httpVars["get_action"], $userSelection, $httpVars);
// if necessary, check recycle was checked.
// We could use a hook instead here? Maybe the full recycle system
// could be turned into a plugin
@@ -96,7 +96,7 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
public function postProcess(\Psr\Http\Message\ServerRequestInterface &$request, \Psr\Http\Message\ResponseInterface &$response)
{
$httpVars = $request->getParsedBody();
- if (!isSet($httpVars["simple_uploader"]) && !isSet($httpVars["xhr_uploader"]) && !isSet($httpVars["force_post"])) {
+ if ($request->getAttribute("api")!="v2" && !isSet($httpVars["simple_uploader"]) && !isSet($httpVars["xhr_uploader"]) && !isSet($httpVars["force_post"])) {
return;
}
$this->logDebug("SimpleUploadProc is active");
@@ -51,7 +51,7 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
{
$httpVars = $request->getParsedBody();
- if(isSet($httpVars["simple_uploader"]) || isset($httpVars["xhr_uploader"]) || isSet($httpVars["Filename"])){
+ if(!count($request->getUploadedFiles()) || isSet($httpVars["simple_uploader"]) || isset($httpVars["xhr_uploader"]) || isSet($httpVars["Filename"])){
return;
}
$repository = ConfService::getRepository();

0 comments on commit 0ffd5d2

Please sign in to comment.