| @@ 22-150 (lines=129) @@ | ||
| 19 | use MongoDB\BSON\ObjectId; |
|
| 20 | use Psr\Log\LoggerInterface; |
|
| 21 | ||
| 22 | class Document extends Controller |
|
| 23 | { |
|
| 24 | /** |
|
| 25 | * Server. |
|
| 26 | * |
|
| 27 | * @var Server |
|
| 28 | */ |
|
| 29 | protected $server; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Logger. |
|
| 33 | * |
|
| 34 | * @var LoggerInterface |
|
| 35 | */ |
|
| 36 | protected $logger; |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Constructor. |
|
| 40 | * |
|
| 41 | * @param Server $server |
|
| 42 | * @param LoggerInterface $logger |
|
| 43 | */ |
|
| 44 | public function __construct(Server $server, LoggerInterface $logger) |
|
| 45 | { |
|
| 46 | $this->server = $server; |
|
| 47 | $this->logger = $logger; |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @api {get} /api/v1/office/wopi/document Get document sesssion information |
|
| 52 | * @apiName get |
|
| 53 | * @apiVersion 1.0.0 |
|
| 54 | * @apiGroup App\Office |
|
| 55 | * @apiPermission none |
|
| 56 | * @apiDescription Get document session information including document owner, session user and document size |
|
| 57 | * |
|
| 58 | * @apiParam (GET Parameter) {string} id The document id |
|
| 59 | * @apiParam (GET Parameter) {string} access_token An access token to access the document |
|
| 60 | * |
|
| 61 | * @apiExample (cURL) example: |
|
| 62 | * curl -XGET "https://SERVER/api/v1/office/wopi/document/58a18a4ca271f962af6fdbc4?access_token=aae366363ee743412abb" |
|
| 63 | * |
|
| 64 | * @apiSuccessExample {json} Success-Response: |
|
| 65 | * HTTP/1.1 200 OK |
|
| 66 | * { |
|
| 67 | * [***] |
|
| 68 | * } |
|
| 69 | * |
|
| 70 | * @param ObjectId $id |
|
| 71 | * @param string $access_token |
|
| 72 | * |
|
| 73 | * @return Response |
|
| 74 | */ |
|
| 75 | public function get(ObjectId $id, string $access_token): Response |
|
| 76 | { |
|
| 77 | $session = Member::getByAccessToken($this->server, $this->logger, $id, $access_token); |
|
| 78 | ||
| 79 | return (new Response())->setCode(200)->setBody($session->getAttributes(), true); |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * @api {post} /api/v1/office/wopi/document/contents Save document contents |
|
| 84 | * @apiName postContents |
|
| 85 | * @apiVersion 1.0.0 |
|
| 86 | * @apiGroup App\Office |
|
| 87 | * @apiPermission none |
|
| 88 | * @apiDescription Save document contents |
|
| 89 | * |
|
| 90 | * @apiParam (GET Parameter) {string} id The document id |
|
| 91 | * @apiParam (GET Parameter) {string} access_token An access token to access the document |
|
| 92 | * |
|
| 93 | * @apiExample (cURL) example: |
|
| 94 | * curl -XPOST "https://SERVER/api/v1/office/wopi/document/58a18a4ca271f962af6fdbaa/contents?access_token=aae366363ee743412abb" |
|
| 95 | * |
|
| 96 | * @apiSuccessExample {json} Success-Response: |
|
| 97 | * HTTP/1.1 200 OK |
|
| 98 | * { |
|
| 99 | * "status": 200, |
|
| 100 | * "data": true |
|
| 101 | * } |
|
| 102 | * |
|
| 103 | * @param ObjectId $id |
|
| 104 | * @param string $access_token |
|
| 105 | * |
|
| 106 | * @return Response |
|
| 107 | */ |
|
| 108 | public function postContents(ObjectId $id, string $access_token): Response |
|
| 109 | { |
|
| 110 | $session = Session::getByAccessToken($this->server, $id, $access_token); |
|
| 111 | $node = $session->getDocument()->getNode(); |
|
| 112 | ini_set('auto_detect_line_endings', '1'); |
|
| 113 | $content = fopen('php://input', 'rb'); |
|
| 114 | $result = $node->put($content, false); |
|
| 115 | ||
| 116 | return (new Response())->setCode(200)->setBody($result); |
|
| 117 | } |
|
| 118 | ||
| 119 | /** |
|
| 120 | * @api {get} /api/v1/office/wopi/document/contents Get document contents |
|
| 121 | * @apiName getContents |
|
| 122 | * @apiVersion 1.0.0 |
|
| 123 | * @apiGroup App\Office |
|
| 124 | * @apiPermission none |
|
| 125 | * @apiDescription Get document contents |
|
| 126 | * |
|
| 127 | * @apiParam (GET Parameter) {string} id The document id |
|
| 128 | * @apiParam (GET Parameter) {string} access_token An access token to access the document |
|
| 129 | * |
|
| 130 | * @apiExample (cURL) Exampl: |
|
| 131 | * curl -XGET "https://SERVER/api/v1/office/document/58a18a4ca271f962af6fdbaa/contents?access_token=aae366363ee743412abb" |
|
| 132 | * |
|
| 133 | * @apiSuccessExample {binary} Success-Response: |
|
| 134 | * HTTP/1.1 200 OK |
|
| 135 | * |
|
| 136 | * @param ObjectId $id |
|
| 137 | * @param string $access_token |
|
| 138 | */ |
|
| 139 | public function getContents(ObjectId $id, string $access_token): void |
|
| 140 | { |
|
| 141 | $session = Session::getByAccessToken($this->server, $id, $access_token); |
|
| 142 | $stream = $session->getDocument()->get(); |
|
| 143 | ||
| 144 | while (!feof($stream)) { |
|
| 145 | echo fread($stream, 8192); |
|
| 146 | } |
|
| 147 | ||
| 148 | exit(); |
|
| 149 | } |
|
| 150 | } |
|
| 151 | ||
| @@ 22-150 (lines=129) @@ | ||
| 19 | use MongoDB\BSON\ObjectId; |
|
| 20 | use Psr\Log\LoggerInterface; |
|
| 21 | ||
| 22 | class Document extends Controller |
|
| 23 | { |
|
| 24 | /** |
|
| 25 | * Server. |
|
| 26 | * |
|
| 27 | * @var Server |
|
| 28 | */ |
|
| 29 | protected $server; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Logger. |
|
| 33 | * |
|
| 34 | * @var LoggerInterface |
|
| 35 | */ |
|
| 36 | protected $logger; |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Constructor. |
|
| 40 | * |
|
| 41 | * @param Server $server |
|
| 42 | * @param LoggerInterface $logger |
|
| 43 | */ |
|
| 44 | public function __construct(Server $server, LoggerInterface $logger) |
|
| 45 | { |
|
| 46 | $this->server = $server; |
|
| 47 | $this->logger = $logger; |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @api {get} /api/v2/office/wopi/document Get document sesssion information |
|
| 52 | * @apiName get |
|
| 53 | * @apiVersion 2.0.0 |
|
| 54 | * @apiGroup App\Office |
|
| 55 | * @apiPermission none |
|
| 56 | * @apiDescription Get document session information including document owner, session user and document size |
|
| 57 | * |
|
| 58 | * @apiParam (GET Parameter) {string} id The document id |
|
| 59 | * @apiParam (GET Parameter) {string} access_token An access token to access the document |
|
| 60 | * |
|
| 61 | * @apiExample (cURL) example: |
|
| 62 | * curl -XGET "https://SERVER/api/v2/office/wopi/document/58a18a4ca271f962af6fdbc4?access_token=aae366363ee743412abb" |
|
| 63 | * |
|
| 64 | * @apiSuccessExample {json} Success-Response: |
|
| 65 | * HTTP/1.1 200 OK |
|
| 66 | * { |
|
| 67 | * [***] |
|
| 68 | * } |
|
| 69 | * |
|
| 70 | * @param ObjectId $id |
|
| 71 | * @param string $access_token |
|
| 72 | * |
|
| 73 | * @return Response |
|
| 74 | */ |
|
| 75 | public function get(ObjectId $id, string $access_token): Response |
|
| 76 | { |
|
| 77 | $session = Member::getByAccessToken($this->server, $this->logger, $id, $access_token); |
|
| 78 | ||
| 79 | return (new Response())->setCode(200)->setBody($session->getAttributes(), true); |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * @api {post} /api/v2/office/wopi/document/contents Save document contents |
|
| 84 | * @apiName postContents |
|
| 85 | * @apiVersion 2.0.0 |
|
| 86 | * @apiGroup App\Office |
|
| 87 | * @apiPermission none |
|
| 88 | * @apiDescription Save document contents |
|
| 89 | * |
|
| 90 | * @apiParam (GET Parameter) {string} id The document id |
|
| 91 | * @apiParam (GET Parameter) {string} access_token An access token to access the document |
|
| 92 | * |
|
| 93 | * @apiExample (cURL) example: |
|
| 94 | * curl -XPOST "https://SERVER/api/v2/office/wopi/document/58a18a4ca271f962af6fdbaa/contents?access_token=aae366363ee743412abb" |
|
| 95 | * |
|
| 96 | * @apiSuccessExample {json} Success-Response: |
|
| 97 | * HTTP/1.1 200 OK |
|
| 98 | * { |
|
| 99 | * "status": 200, |
|
| 100 | * "data": true |
|
| 101 | * } |
|
| 102 | * |
|
| 103 | * @param ObjectId $id |
|
| 104 | * @param string $access_token |
|
| 105 | * |
|
| 106 | * @return Response |
|
| 107 | */ |
|
| 108 | public function postContents(ObjectId $id, string $access_token): Response |
|
| 109 | { |
|
| 110 | $session = Session::getByAccessToken($this->server, $id, $access_token); |
|
| 111 | $node = $session->getDocument()->getNode(); |
|
| 112 | ini_set('auto_detect_line_endings', '1'); |
|
| 113 | $content = fopen('php://input', 'rb'); |
|
| 114 | $result = $node->put($content, false); |
|
| 115 | ||
| 116 | return (new Response())->setCode(200)->setBody($result); |
|
| 117 | } |
|
| 118 | ||
| 119 | /** |
|
| 120 | * @api {get} /api/v2/office/wopi/document/contents Get document contents |
|
| 121 | * @apiName getContents |
|
| 122 | * @apiVersion 2.0.0 |
|
| 123 | * @apiGroup App\Office |
|
| 124 | * @apiPermission none |
|
| 125 | * @apiDescription Get document contents |
|
| 126 | * |
|
| 127 | * @apiParam (GET Parameter) {string} id The document id |
|
| 128 | * @apiParam (GET Parameter) {string} access_token An access token to access the document |
|
| 129 | * |
|
| 130 | * @apiExample (cURL) Exampl: |
|
| 131 | * curl -XGET "https://SERVER/api/v2/office/document/58a18a4ca271f962af6fdbaa/contents?access_token=aae366363ee743412abb" |
|
| 132 | * |
|
| 133 | * @apiSuccessExample {binary} Success-Response: |
|
| 134 | * HTTP/1.1 200 OK |
|
| 135 | * |
|
| 136 | * @param ObjectId $id |
|
| 137 | * @param string $access_token |
|
| 138 | */ |
|
| 139 | public function getContents(ObjectId $id, string $access_token): void |
|
| 140 | { |
|
| 141 | $session = Session::getByAccessToken($this->server, $id, $access_token); |
|
| 142 | $stream = $session->getDocument()->get(); |
|
| 143 | ||
| 144 | while (!feof($stream)) { |
|
| 145 | echo fread($stream, 8192); |
|
| 146 | } |
|
| 147 | ||
| 148 | exit(); |
|
| 149 | } |
|
| 150 | } |
|
| 151 | ||