Skip to content

Commit

Permalink
chore: update openapi spec
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Dec 23, 2024
1 parent c06b2f3 commit 3ab63cb
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 6 deletions.
26 changes: 20 additions & 6 deletions core/Controller/ConversionApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\UserRateLimit;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\Conversion\IConversionManager;
use OCP\Files\File;
Expand All @@ -33,25 +36,36 @@ public function __construct(
parent::__construct($appName, $request);
}

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

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

try {
$destination = $userFolder->getFullpath($destination);
$convertedFile = $this->conversionManager->convert($file, $targetMimeType, $destination);
} catch (\Exception $e) {
return new DataResponse([
'message' => $e->getMessage(),
], Http::STATUS_INTERNAL_SERVER_ERROR);
throw new OCSException($e->getMessage());
}

return new DataResponse([
Expand Down
127 changes: 127 additions & 0 deletions core/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,133 @@
}
}
},
"/ocs/v2.php/conversion/convert": {
"post": {
"operationId": "conversion_api-convert",
"summary": "Converts a file from one MIME type to another",
"tags": [
"conversion_api"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"fileId",
"targetMimeType"
],
"properties": {
"fileId": {
"type": "integer",
"format": "int64",
"description": "ID of the file to be converted"
},
"targetMimeType": {
"type": "string",
"description": "The MIME type to which you want to convert the file"
},
"destination": {
"type": "string",
"nullable": true,
"description": "The target path of the converted file. Written to a temporary file if left empty"
}
}
}
}
}
},
"parameters": [
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"201": {
"description": "File was converted and written to the destination or temporary file",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"path"
],
"properties": {
"path": {
"type": "string"
}
}
}
}
}
}
}
}
}
},
"404": {
"description": "The file to be converted was not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/hovercard/v1/{userId}": {
"get": {
"operationId": "hover_card-get-user",
Expand Down
127 changes: 127 additions & 0 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,133 @@
}
}
},
"/ocs/v2.php/conversion/convert": {
"post": {
"operationId": "conversion_api-convert",
"summary": "Converts a file from one MIME type to another",
"tags": [
"conversion_api"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"fileId",
"targetMimeType"
],
"properties": {
"fileId": {
"type": "integer",
"format": "int64",
"description": "ID of the file to be converted"
},
"targetMimeType": {
"type": "string",
"description": "The MIME type to which you want to convert the file"
},
"destination": {
"type": "string",
"nullable": true,
"description": "The target path of the converted file. Written to a temporary file if left empty"
}
}
}
}
}
},
"parameters": [
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"201": {
"description": "File was converted and written to the destination or temporary file",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"path"
],
"properties": {
"path": {
"type": "string"
}
}
}
}
}
}
}
}
}
},
"404": {
"description": "The file to be converted was not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/hovercard/v1/{userId}": {
"get": {
"operationId": "hover_card-get-user",
Expand Down

0 comments on commit 3ab63cb

Please sign in to comment.