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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@
"description": "If it's a move/rename, will remove original after copy operation", "description": "If it's a move/rename, will remove original after copy operation",
"required": false, "required": false,
"type": "boolean" "type": "boolean"
},
{
"name": "override",
"in": "query",
"description": "Ignore existing resource and override it",
"required": false,
"type": "boolean",
"default": false
} }
], ],
"produces": [ "produces": [
Expand All @@ -170,7 +178,7 @@
"patch": { "patch": {
"x-pydio-plugin": "access.fs", "x-pydio-plugin": "access.fs",
"x-pydio-action": "fs_update_metadata", "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", "operationId": "updateNode",
"parameters": [ "parameters": [
{ {
Expand Down Expand Up @@ -231,7 +239,7 @@
"get": { "get": {
"x-pydio-plugin": "access.fs", "x-pydio-plugin": "access.fs",
"x-pydio-action": "download", "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", "operationId": "download",
"parameters": [ "parameters": [
{ {
Expand All @@ -247,7 +255,7 @@
{ {
"name": "additional_parameters", "name": "additional_parameters",
"in": "query", "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", "type": "string",
"required": false "required": false
} }
Expand Down Expand Up @@ -311,7 +319,7 @@
"$ref": "#/parameters/pathParameter" "$ref": "#/parameters/pathParameter"
}, },
{ {
"name": "file", "name": "userfile_0",
"in": "formData", "in": "formData",
"description": "File to upload", "description": "File to upload",
"required": true, "required": true,
Expand Down Expand Up @@ -351,7 +359,7 @@
"type": "boolean" "type": "boolean"
}, },
{ {
"name": "file", "name": "userfile_0",
"in": "formData", "in": "formData",
"description": "File to upload", "description": "File to upload",
"required": true, "required": true,
Expand All @@ -375,7 +383,16 @@
"get": { "get": {
"description": "List tasks currently running on the server (and visible to the current user).\n", "description": "List tasks currently running on the server (and visible to the current user).\n",
"operationId": "listTasks", "operationId": "listTasks",
"x-pydio-plugin": "core.tasks",
"x-pydio-action": "tasks_list",
"parameters": [ "parameters": [
{
"name": "filter",
"in": "formData",
"description": "additional filters for task listing (JSON serialized)",
"type": "string",
"required": false
},
{ {
"$ref": "#/parameters/workspaceIdFormParameter" "$ref": "#/parameters/workspaceIdFormParameter"
}, },
Expand All @@ -387,7 +404,38 @@
"200": { "200": {
"description": "Successful Response", "description": "Successful Response",
"schema": { "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": { "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", "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", "operationId": "createTask",
"x-pydio-plugin": "core.tasks",
"x-pydio-action": "task_create",
"parameters": [ "parameters": [
{ {
"name": "taskName", "name": "taskId",
"in": "query", "in": "path",
"description": "Task to launch on the server", "description": "Task to launch on the server",
"type": "string", "type": "string",
"enum": [
"index",
"purge",
"restore",
"mkdir",
"resync"
],
"required": true "required": true
}, },
{ {
"$ref": "#/parameters/workspaceIdFormParameter" "name": "task",
}, "in": "body",
{ "description": "JSON Task object",
"$ref": "#/parameters/nodeSelectionParameter" "schema": {
"$ref": "#/definitions/Task"
}
} }
], ],
"responses": { "responses": {
Expand All @@ -431,25 +476,53 @@
"tags": [ "tags": [
"Task" "Task"
] ]
} },
}, "patch": {
"/tasks/{taskId}": { "description": "Update a task on the server.\n",
"get": { "operationId": "updateTask",
"description": "Get information about a currently running task Id\n", "x-pydio-plugin": "core.tasks",
"operationId": "getTaskInfo", "x-pydio-action": "task_update",
"parameters": [ "parameters": [
{ {
"name": "taskId", "name": "taskId",
"in": "path", "in": "path",
"description": "Task to monitor on the server", "description": "Task to update on the server",
"type": "string", "type": "string",
"required": true "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": { "responses": {
Expand Down Expand Up @@ -657,6 +730,29 @@
}, },
"description": { "description": {
"type": "string" "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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class ApiRouter
* "cacheOptions" => ["cacheFile" => "path", "cacheDisabled" => true], * "cacheOptions" => ["cacheFile" => "path", "cacheDisabled" => true],
*/ */
private $cacheOptions; private $cacheOptions;
/**
* @var object Will be used as '$this' for triggering the callbacks
*/
private $callbacksContext;



private $v2Base = "/api/v2"; private $v2Base = "/api/v2";
private $v1Base = "/api"; private $v1Base = "/api";
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public static function handleRequest(ServerRequestInterface $request, ResponseIn
} }
$request = $request->withParsedBody($params); $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(); $serverData = $request->getServerParams();
if(Server::$mode == Server::MODE_REST){ if(Server::$mode == Server::MODE_REST){


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

0 comments on commit 9d8753c

Please sign in to comment.