@@ -47,6 +47,32 @@ public function __construct(
47
47
parent ::__construct ($ appName , $ request );
48
48
}
49
49
50
+ /**
51
+ * Get the notification request for a task when it has finished
52
+ *
53
+ * Does not need bruteforce protection since we respond with success anyways
54
+ * as we don't want to keep the front-end waiting.
55
+ * However, we still use rate limiting to prevent timing attacks.
56
+ *
57
+ * @param int $ocpTaskId ID of the target task
58
+ * @return DataResponse<Http::STATUS_OK, array{id: int, ocp_task_id: int, timestamp: int}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{error: string}, array{}>
59
+ * @throws MultipleObjectsReturnedException
60
+ *
61
+ * 200: Task notification request retrieved successfully
62
+ */
63
+ #[NoAdminRequired]
64
+ #[NoCSRFRequired]
65
+ #[AnonRateLimit(limit: 10 , period: 60 )]
66
+ #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT , tags: ['assistant_api ' ])]
67
+ public function getNotifyWhenReady (int $ ocpTaskId ): DataResponse {
68
+ if ($ this ->userId === null ) {
69
+ return new DataResponse (['error ' => $ this ->l10n ->t ('Failed to notify when ready; unknown user ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
70
+ }
71
+
72
+ $ notification = $ this ->assistantService ->getNotifyWhenReady ($ ocpTaskId , $ this ->userId );
73
+ return new DataResponse ($ notification , Http::STATUS_OK );
74
+ }
75
+
50
76
/**
51
77
* Notify when the task has finished
52
78
*
@@ -77,6 +103,36 @@ public function notifyWhenReady(int $ocpTaskId): DataResponse {
77
103
return new DataResponse ('' , Http::STATUS_OK );
78
104
}
79
105
106
+ /**
107
+ * Cancel an existing notification when a task has finished
108
+ *
109
+ * Does not need bruteforce protection since we respond with success anyways
110
+ * as we don't want to keep the front-end waiting.
111
+ * However, we still use rate limiting to prevent timing attacks.
112
+ *
113
+ * @param int $ocpTaskId ID of the target task
114
+ * @return DataResponse<Http::STATUS_OK, '', array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{error: string}, array{}>
115
+ * @throws MultipleObjectsReturnedException
116
+ *
117
+ * 200: Ready notification deleted successfully
118
+ */
119
+ #[NoAdminRequired]
120
+ #[NoCSRFRequired]
121
+ #[AnonRateLimit(limit: 10 , period: 60 )]
122
+ #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT , tags: ['assistant_api ' ])]
123
+ public function cancelNotifyWhenReady (int $ ocpTaskId ): DataResponse {
124
+ if ($ this ->userId === null ) {
125
+ return new DataResponse (['error ' => $ this ->l10n ->t ('Failed to cancel notification; unknown user ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
126
+ }
127
+
128
+ try {
129
+ $ this ->assistantService ->cancelNotifyWhenReady ($ ocpTaskId , $ this ->userId );
130
+ } catch (Exception $ e ) {
131
+ // Ignore
132
+ }
133
+ return new DataResponse ('' , Http::STATUS_OK );
134
+ }
135
+
80
136
/**
81
137
* Get available task types
82
138
*
0 commit comments