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

Commit

Permalink
Api updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed May 18, 2016
1 parent 2d8fdc4 commit 9d8753c
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 46 deletions.
154 changes: 125 additions & 29 deletions core/src/core/doc/api2.json
Expand Up @@ -149,6 +149,14 @@
"description": "If it's a move/rename, will remove original after copy operation",
"required": false,
"type": "boolean"
},
{
"name": "override",
"in": "query",
"description": "Ignore existing resource and override it",
"required": false,
"type": "boolean",
"default": false
}
],
"produces": [
Expand All @@ -170,7 +178,7 @@
"patch": {
"x-pydio-plugin": "access.fs",
"x-pydio-action": "fs_update_metadata",
"description": "Update existing resources metadata (see I/O for content modification). Basic metadata is provided\nby core plugins, but they can be extended by other plugins.\nFor example :\n`{\"core\": {\"chmod\": 777}}, {\"user_meta\":[{\"metaName\":\"metaValue\"}]}`\n`{\"bookmarks\":{\"bookmarked\": true}, \"locks\":{\"locked\":true}, \"meta.watch\":{\"watch\":true}}`\netc...\n",
"description": "Update existing resources metadata (see I/O for content modification). Basic metadata is provided by core plugins, but they can be extended by other plugins.\nFor example :\n`{\"core\": {\"chmod\": 777}}, {\"user_meta\":[{\"metaName\":\"metaValue\"}]}`\n`{\"bookmarks\":{\"bookmarked\": true}, \"locks\":{\"locked\":true}, \"meta.watch\":{\"watch\":true}}`\netc...\n",
"operationId": "updateNode",
"parameters": [
{
Expand Down Expand Up @@ -231,7 +239,7 @@
"get": {
"x-pydio-plugin": "access.fs",
"x-pydio-action": "download",
"description": "Get resource content. Depending on the attachment parameter, will try to either trigger a download,\nor send binary stream with appropriate headers.\nDepending on the active plugins, may be able to serve:\n+ Plain text\n+ MP3/Wav Stream\n+ MP4 Stream\n+ On-the-fly generated images\n+ On-the-fly generated thumbnails for images or pdf\n",
"description": "Get resource content. Depending on the attachment parameter, will try to either trigger a download, or send binary stream with appropriate headers. Depending on the active plugins, may be able to serve: + Plain text + MP3/Wav Stream + MP4 Stream + On-the-fly generated images + On-the-fly generated thumbnails for images or pdf\n",
"operationId": "download",
"parameters": [
{
Expand All @@ -247,7 +255,7 @@
{
"name": "additional_parameters",
"in": "query",
"description": "some plugin can take more parameters to send various contents derived from main resource. For example, for images, you can pass get_thumb & dimension",
"description": "some plugin can take more parameters to send various contents\nderived from main resource. For example, for images, you can pass\nget_thumb & dimension\n",
"type": "string",
"required": false
}
Expand Down Expand Up @@ -311,7 +319,7 @@
"$ref": "#/parameters/pathParameter"
},
{
"name": "file",
"name": "userfile_0",
"in": "formData",
"description": "File to upload",
"required": true,
Expand Down Expand Up @@ -351,7 +359,7 @@
"type": "boolean"
},
{
"name": "file",
"name": "userfile_0",
"in": "formData",
"description": "File to upload",
"required": true,
Expand All @@ -375,7 +383,16 @@
"get": {
"description": "List tasks currently running on the server (and visible to the current user).\n",
"operationId": "listTasks",
"x-pydio-plugin": "core.tasks",
"x-pydio-action": "tasks_list",
"parameters": [
{
"name": "filter",
"in": "formData",
"description": "additional filters for task listing (JSON serialized)",
"type": "string",
"required": false
},
{
"$ref": "#/parameters/workspaceIdFormParameter"
},
Expand All @@ -387,7 +404,38 @@
"200": {
"description": "Successful Response",
"schema": {
"$ref": "#/definitions/PydioResponse"
"type": "array",
"items": {
"$ref": "#/definitions/Task"
}
}
}
},
"tags": [
"Task"
]
}
},
"/tasks/{taskId}": {
"get": {
"description": "Get information about a currently running task Id\n",
"operationId": "getTaskInfo",
"x-pydio-plugin": "core.tasks",
"x-pydio-action": "task_info",
"parameters": [
{
"name": "taskId",
"in": "path",
"description": "Task to monitor on the server",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "Successful Response",
"schema": {
"$ref": "#/definitions/Task"
}
}
},
Expand All @@ -398,26 +446,23 @@
"post": {
"description": "Create a task on the server. This will generally trigger a server-side background \"Task\", which ID will be returned in the PydioResponse['tasks'] array\n",
"operationId": "createTask",
"x-pydio-plugin": "core.tasks",
"x-pydio-action": "task_create",
"parameters": [
{
"name": "taskName",
"in": "query",
"name": "taskId",
"in": "path",
"description": "Task to launch on the server",
"type": "string",
"enum": [
"index",
"purge",
"restore",
"mkdir",
"resync"
],
"required": true
},
{
"$ref": "#/parameters/workspaceIdFormParameter"
},
{
"$ref": "#/parameters/nodeSelectionParameter"
"name": "task",
"in": "body",
"description": "JSON Task object",
"schema": {
"$ref": "#/definitions/Task"
}
}
],
"responses": {
Expand All @@ -431,25 +476,53 @@
"tags": [
"Task"
]
}
},
"/tasks/{taskId}": {
"get": {
"description": "Get information about a currently running task Id\n",
"operationId": "getTaskInfo",
},
"patch": {
"description": "Update a task on the server.\n",
"operationId": "updateTask",
"x-pydio-plugin": "core.tasks",
"x-pydio-action": "task_update",
"parameters": [
{
"name": "taskId",
"in": "path",
"description": "Task to monitor on the server",
"description": "Task to update on the server",
"type": "string",
"required": true
},
{
"$ref": "#/parameters/workspaceIdFormParameter"
},
"name": "task",
"in": "body",
"description": "JSON Task object",
"schema": {
"$ref": "#/definitions/Task"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"schema": {
"$ref": "#/definitions/Task"
}
}
},
"tags": [
"Task"
]
},
"delete": {
"description": "Update a task on the server.\n",
"operationId": "deleteTask",
"x-pydio-plugin": "core.tasks",
"x-pydio-action": "task_delete",
"parameters": [
{
"$ref": "#/parameters/nodeSelectionParameter"
"name": "taskId",
"in": "path",
"description": "Task to delete on the server",
"type": "string",
"required": true
}
],
"responses": {
Expand Down Expand Up @@ -657,6 +730,29 @@
},
"description": {
"type": "string"
},
"userId": {
"type": "string"
},
"wsId": {
"type": "string"
},
"actionName": {
"type": "string"
},
"schedule": {
"type": "object",
"properties": {
"scheduleType": {
"type": "string"
},
"scheduleValue": {
"type": "string"
}
}
},
"parameters": {
"type": "object"
}
}
},
Expand Down
5 changes: 0 additions & 5 deletions core/src/core/src/pydio/Core/Http/ApiRouter.php
Expand Up @@ -37,11 +37,6 @@ class ApiRouter
* "cacheOptions" => ["cacheFile" => "path", "cacheDisabled" => true],
*/
private $cacheOptions;
/**
* @var object Will be used as '$this' for triggering the callbacks
*/
private $callbacksContext;


private $v2Base = "/api/v2";
private $v1Base = "/api";
Expand Down
Expand Up @@ -43,6 +43,14 @@ public static function handleRequest(ServerRequestInterface $request, ResponseIn
}
$request = $request->withParsedBody($params);

if(in_array("application/json", $request->getHeader("Content-Type"))){
$body = "".$request->getBody();
$body = json_decode($body, true);
if(is_array($body)){
$request = $request->withParsedBody(array_merge($request->getParsedBody(), ["request_body" => $body]));
}
}

$serverData = $request->getServerParams();
if(Server::$mode == Server::MODE_REST){

Expand Down
36 changes: 24 additions & 12 deletions core/src/core/src/pydio/Core/Http/SimpleRestResourceRouter.php
Expand Up @@ -192,19 +192,31 @@ public static function cast($destination, $sourceObject)
if (is_string($destination)) {
$destination = new $destination();
}
$sourceReflection = new \ReflectionObject($sourceObject);
$destinationReflection = new \ReflectionObject($destination);
$sourceProperties = $sourceReflection->getProperties();
foreach ($sourceProperties as $sourceProperty) {
$sourceProperty->setAccessible(true);
$name = $sourceProperty->getName();
$value = $sourceProperty->getValue($sourceObject);
if ($destinationReflection->hasProperty($name)) {
$propDest = $destinationReflection->getProperty($name);
$propDest->setAccessible(true);
$propDest->setValue($destination,$value);
} else {
$destination->$name = $value;
if(is_object($sourceObject)){
$sourceReflection = new \ReflectionObject($sourceObject);
$sourceProperties = $sourceReflection->getProperties();
foreach ($sourceProperties as $sourceProperty) {
$sourceProperty->setAccessible(true);
$name = $sourceProperty->getName();
$value = $sourceProperty->getValue($sourceObject);
if ($destinationReflection->hasProperty($name)) {
$propDest = $destinationReflection->getProperty($name);
$propDest->setAccessible(true);
$propDest->setValue($destination,$value);
} else {
$destination->$name = $value;
}
}
}else{
foreach($sourceObject as $name => $value){
if ($destinationReflection->hasProperty($name)) {
$propDest = $destinationReflection->getProperty($name);
$propDest->setAccessible(true);
$propDest->setValue($destination,$value);
} else {
$destination->$name = $value;
}
}
}
return $destination;
Expand Down

0 comments on commit 9d8753c

Please sign in to comment.