Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Implement File API v2
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed May 18, 2016
1 parent 0a900e9 commit 0ffd5d2
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 110 deletions.
289 changes: 207 additions & 82 deletions core/src/plugins/access.fs/class.fsAccessDriver.php

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions core/src/plugins/access.fs/fsActions.xml
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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)){
Expand Down
22 changes: 14 additions & 8 deletions core/src/plugins/core.access/src/AbstractAccessDriver.php
Expand Up @@ -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);

Expand All @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
10 changes: 7 additions & 3 deletions core/src/plugins/core.access/src/IAjxpWrapperProvider.php
Expand Up @@ -20,6 +20,8 @@
*/
namespace Pydio\Access\Core;

use Pydio\Access\Core\Model\AJXP_Node;

defined('AJXP_EXEC') or die( 'Access not allowed');

/**
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions core/src/plugins/core.access/src/Model/UserSelection.php
Expand Up @@ -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){
Expand Down
20 changes: 11 additions & 9 deletions core/src/plugins/core.access/src/RecycleBinManager.php
Expand Up @@ -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');
/**
Expand Down Expand Up @@ -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;

}
/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/meta.svn/class.SvnManager.php
Expand Up @@ -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
Expand Down
Expand Up @@ -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");
Expand Down
Expand Up @@ -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();
Expand Down

0 comments on commit 0ffd5d2

Please sign in to comment.