-
-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathInternalBookmarkController.php
More file actions
298 lines (270 loc) Β· 6.93 KB
/
Copy pathInternalBookmarkController.php
File metadata and controls
298 lines (270 loc) Β· 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
/*
* Copyright (c) 2020-2024. The Nextcloud Bookmarks contributors.
*
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
*/
namespace OCA\Bookmarks\Controller;
use Exception;
use OCA\Bookmarks\Exception\UnsupportedOperation;
use OCA\Bookmarks\Service\Authorizer;
use OCA\Bookmarks\Service\BookmarkService;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
class InternalBookmarkController extends ApiController {
/**
* @var BookmarkController
*/
private $publicController;
private $userId;
/**
* @var BookmarkService
*/
private $bookmarks;
public function __construct(
$appName, $request, $userId, BookmarkController $publicController, BookmarkService $bookmarks, Authorizer $authorizer,
) {
parent::__construct($appName, $request);
$this->publicController = $publicController;
$this->userId = $userId;
$this->bookmarks = $bookmarks;
if ($this->userId !== null) {
$authorizer->setUserId($this->userId);
}
$authorizer->setCORS(false);
}
/**
* @param int $page
* @param array $tags
* @param string $conjunction
* @param string $sortby
* @param array $search
* @param int $limit
* @param bool $untagged
* @param int|null $folder
* @param string|null $url
* @param bool|null $unavailable
* @param bool|null $archived
* @param bool|null $duplicated
* @param bool $recursive
* @param bool $deleted
* @return DataResponse
*
* @NoAdminRequired
*/
public function getBookmarks(
$page = 0,
$tags = [],
$conjunction = 'or',
$sortby = '',
$search = [],
$limit = 10,
$untagged = false,
$folder = null,
$url = null,
$unavailable = null,
$archived = null,
$duplicated = null,
bool $recursive = false,
bool $deleted = false,
): DataResponse {
return $this->publicController->getBookmarks($page, $tags, $conjunction, $sortby, $search, $limit, $untagged, $folder, $url, $unavailable, $archived, $duplicated, $recursive, $deleted);
}
/**
* @param string $id
* @return JSONResponse
*
* @NoAdminRequired
*/
public function getSingleBookmark($id): JSONResponse {
return $this->publicController->getSingleBookmark($id);
}
/**
* @param string $url
* @param string|null $title
* @param string $description
* @param array $tags
* @param array $folders
* @param string $target
* @return JSONResponse
*
* @NoAdminRequired
*/
public function newBookmark($url = '', $title = null, $description = null, $tags = null, $folders = [], $target = null): JSONResponse {
return $this->publicController->newBookmark($url, $title, $description, $tags, $folders, $target);
}
/**
* @param int|null $id
* @param string|null $url
* @param string|null $title
* @param string $description
* @param array $tags
* @param array|null $folders
* @param string|null $target
* @return JSONResponse
*
* @NoAdminRequired
*/
public function editBookmark($id = null, $url = null, $title = null, $description = '', $tags = [], $folders = null, $target = null): JSONResponse {
return $this->publicController->editBookmark($id, $url, $title, $description, $tags, $folders, $target);
}
/**
* @param int $id
* @return JSONResponse
*
* @NoAdminRequired
*/
public function deleteBookmark($id = -1): JSONResponse {
return $this->publicController->deleteBookmark($id);
}
/**
* @return DataResponse
*
* @NoAdminRequired
*/
public function deleteAllBookmarks(): DataResponse {
try {
$this->bookmarks->deleteAll($this->userId);
} catch (UnsupportedOperation|DoesNotExistException|MultipleObjectsReturnedException $e) {
return new DataResponse(['status' => 'error', 'data' => ['Internal server error']], Http::STATUS_INTERNAL_SERVER_ERROR);
}
return new DataResponse(['status' => 'success']);
}
/**
*
* @param string $url
* @return JSONResponse
* @NoAdminRequired
*/
public function clickBookmark($url = ''): JSONResponse {
return $this->publicController->clickBookmark($url);
}
/**
* @param int|null $folder
* @return JSONResponse
* @NoAdminRequired
*/
public function importBookmark($folder = null): JSONResponse {
return $this->publicController->importBookmark($folder);
}
/**
*
* @return JSONResponse|\OCA\Bookmarks\ExportResponse
*
* @NoAdminRequired
*/
public function exportBookmark() {
return $this->publicController->exportBookmark();
}
/**
*
* @param int $id The id of the bookmark whose favicon shoudl be returned
*
* @return Http\DataDisplayResponse|Http\NotFoundResponse|Http\RedirectResponse|Http\DataResponse
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @throws Exception
*/
public function getBookmarkImage($id) {
return $this->publicController->getBookmarkImage($id);
}
/**
* @param int $id The id of the bookmark whose image shoudl be returned
*
* @return Http\DataDisplayResponse|Http\NotFoundResponse|Http\RedirectResponse|Http\DataResponse
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @throws Exception
*/
public function getBookmarkFavicon($id) {
return $this->publicController->getBookmarkFavicon($id);
}
/**
*
* @param int $folder
* @return JSONResponse
*
* @NoAdminRequired
*/
public function countBookmarks(int $folder): JSONResponse {
return $this->publicController->countBookmarks($folder);
}
/**
*
* @return JSONResponse
*
* @NoAdminRequired
*/
public function countUnavailable(): JSONResponse {
return $this->publicController->countUnavailable();
}
/**
*
* @return JSONResponse
*
* @NoAdminRequired
*/
public function countArchived(): JSONResponse {
return $this->publicController->countArchived();
}
/**
*
* @return JSONResponse
*
* @NoAdminRequired
*/
public function countDuplicated(): JSONResponse {
return $this->publicController->countDuplicated();
}
/**
* @return JSONResponse
* @NoAdminRequired
*/
public function acquireLock(): JSONResponse {
return $this->publicController->acquireLock();
}
/**
* @return JSONResponse
* @NoAdminRequired
*/
public function releaseLock(): JSONResponse {
return $this->publicController->releaseLock();
}
/**
* @return Http\DataResponse
* @NoAdminRequired
*/
public function getDeletedBookmarks(): DataResponse {
return $this->publicController->getDeletedBookmarks();
}
/**
* @return Http\DataResponse
* @NoAdminRequired
*/
public function countAllClicks(): DataResponse {
return $this->publicController->countAllClicks();
}
/**
* @return Http\DataResponse
* @NoAdminRequired
*/
public function countWithClicks(): DataResponse {
return $this->publicController->countWithClicks();
}
/**
* @return JSONResponse
* @throws \OCA\Bookmarks\Exception\UnauthenticatedError
* @NoAdminRequired
*/
public function countDeleted() {
return $this->publicController->countDeleted();
}
}