Skip to content

Commit d5220d6

Browse files
authored
Merge pull request #55776 from nextcloud/fix/text2image-better-attributes
fix(TextToImage): Set better attribute for routes
2 parents 0c1be89 + a5ce35a commit d5220d6

4 files changed

Lines changed: 340 additions & 18 deletions

File tree

core/Controller/TextToImageApiController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use OCP\AppFramework\Http\Attribute\ApiRoute;
1818
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
1919
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
20-
use OCP\AppFramework\Http\Attribute\PublicPage;
2120
use OCP\AppFramework\Http\Attribute\UserRateLimit;
2221
use OCP\AppFramework\Http\DataResponse;
2322
use OCP\AppFramework\Http\FileDisplayResponse;
@@ -54,7 +53,7 @@ public function __construct(
5453
*
5554
* 200: Returns availability status
5655
*/
57-
#[PublicPage]
56+
#[NoAdminRequired]
5857
#[ApiRoute(verb: 'GET', url: '/is_available', root: '/text2image')]
5958
public function isAvailable(): DataResponse {
6059
return new DataResponse([
@@ -75,9 +74,8 @@ public function isAvailable(): DataResponse {
7574
* 200: Task scheduled successfully
7675
* 412: Scheduling task is not possible
7776
*/
78-
#[PublicPage]
77+
#[NoAdminRequired]
7978
#[UserRateLimit(limit: 20, period: 120)]
80-
#[AnonRateLimit(limit: 5, period: 120)]
8179
#[ApiRoute(verb: 'POST', url: '/schedule', root: '/text2image')]
8280
public function schedule(string $input, string $appId, string $identifier = '', int $numberOfImages = 8): DataResponse {
8381
$task = new Task($input, $appId, $numberOfImages, $this->userId, $identifier);
@@ -111,7 +109,7 @@ public function schedule(string $input, string $appId, string $identifier = '',
111109
* 200: Task returned
112110
* 404: Task not found
113111
*/
114-
#[PublicPage]
112+
#[NoAdminRequired]
115113
#[BruteForceProtection(action: 'text2image')]
116114
#[ApiRoute(verb: 'GET', url: '/task/{id}', root: '/text2image')]
117115
public function getTask(int $id): DataResponse {
@@ -143,7 +141,7 @@ public function getTask(int $id): DataResponse {
143141
* 200: Image returned
144142
* 404: Task or image not found
145143
*/
146-
#[PublicPage]
144+
#[NoAdminRequired]
147145
#[BruteForceProtection(action: 'text2image')]
148146
#[ApiRoute(verb: 'GET', url: '/task/{id}/image/{index}', root: '/text2image')]
149147
public function getImage(int $id, int $index): DataResponse|FileDisplayResponse {

core/openapi-full.json

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7253,7 +7253,6 @@
72537253
"text_to_image_api"
72547254
],
72557255
"security": [
7256-
{},
72577256
{
72587257
"bearer_auth": []
72597258
},
@@ -7311,6 +7310,34 @@
73117310
}
73127311
}
73137312
}
7313+
},
7314+
"401": {
7315+
"description": "Current user is not logged in",
7316+
"content": {
7317+
"application/json": {
7318+
"schema": {
7319+
"type": "object",
7320+
"required": [
7321+
"ocs"
7322+
],
7323+
"properties": {
7324+
"ocs": {
7325+
"type": "object",
7326+
"required": [
7327+
"meta",
7328+
"data"
7329+
],
7330+
"properties": {
7331+
"meta": {
7332+
"$ref": "#/components/schemas/OCSMeta"
7333+
},
7334+
"data": {}
7335+
}
7336+
}
7337+
}
7338+
}
7339+
}
7340+
}
73147341
}
73157342
}
73167343
}
@@ -7323,7 +7350,6 @@
73237350
"text_to_image_api"
73247351
],
73257352
"security": [
7326-
{},
73277353
{
73287354
"bearer_auth": []
73297355
},
@@ -7492,6 +7518,34 @@
74927518
}
74937519
}
74947520
}
7521+
},
7522+
"401": {
7523+
"description": "Current user is not logged in",
7524+
"content": {
7525+
"application/json": {
7526+
"schema": {
7527+
"type": "object",
7528+
"required": [
7529+
"ocs"
7530+
],
7531+
"properties": {
7532+
"ocs": {
7533+
"type": "object",
7534+
"required": [
7535+
"meta",
7536+
"data"
7537+
],
7538+
"properties": {
7539+
"meta": {
7540+
"$ref": "#/components/schemas/OCSMeta"
7541+
},
7542+
"data": {}
7543+
}
7544+
}
7545+
}
7546+
}
7547+
}
7548+
}
74957549
}
74967550
}
74977551
}
@@ -7504,7 +7558,6 @@
75047558
"text_to_image_api"
75057559
],
75067560
"security": [
7507-
{},
75087561
{
75097562
"bearer_auth": []
75107563
},
@@ -7648,6 +7701,34 @@
76487701
}
76497702
}
76507703
}
7704+
},
7705+
"401": {
7706+
"description": "Current user is not logged in",
7707+
"content": {
7708+
"application/json": {
7709+
"schema": {
7710+
"type": "object",
7711+
"required": [
7712+
"ocs"
7713+
],
7714+
"properties": {
7715+
"ocs": {
7716+
"type": "object",
7717+
"required": [
7718+
"meta",
7719+
"data"
7720+
],
7721+
"properties": {
7722+
"meta": {
7723+
"$ref": "#/components/schemas/OCSMeta"
7724+
},
7725+
"data": {}
7726+
}
7727+
}
7728+
}
7729+
}
7730+
}
7731+
}
76517732
}
76527733
}
76537734
},
@@ -7841,7 +7922,6 @@
78417922
"text_to_image_api"
78427923
],
78437924
"security": [
7844-
{},
78457925
{
78467926
"bearer_auth": []
78477927
},
@@ -7968,6 +8048,34 @@
79688048
}
79698049
}
79708050
}
8051+
},
8052+
"401": {
8053+
"description": "Current user is not logged in",
8054+
"content": {
8055+
"application/json": {
8056+
"schema": {
8057+
"type": "object",
8058+
"required": [
8059+
"ocs"
8060+
],
8061+
"properties": {
8062+
"ocs": {
8063+
"type": "object",
8064+
"required": [
8065+
"meta",
8066+
"data"
8067+
],
8068+
"properties": {
8069+
"meta": {
8070+
"$ref": "#/components/schemas/OCSMeta"
8071+
},
8072+
"data": {}
8073+
}
8074+
}
8075+
}
8076+
}
8077+
}
8078+
}
79718079
}
79728080
}
79738081
}

