Skip to content

Commit 3ab63cb

Browse files
committed
chore: update openapi spec
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
1 parent c06b2f3 commit 3ab63cb

File tree

3 files changed

+274
-6
lines changed

3 files changed

+274
-6
lines changed

core/Controller/ConversionApiController.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212

1313
use OCP\AppFramework\Http;
1414
use OCP\AppFramework\Http\Attribute\ApiRoute;
15+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1516
use OCP\AppFramework\Http\Attribute\UserRateLimit;
1617
use OCP\AppFramework\Http\DataResponse;
18+
use OCP\AppFramework\OCS\OCSException;
19+
use OCP\AppFramework\OCS\OCSNotFoundException;
1720
use OCP\AppFramework\OCSController;
1821
use OCP\Conversion\IConversionManager;
1922
use OCP\Files\File;
@@ -33,25 +36,36 @@ public function __construct(
3336
parent::__construct($appName, $request);
3437
}
3538

39+
/**
40+
* Converts a file from one MIME type to another
41+
*
42+
* @param int $fileId ID of the file to be converted
43+
* @param string $targetMimeType The MIME type to which you want to convert the file
44+
* @param string|null $destination The target path of the converted file. Written to a temporary file if left empty
45+
*
46+
* @return DataResponse<Http::STATUS_CREATED, array{path: string}, array{}>
47+
*
48+
* 201: File was converted and written to the destination or temporary file
49+
*
50+
* @throws OCSException The file was unable to be converted
51+
* @throws OCSNotFoundException The file to be converted was not found
52+
*/
53+
#[NoAdminRequired]
3654
#[UserRateLimit(limit: 25, period: 120)]
3755
#[ApiRoute(verb: 'POST', url: '/convert', root: '/conversion')]
3856
public function convert(int $fileId, string $targetMimeType, ?string $destination = null): DataResponse {
3957
$userFolder = $this->rootFolder->getUserFolder($this->userId);
4058
$file = $userFolder->getFirstNodeById($fileId);
4159

4260
if (!($file instanceof File)) {
43-
return new DataResponse([
44-
'message' => $this->l10n->t('File not found'),
45-
], Http::STATUS_NOT_FOUND);
61+
throw new OCSNotFoundException();
4662
}
4763

4864
try {
4965
$destination = $userFolder->getFullpath($destination);
5066
$convertedFile = $this->conversionManager->convert($file, $targetMimeType, $destination);
5167
} catch (\Exception $e) {
52-
return new DataResponse([
53-
'message' => $e->getMessage(),
54-
], Http::STATUS_INTERNAL_SERVER_ERROR);
68+
throw new OCSException($e->getMessage());
5569
}
5670

5771
return new DataResponse([

core/openapi-full.json

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,133 @@
25352535
}
25362536
}
25372537
},
2538+
"/ocs/v2.php/conversion/convert": {
2539+
"post": {
2540+
"operationId": "conversion_api-convert",
2541+
"summary": "Converts a file from one MIME type to another",
2542+
"tags": [
2543+
"conversion_api"
2544+
],
2545+
"security": [
2546+
{
2547+
"bearer_auth": []
2548+
},
2549+
{
2550+
"basic_auth": []
2551+
}
2552+
],
2553+
"requestBody": {
2554+
"required": true,
2555+
"content": {
2556+
"application/json": {
2557+
"schema": {
2558+
"type": "object",
2559+
"required": [
2560+
"fileId",
2561+
"targetMimeType"
2562+
],
2563+
"properties": {
2564+
"fileId": {
2565+
"type": "integer",
2566+
"format": "int64",
2567+
"description": "ID of the file to be converted"
2568+
},
2569+
"targetMimeType": {
2570+
"type": "string",
2571+
"description": "The MIME type to which you want to convert the file"
2572+
},
2573+
"destination": {
2574+
"type": "string",
2575+
"nullable": true,
2576+
"description": "The target path of the converted file. Written to a temporary file if left empty"
2577+
}
2578+
}
2579+
}
2580+
}
2581+
}
2582+
},
2583+
"parameters": [
2584+
{
2585+
"name": "OCS-APIRequest",
2586+
"in": "header",
2587+
"description": "Required to be true for the API request to pass",
2588+
"required": true,
2589+
"schema": {
2590+
"type": "boolean",
2591+
"default": true
2592+
}
2593+
}
2594+
],
2595+
"responses": {
2596+
"201": {
2597+
"description": "File was converted and written to the destination or temporary file",
2598+
"content": {
2599+
"application/json": {
2600+
"schema": {
2601+
"type": "object",
2602+
"required": [
2603+
"ocs"
2604+
],
2605+
"properties": {
2606+
"ocs": {
2607+
"type": "object",
2608+
"required": [
2609+
"meta",
2610+
"data"
2611+
],
2612+
"properties": {
2613+
"meta": {
2614+
"$ref": "#/components/schemas/OCSMeta"
2615+
},
2616+
"data": {
2617+
"type": "object",
2618+
"required": [
2619+
"path"
2620+
],
2621+
"properties": {
2622+
"path": {
2623+
"type": "string"
2624+
}
2625+
}
2626+
}
2627+
}
2628+
}
2629+
}
2630+
}
2631+
}
2632+
}
2633+
},
2634+
"404": {
2635+
"description": "The file to be converted was not found",
2636+
"content": {
2637+
"application/json": {
2638+
"schema": {
2639+
"type": "object",
2640+
"required": [
2641+
"ocs"
2642+
],
2643+
"properties": {
2644+
"ocs": {
2645+
"type": "object",
2646+
"required": [
2647+
"meta",
2648+
"data"
2649+
],
2650+
"properties": {
2651+
"meta": {
2652+
"$ref": "#/components/schemas/OCSMeta"
2653+
},
2654+
"data": {}
2655+
}
2656+
}
2657+
}
2658+
}
2659+
}
2660+
}
2661+
}
2662+
}
2663+
}
2664+
},
25382665
"/ocs/v2.php/hovercard/v1/{userId}": {
25392666
"get": {
25402667
"operationId": "hover_card-get-user",

core/openapi.json

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,133 @@
25352535
}
25362536
}
25372537
},
2538+
"/ocs/v2.php/conversion/convert": {
2539+
"post": {
2540+
"operationId": "conversion_api-convert",
2541+
"summary": "Converts a file from one MIME type to another",
2542+
"tags": [
2543+
"conversion_api"
2544+
],
2545+
"security": [
2546+
{
2547+
"bearer_auth": []
2548+
},
2549+
{
2550+
"basic_auth": []
2551+
}
2552+
],
2553+
"requestBody": {
2554+
"required": true,
2555+
"content": {
2556+
"application/json": {
2557+
"schema": {
2558+
"type": "object",
2559+
"required": [
2560+
"fileId",
2561+
"targetMimeType"
2562+
],
2563+
"properties": {
2564+
"fileId": {
2565+
"type": "integer",
2566+
"format": "int64",
2567+
"description": "ID of the file to be converted"
2568+
},
2569+
"targetMimeType": {
2570+
"type": "string",
2571+
"description": "The MIME type to which you want to convert the file"
2572+
},
2573+
"destination": {
2574+
"type": "string",
2575+
"nullable": true,
2576+
"description": "The target path of the converted file. Written to a temporary file if left empty"
2577+
}
2578+
}
2579+
}
2580+
}
2581+
}
2582+
},
2583+
"parameters": [
2584+
{
2585+
"name": "OCS-APIRequest",
2586+
"in": "header",
2587+
"description": "Required to be true for the API request to pass",
2588+
"required": true,
2589+
"schema": {
2590+
"type": "boolean",
2591+
"default": true
2592+
}
2593+
}
2594+
],
2595+
"responses": {
2596+
"201": {
2597+
"description": "File was converted and written to the destination or temporary file",
2598+
"content": {
2599+
"application/json": {
2600+
"schema": {
2601+
"type": "object",
2602+
"required": [
2603+
"ocs"
2604+
],
2605+
"properties": {
2606+
"ocs": {
2607+
"type": "object",
2608+
"required": [
2609+
"meta",
2610+
"data"
2611+
],
2612+
"properties": {
2613+
"meta": {
2614+
"$ref": "#/components/schemas/OCSMeta"
2615+
},
2616+
"data": {
2617+
"type": "object",
2618+
"required": [
2619+
"path"
2620+
],
2621+
"properties": {
2622+
"path": {
2623+
"type": "string"
2624+
}
2625+
}
2626+
}
2627+
}
2628+
}
2629+
}
2630+
}
2631+
}
2632+
}
2633+
},
2634+
"404": {
2635+
"description": "The file to be converted was not found",
2636+
"content": {
2637+
"application/json": {
2638+
"schema": {
2639+
"type": "object",
2640+
"required": [
2641+
"ocs"
2642+
],
2643+
"properties": {
2644+
"ocs": {
2645+
"type": "object",
2646+
"required": [
2647+
"meta",
2648+
"data"
2649+
],
2650+
"properties": {
2651+
"meta": {
2652+
"$ref": "#/components/schemas/OCSMeta"
2653+
},
2654+
"data": {}
2655+
}
2656+
}
2657+
}
2658+
}
2659+
}
2660+
}
2661+
}
2662+
}
2663+
}
2664+
},
25382665
"/ocs/v2.php/hovercard/v1/{userId}": {
25392666
"get": {
25402667
"operationId": "hover_card-get-user",

0 commit comments

Comments
 (0)