Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: file conversion provider #49922

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

elzody
Copy link
Contributor

@elzody elzody commented Dec 18, 2024

Summary

This PR will introduce a file conversion API endpoint, which can be called to convert a file from one type to another. Apps can register their own conversion providers (which implement IConversionProvider), and the providers can define which MIME types they support for conversion via ConversionMimeTuples.

TODO

  • OpenAPI specs
  • Flesh out some more details around the IConversionProvider interface
    • What type should it really return? Stream, resource, File, file path?
  • What should happen when multiple apps register similar conversion providers?
  • How should we make the preferred list of conversion providers?

Checklist

@elzody elzody added enhancement 2. developing Work in progress feature: files feature: workflows php Pull requests that update Php code labels Dec 18, 2024
@elzody elzody added this to the Nextcloud 31 milestone Dec 18, 2024
@elzody elzody self-assigned this Dec 18, 2024
@elzody elzody force-pushed the feat/file-conversion-provider branch 2 times, most recently from 7e8ed84 to 3ab63cb Compare December 23, 2024 22:46

public function getSupportedMimeTypes(): array {
$jpegConversions = new ConversionMimeTuple('image/jpeg', [
'image/png',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something just came to my mind is that for integrating the user interface we may also want additional metadata for the target formats.

We can probably get the file extension from our mimetype mapping, but wondering if we need to have more details, like a display name. Similar to save dialogs that came to my mind:

Screenshot 2024-12-27 at 17 26 10

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorbaugh Has the files team already discussed any UI parts with designers? I'd say we can start with this PR and could extend/adapt on demand later on as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I literally added a similar comment eheh

Two options I think:

  1. We stop using getSupportedMimeTypes and go back to a singular getSupportedMimeType, and we basically use the name, only one Provider per destination mime
  2. We turn this into a mime => l10n array, so we know the end name of each mime :)

@elzody elzody force-pushed the feat/file-conversion-provider branch from b1d9670 to 1bceac6 Compare December 27, 2024 19:58
@elzody elzody force-pushed the feat/file-conversion-provider branch 2 times, most recently from 2cdd54b to e91c447 Compare January 7, 2025 20:24
Comment on lines 58 to 62
if (!($file instanceof File)) {
throw new OCSNotFoundException();
}

try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also check the parent folder CREATE permissions?

Copy link
Contributor Author

@elzody elzody Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. I just did some testing by sharing a view-only folder with a document in it to another user, and it will already throw an OCP\Files\NotPermittedException if it cannot write to the destination (L122), which then returns something like this in the network response via an OCSException:

{
  "ocs": {
    "meta": {
      "status": "failure",
      "statuscode": 999,
      "message": "Could not create path \"/alice/files/Bobs_Shared_Folder/converted_file.pdf\""
    },
    "data": []
  }
}

I can still implement an explicit check if necessary, though. What do you think? It could also be that my error handling here isn't the best or obvious enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can still implement an explicit check if necessary, though

I am usually in favour of clear sanity checks.
Because if something breaks/changes in the following methods, we'll have no way of knowing it.

@elzody elzody marked this pull request as ready for review January 9, 2025 15:37
@elzody elzody requested a review from provokateurin as a code owner January 9, 2025 15:37
*
* @since 31.0.0
*/
public function getName(): string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

I think the name of the end format is more relevant.

elzody and others added 5 commits January 10, 2025 14:28
Signed-off-by: Elizabeth Danzberger <[email protected]>
Signed-off-by: Elizabeth Danzberger <[email protected]>
@elzody elzody force-pushed the feat/file-conversion-provider branch from 877231a to 2d7a803 Compare January 10, 2025 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress enhancement feature: files feature: workflows php Pull requests that update Php code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants