|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* balloon |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copryright (c) 2012-2018 gyselroth GmbH (https://gyselroth.com) |
|
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Balloon\App\Sharelink\Api\v2; |
|
13
|
|
|
|
|
14
|
|
|
use Balloon\App\Api\Controller; |
|
15
|
|
|
use Balloon\App\Sharelink\Sharelink as Share; |
|
16
|
|
|
use Balloon\Filesystem; |
|
17
|
|
|
use Balloon\Filesystem\Node\AttributeDecorator as NodeAttributeDecorator; |
|
18
|
|
|
use Balloon\Server; |
|
19
|
|
|
use Micro\Http\Response; |
|
20
|
|
|
|
|
21
|
|
|
class ShareLink extends Controller |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Sharelink. |
|
25
|
|
|
* |
|
26
|
|
|
* @var Share |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $sharelink; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Filesystem. |
|
32
|
|
|
* |
|
33
|
|
|
* @var Filesystem |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $fs; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Node attribute decorator. |
|
39
|
|
|
* |
|
40
|
|
|
* @var NodeAttributeDecorator |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $node_decorator; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Constructor. |
|
46
|
|
|
* |
|
47
|
|
|
* @param Share $sharelink |
|
48
|
|
|
* @param Server $server |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct(Share $sharelink, Server $server, NodeAttributeDecorator $node_decorator) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->fs = $server->getFilesystem(); |
|
53
|
|
|
$this->sharelink = $sharelink; |
|
54
|
|
|
$this->node_decorator = $node_decorator; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @api {post} /api/v2/nodes/:id/share-link Create share link |
|
59
|
|
|
* @apiVersion 2.0.0 |
|
60
|
|
|
* @apiName postShareLink |
|
61
|
|
|
* @apiGroup Node |
|
62
|
|
|
* @apiPermission none |
|
63
|
|
|
* @apiDescription Create a unique sharing link of a node (global accessible): |
|
64
|
|
|
* a possible existing link will be deleted if this method will be called. |
|
65
|
|
|
* @apiUse _getNode |
|
66
|
|
|
* @apiUse _writeAction |
|
67
|
|
|
* |
|
68
|
|
|
* @apiParam (POST Parameter) {object} [options] Sharing options |
|
69
|
|
|
* @apiParam (POST Parameter) {number} [options.expiration] Expiration unix timestamp of the sharing link |
|
70
|
|
|
* @apiParam (POST Parameter) {string} [options.password] Protected shared link with password |
|
71
|
|
|
* |
|
72
|
|
|
* @apiExample (cURL) example: |
|
73
|
|
|
* curl -XPOST "https://SERVER/api/v2/node/share-link?id=544627ed3c58891f058b4686&pretty" |
|
74
|
|
|
* curl -XPOST "https://SERVER/api/v2/node/544627ed3c58891f058b4686/share-link?pretty" |
|
75
|
|
|
* curl -XPOST "https://SERVER/api/v2/node/share-link?p=/absolute/path/to/my/node&pretty" |
|
76
|
|
|
* |
|
77
|
|
|
* @apiSuccessExample {json} Success-Response (Created or modified share link): |
|
78
|
|
|
* HTTP/1.1 200 OK |
|
79
|
|
|
* { |
|
80
|
|
|
* "id": "544627ed3c58891f058b4686" |
|
81
|
|
|
* } |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $id |
|
84
|
|
|
* @param string $p |
|
85
|
|
|
* @param array $options |
|
86
|
|
|
* |
|
87
|
|
|
* @return Response |
|
88
|
|
|
*/ |
|
89
|
|
|
public function post(?string $id = null, ?string $p = null, array $options = []): Response |
|
90
|
|
|
{ |
|
91
|
|
|
$node = $this->fs->getNode($id, $p); |
|
92
|
|
|
$options['shared'] = true; |
|
93
|
|
|
|
|
94
|
|
|
$this->sharelink->shareLink($node, $options); |
|
95
|
|
|
$result = $this->node_decorator->decorate($node); |
|
96
|
|
|
|
|
97
|
|
|
return (new Response())->setCode(200)->setBody($result); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @api {delete} /api/v2/nodes/:id/share-link Delete share link |
|
102
|
|
|
* @apiVersion 2.0.0 |
|
103
|
|
|
* @apiName deleteShareLink |
|
104
|
|
|
* @apiGroup Node |
|
105
|
|
|
* @apiPermission none |
|
106
|
|
|
* @apiDescription Delete an existing sharing link |
|
107
|
|
|
* @apiUse _getNode |
|
108
|
|
|
* @apiUse _writeAction |
|
109
|
|
|
* |
|
110
|
|
|
* @apiExample (cURL) example: |
|
111
|
|
|
* curl -XDELETE "https://SERVER/api/v2/node/share-link?id=544627ed3c58891f058b4686?pretty" |
|
112
|
|
|
* |
|
113
|
|
|
* @apiSuccessExample {json} Success-Response: |
|
114
|
|
|
* HTTP/1.1 204 No Content |
|
115
|
|
|
* |
|
116
|
|
|
* @param string $id |
|
117
|
|
|
* @param string $p |
|
118
|
|
|
* |
|
119
|
|
|
* @return Response |
|
120
|
|
|
*/ |
|
121
|
|
|
public function delete(?string $id = null, ?string $p = null): Response |
|
122
|
|
|
{ |
|
123
|
|
|
$node = $this->fs->getNode($id, $p); |
|
124
|
|
|
$options = ['shared' => false]; |
|
125
|
|
|
|
|
126
|
|
|
$this->sharelink->shareLink($node, $options); |
|
127
|
|
|
|
|
128
|
|
|
return (new Response())->setCode(204); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|