| 40 | import java.util.Map; |
| 41 | |
| 42 | @ReactModule(name = RNFSManager.MODULE_NAME) |
| 43 | public class RNFSManager extends ReactContextBaseJavaModule { |
| 44 | |
| 45 | static final String MODULE_NAME = "RNFSManager"; |
| 46 | |
| 47 | private static final String RNFSDocumentDirectoryPath = "RNFSDocumentDirectoryPath"; |
| 48 | private static final String RNFSExternalDirectoryPath = "RNFSExternalDirectoryPath"; |
| 49 | private static final String RNFSExternalStorageDirectoryPath = "RNFSExternalStorageDirectoryPath"; |
| 50 | private static final String RNFSPicturesDirectoryPath = "RNFSPicturesDirectoryPath"; |
| 51 | private static final String RNFSDownloadDirectoryPath = "RNFSDownloadDirectoryPath"; |
| 52 | private static final String RNFSTemporaryDirectoryPath = "RNFSTemporaryDirectoryPath"; |
| 53 | private static final String RNFSCachesDirectoryPath = "RNFSCachesDirectoryPath"; |
| 54 | private static final String RNFSExternalCachesDirectoryPath = "RNFSExternalCachesDirectoryPath"; |
| 55 | private static final String RNFSDocumentDirectory = "RNFSDocumentDirectory"; |
| 56 | |
| 57 | private static final String RNFSFileTypeRegular = "RNFSFileTypeRegular"; |
| 58 | private static final String RNFSFileTypeDirectory = "RNFSFileTypeDirectory"; |
| 59 | |
| 60 | private SparseArray<Downloader> downloaders = new SparseArray<>(); |
| 61 | private SparseArray<Uploader> uploaders = new SparseArray<>(); |
| 62 | |
| 63 | private ReactApplicationContext reactContext; |
| 64 | |
| 65 | public RNFSManager(ReactApplicationContext reactContext) { |
| 66 | super(reactContext); |
| 67 | this.reactContext = reactContext; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public String getName() { |
| 72 | return MODULE_NAME; |
| 73 | } |
| 74 | |
| 75 | private Uri getFileUri(String filepath, boolean isDirectoryAllowed) throws IORejectionException { |
| 76 | Uri uri = Uri.parse(filepath); |
| 77 | if (uri.getScheme() == null) { |
| 78 | // No prefix, assuming that provided path is absolute path to file |
| 79 | File file = new File(filepath); |
| 80 | if (!isDirectoryAllowed && file.isDirectory()) { |
| 81 | throw new IORejectionException("EISDIR", "EISDIR: illegal operation on a directory, read '" + filepath + "'"); |
| 82 | } |
| 83 | uri = Uri.parse("file://" + filepath); |
| 84 | } |
| 85 | return uri; |
| 86 | } |
| 87 | |
| 88 | private String getOriginalFilepath(String filepath, boolean isDirectoryAllowed) throws IORejectionException { |
| 89 | Uri uri = getFileUri(filepath, isDirectoryAllowed); |
| 90 | String originalFilepath = filepath; |
| 91 | if (uri.getScheme().equals("content")) { |
| 92 | try { |
| 93 | Cursor cursor = reactContext.getContentResolver().query(uri, null, null, null, null); |
| 94 | if (cursor.moveToFirst()) { |
| 95 | originalFilepath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); |
| 96 | } |
| 97 | cursor.close(); |
| 98 | } catch (IllegalArgumentException ignored) { |
| 99 | } |
nothing calls this directly
no outgoing calls
no test coverage detected