@react-native-documents/picker 10.1.4 → 10.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -83,12 +83,8 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) :
|
|
|
83
83
|
|
|
84
84
|
@ReactMethod
|
|
85
85
|
override fun pick(opts: ReadableMap, promise: Promise) {
|
|
86
|
-
val currentActivity = currentActivity
|
|
86
|
+
val currentActivity = reactApplicationContext.currentActivity ?: return rejectWithNullActivity(promise)
|
|
87
87
|
|
|
88
|
-
if (currentActivity == null) {
|
|
89
|
-
rejectWithNullActivity(promise)
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
88
|
if (!promiseWrapper.trySetPromiseRejectingIncoming(promise, "pick")) {
|
|
93
89
|
return
|
|
94
90
|
}
|
|
@@ -145,11 +141,8 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) :
|
|
|
145
141
|
|
|
146
142
|
@ReactMethod
|
|
147
143
|
override fun pickDirectory(opts: ReadableMap, promise: Promise) {
|
|
148
|
-
val currentActivity = currentActivity
|
|
149
|
-
|
|
150
|
-
rejectWithNullActivity(promise)
|
|
151
|
-
return
|
|
152
|
-
}
|
|
144
|
+
val currentActivity = reactApplicationContext.currentActivity ?: return rejectWithNullActivity(promise)
|
|
145
|
+
|
|
153
146
|
if (!promiseWrapper.trySetPromiseRejectingIncoming(promise, "pickDirectory")) {
|
|
154
147
|
return
|
|
155
148
|
}
|
|
@@ -28,10 +28,10 @@ import MobileCoreServices
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
public func getMetadataFor(url: URL) throws -> DocumentMetadataBuilder {
|
|
31
|
-
if (currentOptions?.isOpenMode() == true) {
|
|
32
|
-
|
|
31
|
+
return if (currentOptions?.isOpenMode() == true) {
|
|
32
|
+
try self.getOpenedDocumentInfo(url: url, requestLongTermAccess: currentOptions?.requestLongTermAccess ?? false)
|
|
33
33
|
} else {
|
|
34
|
-
|
|
34
|
+
try self.getAnyModeMetadata(url: url)
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -4,45 +4,47 @@ import Foundation
|
|
|
4
4
|
|
|
5
5
|
@objc public class FileOperations: NSObject {
|
|
6
6
|
|
|
7
|
-
@objc public static func keepLocalCopyAtUniqueDestination(from:
|
|
8
|
-
|
|
9
|
-
let results =
|
|
7
|
+
@objc public static func keepLocalCopyAtUniqueDestination(from: [[String: String]], destinationPreset: String, resolve: @escaping RNDPPromiseResolveBlock) {
|
|
8
|
+
DispatchQueue.global(qos: .utility).async {
|
|
9
|
+
let results = moveFiles(from: from, destinationPreset: destinationPreset)
|
|
10
10
|
resolve(results)
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
static func moveFiles(from:
|
|
14
|
+
static func moveFiles(from: [[String: String]], destinationPreset: String) -> [[String: String?]] {
|
|
15
15
|
let destinationRootDir = getDirectoryForFileDestination(destinationPreset)
|
|
16
16
|
let uniqueSubDirName = UUID().uuidString
|
|
17
|
-
let destinationDir
|
|
18
|
-
// TODO do we need all of this Task dance?
|
|
17
|
+
let destinationDir = destinationRootDir.appendingPathComponent(uniqueSubDirName, isDirectory: true)
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
do {
|
|
26
|
-
guard let uriString = dictionary["uri"], let uri = URL(string: uriString) else {
|
|
27
|
-
return LocalCopyResponse.error(sourceUri: dictionary["uri"], copyError: "Invalid URI")
|
|
28
|
-
}
|
|
29
|
-
guard let fileName = dictionary["fileName"] else {
|
|
30
|
-
return LocalCopyResponse.error(sourceUri: uri.absoluteString, copyError: "Invalid fileName")
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let destinationUrl = try moveToDestination(from: uri, usingFilename: fileName, destinationDir: destinationDir)
|
|
34
|
-
return LocalCopyResponse.success(sourceUri: uri.absoluteString, localUri: destinationUrl.absoluteString)
|
|
35
|
-
} catch {
|
|
36
|
-
return LocalCopyResponse.error(sourceUri: dictionary["uri"]!, copyError: error.localizedDescription)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
19
|
+
do {
|
|
20
|
+
try FileManager.default.createDirectory(at: destinationDir, withIntermediateDirectories: true, attributes: nil)
|
|
21
|
+
} catch {
|
|
22
|
+
return from.map { dictionary in
|
|
23
|
+
LocalCopyResponse.error(sourceUri: dictionary["uri"], copyError: "Failed to create destination directory: \(error.localizedDescription)").dictionaryRepresentation
|
|
39
24
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// move files
|
|
28
|
+
return from.map { dictionary in
|
|
29
|
+
moveSingleFile(dictionary: dictionary, destinationDir: destinationDir).dictionaryRepresentation
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private static func moveSingleFile(dictionary: [String: String], destinationDir: URL) -> LocalCopyResponse {
|
|
34
|
+
guard let uriString = dictionary["uri"],
|
|
35
|
+
let uri = URL(string: uriString),
|
|
36
|
+
let fileName = dictionary["fileName"] else {
|
|
37
|
+
return LocalCopyResponse.error(
|
|
38
|
+
sourceUri: dictionary["uri"],
|
|
39
|
+
copyError: "Invalid URI or fileName"
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
do {
|
|
44
|
+
let destinationUrl = try moveToDestination(from: uri, usingFilename: fileName, destinationDir: destinationDir)
|
|
45
|
+
return LocalCopyResponse.success(sourceUri: uri.absoluteString, localUri: destinationUrl.absoluteString)
|
|
46
|
+
} catch {
|
|
47
|
+
return LocalCopyResponse.error(sourceUri: uriString, copyError: error.localizedDescription)
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -50,19 +52,20 @@ import Foundation
|
|
|
50
52
|
let destinationFile = destinationDir.appendingPathComponent(fileName).standardized
|
|
51
53
|
|
|
52
54
|
guard destinationFile.path.hasPrefix(destinationDir.standardized.path) else {
|
|
53
|
-
throw NSError(
|
|
55
|
+
throw NSError(
|
|
56
|
+
domain: "PathTraversalPrevention",
|
|
57
|
+
code: 400,
|
|
58
|
+
userInfo: [NSLocalizedDescriptionKey: "The copied file is attempting to write outside of the target directory."]
|
|
59
|
+
)
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
try FileManager.default.createDirectory(at: destinationDir, withIntermediateDirectories: true, attributes: nil)
|
|
57
62
|
try FileManager.default.moveItem(at: from, to: destinationFile)
|
|
58
63
|
|
|
59
64
|
return destinationFile
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
static func getDirectoryForFileDestination(_ copyToDirectory: String) -> URL {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
return FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
|
|
68
|
+
let searchPath: FileManager.SearchPathDirectory = copyToDirectory == "documentDirectory" ? .documentDirectory : .cachesDirectory
|
|
69
|
+
return FileManager.default.urls(for: searchPath, in: .userDomainMask).first!
|
|
67
70
|
}
|
|
68
71
|
}
|
|
@@ -28,14 +28,10 @@ import UniformTypeIdentifiers
|
|
|
28
28
|
|
|
29
29
|
static func createUTType(kind: String, value: String) -> UTType? {
|
|
30
30
|
switch kind {
|
|
31
|
-
case "UTType":
|
|
32
|
-
|
|
33
|
-
case "
|
|
34
|
-
|
|
35
|
-
case "extension":
|
|
36
|
-
return UTType(filenameExtension: value)
|
|
37
|
-
default:
|
|
38
|
-
return nil
|
|
31
|
+
case "UTType": UTType(value)
|
|
32
|
+
case "mimeType": UTType(mimeType: value)
|
|
33
|
+
case "extension": UTType(filenameExtension: value)
|
|
34
|
+
default: nil
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
37
|
}
|
package/package.json
CHANGED