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

iOS: Implement security scope access (bookmark) for read and readDir #51

Open
zenoxs opened this issue Jun 14, 2024 · 3 comments
Open
Labels
In Progress Work in progress. P2 Important issue.

Comments

@zenoxs
Copy link

zenoxs commented Jun 14, 2024

Hey,
First of all thank you for taking over the development of the fs lib.

I'm trying to access shared directories from my app on iOS, it should be possible using the new security scoped URL with bookmark: https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directories.

I can submit a PR to implement this feature but I would like to know which approach do you prefer?
Would it make sense to create "readDirBookmark" and "readBookmark" functions only available for iOS? then passing the base64 encoded iOS bookmark (this would allow the implementation to work easily with https://react-native-documents.github.io/docs/doc-picker-api#bookmarkingresponse)

@birdofpreyru
Copy link
Owner

Hi @zenoxs , thanks for your interest!

I am strongly against specific-OS-only functions in RN libraries. This one has a bunch of them, but that is the legacy, I want to get rid of them all over time (though, it might take a while).

Re. bookmarks, I've added their support to pickFile(), copyFile(), and exists() methods some time ago (see #28, and the commit 2437f8e, in particular). I might not remember the exact details now, but I believe in TS layer bookmark URLs are handled just as regular URLs passed to the existing functions, and having the format bookmark://<BASE64_ENCODED_SCOPED_URL_DATA>, and on the native side, in iOS code, there is already pathToUrl() method that, if passed such string, correctly restores the original bookmark URL, which can be used to access scoped resources (and if passed a regular URL, it also handles it appropriately). So, essentially to support that in other functions, you should just ensure they pass URL they got through that pathToUrl() method, and may be a few other minor checks / code changes on top of that — just replicate what I did in that change I referred to. Unless I am missing anything here, then let's discuss if further.

@birdofpreyru birdofpreyru added the P2 Important issue. label Jun 14, 2024
@zenoxs
Copy link
Author

zenoxs commented Jun 14, 2024

Hi @zenoxs , thanks for your interest!

I am strongly against specific-OS-only functions in RN libraries. This one has a bunch of them, but that is the legacy, I want to get rid of them all over time (though, it might take a while).

Re. bookmarks, I've added their support to pickFile(), copyFile(), and exists() methods some time ago (see #28, and the commit 2437f8e, in particular). I might not remember the exact details now, but I believe in TS layer bookmark URLs are handled just as regular URLs passed to the existing functions, and having the format bookmark://<BASE64_ENCODED_SCOPED_URL_DATA>, and on the native side, in iOS code, there is already pathToUrl() method that, if passed such string, correctly restores the original bookmark URL, which can be used to access scoped resources (and if passed a regular URL, it also handles it appropriately). So, essentially to support that in other functions, you should just ensure they pass URL they got through that pathToUrl() method, and may be a few other minor checks / code changes on top of that — just replicate what I did in that change I referred to. Unless I am missing anything here, then let's discuss if further.

Thanks for the quick reply and for all the details, that's exactly what I was expecting. I will try to replicate what you did for pickFile(), copyFile(), and exists() for the read and readDir with the bookmark scheme in the url. 👍

@birdofpreyru birdofpreyru added In Progress Work in progress. Ready Ready for release. and removed In Progress Work in progress. Ready Ready for release. labels Jun 15, 2024
@birdofpreyru
Copy link
Owner

Presumably done for readDir() (though, I have not explicitly tested it with a bookmark, just refactored the code, and checked it still works for regular URLs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Progress Work in progress. P2 Important issue.
Projects
None yet
Development

No branches or pull requests

2 participants