core/openapi.json

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7253,7 +7253,6 @@
72537253
"text_to_image_api"
72547254
],
72557255
"security": [
7256-
{},
72577256
{
72587257
"bearer_auth": []
72597258
},
@@ -7311,6 +7310,34 @@
73117310
}
73127311
}
73137312
}
7313+
},
7314+
"401": {
7315+
"description": "Current user is not logged in",
7316+
"content": {
7317+
"application/json": {
7318+
"schema": {
7319+
"type": "object",
7320+
"required": [
7321+
"ocs"
7322+
],
7323+
"properties": {
7324+
"ocs": {
7325+
"type": "object",
7326+
"required": [
7327+
"meta",
7328+
"data"
7329+
],
7330+
"properties": {
7331+
"meta": {
7332+
"$ref": "#/components/schemas/OCSMeta"
7333+
},
7334+
"data": {}
7335+
}
7336+
}
7337+
}
7338+
}
7339+
}
7340+
}
73147341
}
73157342
}
73167343
}
@@ -7323,7 +7350,6 @@
73237350
"text_to_image_api"
73247351
],
73257352
"security": [
7326-
{},
73277353
{
73287354
"bearer_auth": []
73297355
},
@@ -7492,6 +7518,34 @@
74927518
}
74937519
}
74947520
}
7521+
},
7522+
"401": {
7523+
"description": "Current user is not logged in",
7524+
"content": {
7525+
"application/json": {
7526+
"schema": {
7527+
"type": "object",
7528+
"required": [
7529+
"ocs"
7530+
],
7531+
"properties": {
7532+
"ocs": {
7533+
"type": "object",
7534+
"required": [
7535+
"meta",
7536+
"data"
7537+
],
7538+
"properties": {
7539+
"meta": {
7540+
"$ref": "#/components/schemas/OCSMeta"
7541+
},
7542+
"data": {}
7543+
}
7544+
}
7545+
}
7546+
}
7547+
}
7548+
}
74957549
}
74967550
}
74977551
}
@@ -7504,7 +7558,6 @@
75047558
"text_to_image_api"
75057559
],
75067560
"security": [
7507-
{},
75087561
{
75097562
"bearer_auth": []
75107563
},
@@ -7648,6 +7701,34 @@
76487701
}
76497702
}
76507703
}
7704+
},
7705+
"401": {
7706+
"description": "Current user is not logged in",
7707+
"content": {
7708+
"application/json": {
7709+
"schema": {
7710+
"type": "object",
7711+
"required": [
7712+
"ocs"
7713+
],
7714+
"properties": {
7715+
"ocs": {
7716+
"type": "object",
7717+
"required": [
7718+
"meta",
7719+
"data"
7720+
],
7721+
"properties": {
7722+
"meta": {
7723+
"$ref": "#/components/schemas/OCSMeta"
7724+
},
7725+
"data": {}
7726+
}
7727+
}
7728+
}
7729+
}
7730+
}
7731+
}
76517732
}
76527733
}
76537734
},
@@ -7841,7 +7922,6 @@
78417922
"text_to_image_api"
78427923
],
78437924
"security": [
7844-
{},
78457925
{
78467926
"bearer_auth": []
78477927
},
@@ -7968,6 +8048,34 @@
79688048
}
79698049
}
79708050
}
8051+
},
8052+
"401": {
8053+
"description": "Current user is not logged in",
8054+
"content": {
8055+
"application/json": {
8056+
"schema": {
8057+
"type": "object",
8058+
"required": [
8059+
"ocs"
8060+
],
8061+
"properties": {
8062+
"ocs": {
8063+
"type": "object",
8064+
"required": [
8065+
"meta",
8066+
"data"
8067+
],
8068+
"properties": {
8069+
"meta": {
8070+
"$ref": "#/components/schemas/OCSMeta"
8071+
},
8072+
"data": {}
8073+
}
8074+
}
8075+
}
8076+
}
8077+
}
8078+
}
79718079
}
79728080
}
79738081
}

0 commit comments

Comments
 (0)