2929use InvalidArgumentException ;
3030use OCA \Core \ResponseDefinitions ;
3131use OCP \AppFramework \Http ;
32+ use OCP \AppFramework \Http \Attribute \AnonRateLimit ;
33+ use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
34+ use OCP \AppFramework \Http \Attribute \PublicPage ;
35+ use OCP \AppFramework \Http \Attribute \UserRateLimit ;
3236use OCP \AppFramework \Http \DataResponse ;
3337use OCP \Common \Exception \NotFoundException ;
3438use OCP \IL10N ;
4751 */
4852class TextProcessingApiController extends \OCP \AppFramework \OCSController {
4953 public function __construct (
50- string $ appName ,
51- IRequest $ request ,
52- private IManager $ languageModelManager ,
53- private IL10N $ l ,
54- private ?string $ userId ,
54+ string $ appName ,
55+ IRequest $ request ,
56+ private IManager $ textProcessingManager ,
57+ private IL10N $ l ,
58+ private ?string $ userId ,
5559 private ContainerInterface $ container ,
56- private LoggerInterface $ logger ,
60+ private LoggerInterface $ logger ,
5761 ) {
5862 parent ::__construct ($ appName , $ request );
5963 }
6064
6165 /**
6266 * This endpoint returns all available LanguageModel task types
6367 *
64- * @PublicPage
65- *
6668 * @return DataResponse<Http::STATUS_OK, array{types: array{id: string, name: string, description: string}[]}, array{}>
6769 */
70+ #[PublicPage]
6871 public function taskTypes (): DataResponse {
69- $ typeClasses = $ this ->languageModelManager ->getAvailableTaskTypes ();
72+ $ typeClasses = $ this ->textProcessingManager ->getAvailableTaskTypes ();
7073 $ types = [];
7174 /** @var string $typeClass */
7275 foreach ($ typeClasses as $ typeClass ) {
@@ -92,10 +95,6 @@ public function taskTypes(): DataResponse {
9295 /**
9396 * This endpoint allows scheduling a language model task
9497 *
95- * @PublicPage
96- * @UserRateThrottle(limit=20, period=120)
97- * @AnonRateThrottle(limit=5, period=120)
98- *
9998 * @param string $input Input text
10099 * @param string $type Type of the task
101100 * @param string $appId ID of the app that will execute the task
@@ -107,14 +106,17 @@ public function taskTypes(): DataResponse {
107106 * 400: Scheduling task is not possible
108107 * 412: Scheduling task is not possible
109108 */
109+ #[PublicPage]
110+ #[UserRateLimit(limit: 20 , period: 120 )]
111+ #[AnonRateLimit(limit: 5 , period: 120 )]
110112 public function schedule (string $ input , string $ type , string $ appId , string $ identifier = '' ): DataResponse {
111113 try {
112114 $ task = new Task ($ type , $ input , $ appId , $ this ->userId , $ identifier );
113115 } catch (InvalidArgumentException ) {
114116 return new DataResponse (['message ' => $ this ->l ->t ('Requested task type does not exist ' )], Http::STATUS_BAD_REQUEST );
115117 }
116118 try {
117- $ this ->languageModelManager ->scheduleTask ($ task );
119+ $ this ->textProcessingManager ->scheduleTask ($ task );
118120
119121 $ json = $ task ->jsonSerialize ();
120122
@@ -130,21 +132,17 @@ public function schedule(string $input, string $type, string $appId, string $ide
130132 * This endpoint allows checking the status and results of a task.
131133 * Tasks are removed 1 week after receiving their last update.
132134 *
133- * @PublicPage
134135 * @param int $id The id of the task
135136 *
136137 * @return DataResponse<Http::STATUS_OK, array{task: CoreTextProcessingTask}, array{}>|DataResponse<Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
137138 *
138139 * 200: Task returned
139140 * 404: Task not found
140141 */
142+ #[PublicPage]
141143 public function getTask (int $ id ): DataResponse {
142144 try {
143- $ task = $ this ->languageModelManager ->getTask ($ id );
144-
145- if ($ this ->userId !== $ task ->getUserId ()) {
146- return new DataResponse (['message ' => $ this ->l ->t ('Task not found ' )], Http::STATUS_NOT_FOUND );
147- }
145+ $ task = $ this ->textProcessingManager ->getUserTask ($ id , $ this ->userId );
148146
149147 $ json = $ task ->jsonSerialize ();
150148
@@ -159,25 +157,19 @@ public function getTask(int $id): DataResponse {
159157 }
160158
161159 /**
162- * This endpoint returns a list of tasks related with a specific appId and identifier
163- *
164- * @PublicPage
165- * @UserRateThrottle(limit=20, period=120)
160+ * This endpoint returns a list of tasks of a user that are related
161+ * with a specific appId and optionally with an identifier
166162 *
167163 * @param string $appId
168164 * @param string|null $identifier
169165 * @return DataResponse<Http::STATUS_OK, array{tasks: array{CoreTextProcessingTask}}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
170166 *
171167 * 200: Task list returned
172168 */
169+ #[NoAdminRequired]
173170 public function listTasksByApp (string $ appId , ?string $ identifier = null ): DataResponse {
174- if ($ this ->userId === null ) {
175- return new DataResponse ([
176- 'tasks ' => [],
177- ]);
178- }
179171 try {
180- $ tasks = $ this ->languageModelManager -> getTasksByApp ($ this ->userId , $ appId , $ identifier );
172+ $ tasks = $ this ->textProcessingManager -> getUserTasksByApp ($ this ->userId , $ appId , $ identifier );
181173 $ json = array_map (static function (Task $ task ) {
182174 return $ task ->jsonSerialize ();
183175 }, $ tasks );
0 commit comments