3535use OCP \AppFramework \Http \Attribute \UserRateLimit ;
3636use OCP \AppFramework \Http \DataDownloadResponse ;
3737use OCP \AppFramework \Http \DataResponse ;
38- use OCP \Common \Exception \NotFoundException ;
3938use OCP \Files \File ;
40- use OCP \Files \GenericFileException ;
4139use OCP \Files \IRootFolder ;
42- use OCP \Files \NotPermittedException ;
4340use OCP \IL10N ;
4441use OCP \IRequest ;
45- use OCP \Lock \LockedException ;
4642use OCP \TaskProcessing \EShapeType ;
4743use OCP \TaskProcessing \Exception \Exception ;
4844use OCP \TaskProcessing \Exception \UnauthorizedException ;
@@ -67,7 +63,7 @@ public function __construct(
6763 }
6864
6965 /**
70- * This endpoint returns all available TaskProcessing task types
66+ * Returns all available TaskProcessing task types
7167 *
7268 * @return DataResponse<Http::STATUS_OK, array{types: array<string, CoreTaskProcessingTaskType>}, array{}>
7369 *
@@ -100,7 +96,7 @@ public function taskTypes(): DataResponse {
10096 }
10197
10298 /**
103- * This endpoint allows scheduling a task
99+ * Schedules a task
104100 *
105101 * @param array<string, mixed> $input Task's input parameters
106102 * @param string $type Type of the task
@@ -141,7 +137,8 @@ public function schedule(array $input, string $type, string $appId, string $cust
141137 }
142138
143139 /**
144- * This endpoint allows checking the status and results of a task.
140+ * Gets a task including status and result
141+ *
145142 * Tasks are removed 1 week after receiving their last update
146143 *
147144 * @param int $id The id of the task
@@ -163,21 +160,21 @@ public function getTask(int $id): DataResponse {
163160 return new DataResponse ([
164161 'task ' => $ json ,
165162 ]);
166- } catch (NotFoundException $ e ) {
163+ } catch (\ OCP \ TaskProcessing \ Exception \ NotFoundException $ e ) {
167164 return new DataResponse (['message ' => $ this ->l ->t ('Task not found ' )], Http::STATUS_NOT_FOUND );
168165 } catch (\RuntimeException $ e ) {
169166 return new DataResponse (['message ' => $ this ->l ->t ('Internal error ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
170167 }
171168 }
172169
173170 /**
174- * This endpoint allows to delete a scheduled task for a user
171+ * Deletes a task
175172 *
176173 * @param int $id The id of the task
177174 *
178175 * @return DataResponse<Http::STATUS_OK, null, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
179176 *
180- * 200: Task returned
177+ * 200: Task deleted
181178 */
182179 #[NoAdminRequired]
183180 #[ApiRoute(verb: 'DELETE ' , url: '/task/{id} ' , root: '/taskprocessing ' )]
@@ -197,14 +194,13 @@ public function deleteTask(int $id): DataResponse {
197194
198195
199196 /**
200- * This endpoint returns a list of tasks of a user that are related
201- * with a specific appId and optionally with an identifier
197+ * Returns tasks for the current user filtered by the appId and optional customId
202198 *
203199 * @param string $appId ID of the app
204200 * @param string|null $customId An arbitrary identifier for the task
205201 * @return DataResponse<Http::STATUS_OK, array{tasks: CoreTaskProcessingTask[]}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
206202 *
207- * 200: Task list returned
203+ * 200: Tasks returned
208204 */
209205 #[NoAdminRequired]
210206 #[ApiRoute(verb: 'GET ' , url: '/tasks/app/{appId} ' , root: '/taskprocessing ' )]
@@ -221,24 +217,21 @@ public function listTasksByApp(string $appId, ?string $customId = null): DataRes
221217 ]);
222218 } catch (Exception $ e ) {
223219 return new DataResponse (['message ' => $ this ->l ->t ('Internal error ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
224- } catch (\JsonException $ e ) {
225- return new DataResponse (['message ' => $ this ->l ->t ('Internal error ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
226220 }
227221 }
228222
229223 /**
230- * This endpoint returns a list of tasks of a user that are related
231- * with a specific appId and optionally with an identifier
224+ * Returns tasks for the current user filtered by the optional taskType and optional customId
232225 *
233226 * @param string|null $taskType The task type to filter by
234227 * @param string|null $customId An arbitrary identifier for the task
235228 * @return DataResponse<Http::STATUS_OK, array{tasks: CoreTaskProcessingTask[]}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
236229 *
237- * 200: Task list returned
230+ * 200: Tasks returned
238231 */
239232 #[NoAdminRequired]
240233 #[ApiRoute(verb: 'GET ' , url: '/tasks ' , root: '/taskprocessing ' )]
241- public function listTasksByUser (?string $ taskType , ?string $ customId = null ): DataResponse {
234+ public function listTasks (?string $ taskType , ?string $ customId = null ): DataResponse {
242235 try {
243236 $ tasks = $ this ->taskProcessingManager ->getUserTasks ($ this ->userId , $ taskType , $ customId );
244237 /** @var CoreTaskProcessingTask[] $json */
@@ -251,13 +244,11 @@ public function listTasksByUser(?string $taskType, ?string $customId = null): Da
251244 ]);
252245 } catch (Exception $ e ) {
253246 return new DataResponse (['message ' => $ this ->l ->t ('Internal error ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
254- } catch (\JsonException $ e ) {
255- return new DataResponse (['message ' => $ this ->l ->t ('Internal error ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
256247 }
257248 }
258249
259250 /**
260- * This endpoint returns the contents of a file referenced in a task
251+ * Returns the contents of a file referenced in a task
261252 *
262253 * @param int $taskId The id of the task
263254 * @param int $fileId The file id of the file to retrieve
@@ -288,7 +279,7 @@ public function getFileContents(int $taskId, int $fileId): Http\DataDownloadResp
288279 return new Http \DataDownloadResponse ($ node ->getContent (), $ node ->getName (), $ node ->getMimeType ());
289280 } catch (\OCP \TaskProcessing \Exception \NotFoundException $ e ) {
290281 return new DataResponse (['message ' => $ this ->l ->t ('Not found ' )], Http::STATUS_NOT_FOUND );
291- } catch (GenericFileException | NotPermittedException | LockedException | Exception $ e ) {
282+ } catch (Exception $ e ) {
292283 return new DataResponse (['message ' => $ this ->l ->t ('Internal error ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
293284 }
294285 }
@@ -333,13 +324,13 @@ private function extractFileIdsFromTask(Task $task): array {
333324 }
334325
335326 /**
336- * This endpoint sets the task progress
327+ * Sets the task progress
337328 *
338329 * @param int $taskId The id of the task
339330 * @param float $progress The progress
340331 * @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
341332 *
342- * 200: File content returned
333+ * 200: Progress updated successfully
343334 * 404: Task not found
344335 */
345336 #[NoAdminRequired]
@@ -363,14 +354,14 @@ public function setProgress(int $taskId, float $progress): DataResponse {
363354 }
364355
365356 /**
366- * This endpoint sets the task progress
357+ * Sets the task result
367358 *
368359 * @param int $taskId The id of the task
369360 * @param array<string,mixed>|null $output The resulting task output
370361 * @param string|null $errorMessage An error message if the task failed
371362 * @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
372363 *
373- * 200: File content returned
364+ * 200: Result updated successfully
374365 * 404: Task not found
375366 */
376367 #[NoAdminRequired]
@@ -397,12 +388,12 @@ public function setResult(int $taskId, ?array $output = null, ?string $errorMess
397388 }
398389
399390 /**
400- * This endpoint cancels a task
391+ * Cancels a task
401392 *
402393 * @param int $taskId The id of the task
403394 * @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
404395 *
405- * 200: File content returned
396+ * 200: Task canceled successfully
406397 * 404: Task not found
407398 */
408399 #[NoAdminRequired]
0 commit comments