react-native-compressor 1.15.0 → 1.16.1
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.
- package/README.md +0 -2
- package/ios/Image/ImageCompressor.swift +63 -37
- package/ios/Image/ImageMain.swift +16 -5
- package/ios/Utils/Utils.swift +7 -6
- package/lib/commonjs/Audio/index.js +2 -4
- package/lib/commonjs/Audio/index.js.map +1 -1
- package/lib/commonjs/Image/index.js +3 -5
- package/lib/commonjs/Image/index.js.map +1 -1
- package/lib/commonjs/Main.js +1 -2
- package/lib/commonjs/Main.js.map +1 -1
- package/lib/commonjs/Spec/NativeCompressor.js +1 -2
- package/lib/commonjs/Spec/NativeCompressor.js.map +1 -1
- package/lib/commonjs/Video/index.js +12 -13
- package/lib/commonjs/Video/index.js.map +1 -1
- package/lib/commonjs/expo-plugin/compressor.js +1 -2
- package/lib/commonjs/expo-plugin/compressor.js.map +1 -1
- package/lib/commonjs/global.d.js +6 -0
- package/lib/commonjs/global.d.js.map +1 -0
- package/lib/commonjs/index.js +2 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/Downloader.js +2 -2
- package/lib/commonjs/utils/Downloader.js.map +1 -1
- package/lib/commonjs/utils/Uploader.js +9 -13
- package/lib/commonjs/utils/Uploader.js.map +1 -1
- package/lib/commonjs/utils/helpers.js +16 -0
- package/lib/commonjs/utils/helpers.js.map +1 -0
- package/lib/commonjs/utils/index.js +21 -26
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/Audio/index.js +3 -2
- package/lib/module/Audio/index.js.map +1 -1
- package/lib/module/Image/index.js +4 -3
- package/lib/module/Image/index.js.map +1 -1
- package/lib/module/Main.js +2 -0
- package/lib/module/Main.js.map +1 -1
- package/lib/module/Spec/NativeCompressor.js +2 -0
- package/lib/module/Spec/NativeCompressor.js.map +1 -1
- package/lib/module/Video/index.js +13 -11
- package/lib/module/Video/index.js.map +1 -1
- package/lib/module/expo-plugin/compressor.js +2 -0
- package/lib/module/expo-plugin/compressor.js.map +1 -1
- package/lib/module/global.d.js +4 -0
- package/lib/module/global.d.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/Downloader.js +3 -1
- package/lib/module/utils/Downloader.js.map +1 -1
- package/lib/module/utils/Uploader.js +8 -8
- package/lib/module/utils/Uploader.js.map +1 -1
- package/lib/module/utils/helpers.js +11 -0
- package/lib/module/utils/helpers.js.map +1 -0
- package/lib/module/utils/index.js +9 -19
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/src/Audio/index.d.ts.map +1 -0
- package/lib/typescript/src/Image/index.d.ts.map +1 -0
- package/lib/typescript/src/Main.d.ts.map +1 -0
- package/lib/typescript/src/Spec/NativeCompressor.d.ts.map +1 -0
- package/lib/typescript/src/Video/index.d.ts.map +1 -0
- package/lib/typescript/src/expo-plugin/compressor.d.ts.map +1 -0
- package/lib/typescript/{index.d.ts → src/index.d.ts} +7 -7
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/Downloader.d.ts +2 -0
- package/lib/typescript/src/utils/Downloader.d.ts.map +1 -0
- package/lib/typescript/{utils → src/utils}/Uploader.d.ts +1 -1
- package/lib/typescript/src/utils/Uploader.d.ts.map +1 -0
- package/lib/typescript/src/utils/helpers.d.ts +2 -0
- package/lib/typescript/src/utils/helpers.d.ts.map +1 -0
- package/lib/typescript/{utils → src/utils}/index.d.ts +2 -2
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +38 -95
- package/src/Image/index.tsx +5 -11
- package/src/Main.tsx +2 -4
- package/src/Spec/NativeCompressor.ts +1 -1
- package/src/Video/index.tsx +19 -43
- package/src/global.d.ts +8 -0
- package/src/utils/Downloader.tsx +6 -13
- package/src/utils/Uploader.tsx +7 -13
- package/src/utils/helpers.ts +8 -0
- package/src/utils/index.tsx +11 -45
- package/lib/typescript/Audio/index.d.ts.map +0 -1
- package/lib/typescript/Image/index.d.ts.map +0 -1
- package/lib/typescript/Main.d.ts.map +0 -1
- package/lib/typescript/Spec/NativeCompressor.d.ts.map +0 -1
- package/lib/typescript/Video/index.d.ts.map +0 -1
- package/lib/typescript/expo-plugin/compressor.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/utils/Downloader.d.ts +0 -2
- package/lib/typescript/utils/Downloader.d.ts.map +0 -1
- package/lib/typescript/utils/Uploader.d.ts.map +0 -1
- package/lib/typescript/utils/index.d.ts.map +0 -1
- /package/lib/typescript/{Audio → src/Audio}/index.d.ts +0 -0
- /package/lib/typescript/{Image → src/Image}/index.d.ts +0 -0
- /package/lib/typescript/{Main.d.ts → src/Main.d.ts} +0 -0
- /package/lib/typescript/{Spec → src/Spec}/NativeCompressor.d.ts +0 -0
- /package/lib/typescript/{Video → src/Video}/index.d.ts +0 -0
- /package/lib/typescript/{expo-plugin → src/expo-plugin}/compressor.d.ts +0 -0
package/README.md
CHANGED
|
@@ -101,17 +101,25 @@ class ImageCompressor {
|
|
|
101
101
|
return UIImage()
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
static func isCompressedSizeLessThanActualFile(sourceFileUrl: String
|
|
105
|
-
|
|
106
|
-
let sourcefileSize:Double=Utils.getfileSizeInBytes(forURL:sourceVideoURL!)
|
|
104
|
+
static func isCompressedSizeLessThanActualFile(sourceFileUrl: String?, sourceData: Data?, compressedFileUrl: String)-> Bool {
|
|
105
|
+
var sourcefileSize: Int = 0
|
|
107
106
|
|
|
108
|
-
let
|
|
109
|
-
|
|
107
|
+
if let _sourceFileUrl = sourceFileUrl {
|
|
108
|
+
let sourceVideoURL = URL(string: _sourceFileUrl)
|
|
109
|
+
sourcefileSize = Utils.getfileSizeInBytes(forURL: sourceVideoURL!)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if let _sourceData = sourceData {
|
|
113
|
+
sourcefileSize = _sourceData.count
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let compressedFileURL = URL(string: compressedFileUrl)
|
|
117
|
+
let compressedfileSize = Utils.getfileSizeInBytes(forURL: compressedFileURL!)
|
|
110
118
|
|
|
111
|
-
if
|
|
112
|
-
|
|
113
|
-
return true
|
|
119
|
+
if compressedfileSize <= sourcefileSize {
|
|
120
|
+
return true
|
|
114
121
|
}
|
|
122
|
+
|
|
115
123
|
return false
|
|
116
124
|
}
|
|
117
125
|
|
|
@@ -119,7 +127,7 @@ class ImageCompressor {
|
|
|
119
127
|
return data.starts(with: [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])
|
|
120
128
|
}
|
|
121
129
|
|
|
122
|
-
static func copyExifInfo(actualImagePath:String, image: UIImage, data: Data) -> Data {
|
|
130
|
+
static func copyExifInfo(actualImagePath: String, image: UIImage, data: Data) -> Data {
|
|
123
131
|
let fileURL = URL(string: actualImagePath)!
|
|
124
132
|
let filePath = fileURL.path
|
|
125
133
|
|
|
@@ -156,46 +164,45 @@ class ImageCompressor {
|
|
|
156
164
|
return destinationData as Data
|
|
157
165
|
}
|
|
158
166
|
|
|
159
|
-
static func writeImage(_ image: UIImage, output: Int, quality: Float, outputExtension: String, isBase64: Bool,disablePngTransparency:Bool,isEnableAutoCompress:Bool,actualImagePath:String)-> String{
|
|
167
|
+
static func writeImage(_ image: UIImage, output: Int, quality: Float, outputExtension: String, isBase64: Bool, disablePngTransparency: Bool, isEnableAutoCompress: Bool, actualImagePath: String?)-> String {
|
|
160
168
|
var data: Data
|
|
161
169
|
var exception: NSException?
|
|
170
|
+
|
|
162
171
|
switch OutputType(rawValue: output)! {
|
|
163
172
|
case .jpg:
|
|
164
173
|
data = image.jpegData(compressionQuality: CGFloat(quality))!
|
|
165
174
|
case .png:
|
|
166
|
-
if
|
|
167
|
-
{
|
|
175
|
+
if disablePngTransparency {
|
|
168
176
|
data = image.jpegData(compressionQuality: CGFloat(quality))!
|
|
169
177
|
let compressedImage = UIImage(data: data)
|
|
170
178
|
data = compressedImage!.pngData()!
|
|
179
|
+
} else {
|
|
180
|
+
data = image.pngData()!
|
|
171
181
|
}
|
|
172
|
-
else
|
|
173
|
-
{
|
|
174
|
-
data=image.pngData()!
|
|
175
|
-
}
|
|
176
|
-
|
|
177
182
|
}
|
|
178
183
|
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
if let _actualImagePath = actualImagePath {
|
|
185
|
+
data = copyExifInfo(actualImagePath: _actualImagePath, image: UIImage(data: data) ?? image, data: data)
|
|
186
|
+
}
|
|
181
187
|
|
|
182
188
|
if isBase64 {
|
|
183
189
|
return data.base64EncodedString(options: [])
|
|
184
190
|
} else {
|
|
185
191
|
let filePath = Utils.generateCacheFilePath(outputExtension)
|
|
192
|
+
|
|
186
193
|
do {
|
|
187
194
|
try data.write(to: URL(fileURLWithPath: filePath), options: .atomic)
|
|
188
195
|
let returnablePath = makeValidUri(filePath)
|
|
189
|
-
|
|
190
|
-
{
|
|
191
|
-
if
|
|
192
|
-
{
|
|
196
|
+
|
|
197
|
+
if isEnableAutoCompress == true {
|
|
198
|
+
if self.isCompressedSizeLessThanActualFile(sourceFileUrl: actualImagePath, sourceData: data, compressedFileUrl: returnablePath) {
|
|
193
199
|
return returnablePath
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
200
|
+
} else {
|
|
201
|
+
MediaCache.deleteFile(atPath: returnablePath)
|
|
202
|
+
|
|
203
|
+
if let _actualImagePath = actualImagePath {
|
|
204
|
+
return _actualImagePath
|
|
205
|
+
}
|
|
199
206
|
}
|
|
200
207
|
}
|
|
201
208
|
|
|
@@ -210,8 +217,8 @@ class ImageCompressor {
|
|
|
210
217
|
}
|
|
211
218
|
|
|
212
219
|
|
|
213
|
-
static func manualCompress(_ image: UIImage, output: Int, quality: Float, outputExtension: String, isBase64: Bool,disablePngTransparency:Bool,actualImagePath:String) -> String {
|
|
214
|
-
return writeImage(image, output: output, quality: quality, outputExtension: outputExtension, isBase64: isBase64, disablePngTransparency: disablePngTransparency,isEnableAutoCompress: false,actualImagePath: actualImagePath)
|
|
220
|
+
static func manualCompress(_ image: UIImage, output: Int, quality: Float, outputExtension: String, isBase64: Bool, disablePngTransparency: Bool, actualImagePath: String?) -> String {
|
|
221
|
+
return writeImage(image, output: output, quality: quality, outputExtension: outputExtension, isBase64: isBase64, disablePngTransparency: disablePngTransparency, isEnableAutoCompress: false, actualImagePath: actualImagePath)
|
|
215
222
|
}
|
|
216
223
|
|
|
217
224
|
|
|
@@ -280,15 +287,19 @@ class ImageCompressor {
|
|
|
280
287
|
}
|
|
281
288
|
|
|
282
289
|
|
|
283
|
-
|
|
290
|
+
static func manualCompressHandler(imagePath: String?, base64: String?, options: ImageCompressorOptions) -> String {
|
|
284
291
|
var exception: NSException?
|
|
285
292
|
var image: UIImage?
|
|
286
293
|
|
|
287
294
|
switch options.input {
|
|
288
295
|
case .base64:
|
|
289
|
-
|
|
296
|
+
if let _base64 = base64 {
|
|
297
|
+
image = ImageCompressor.decodeImage(_base64)
|
|
298
|
+
}
|
|
290
299
|
case .uri:
|
|
291
|
-
|
|
300
|
+
if let _imagePath = imagePath {
|
|
301
|
+
image = ImageCompressor.loadImage(_imagePath)
|
|
302
|
+
}
|
|
292
303
|
}
|
|
293
304
|
|
|
294
305
|
if let _image = image {
|
|
@@ -296,7 +307,7 @@ class ImageCompressor {
|
|
|
296
307
|
let outputExtension = ImageCompressorOptions.getOutputInString(options.output)
|
|
297
308
|
let resizedImage = ImageCompressor.manualResize(image!, maxWidth: options.maxWidth, maxHeight: options.maxHeight)
|
|
298
309
|
let isBase64 = options.returnableOutputType == .rbase64
|
|
299
|
-
return ImageCompressor.manualCompress(resizedImage, output: options.output.rawValue, quality: options.quality, outputExtension: outputExtension, isBase64: isBase64,disablePngTransparency: options.disablePngTransparency,actualImagePath: imagePath)
|
|
310
|
+
return ImageCompressor.manualCompress(resizedImage, output: options.output.rawValue, quality: options.quality, outputExtension: outputExtension, isBase64: isBase64,disablePngTransparency: options.disablePngTransparency, actualImagePath: imagePath)
|
|
300
311
|
} else {
|
|
301
312
|
exception = NSException(name: NSExceptionName(rawValue: "unsupported_value"), reason: "Unsupported value type.", userInfo: nil)
|
|
302
313
|
exception?.raise()
|
|
@@ -306,9 +317,20 @@ class ImageCompressor {
|
|
|
306
317
|
}
|
|
307
318
|
|
|
308
319
|
|
|
309
|
-
static func autoCompressHandler(
|
|
320
|
+
static func autoCompressHandler(imagePath: String?, base64: String?, options: ImageCompressorOptions) -> String {
|
|
310
321
|
var exception: NSException?
|
|
311
|
-
var image
|
|
322
|
+
var image: UIImage?
|
|
323
|
+
|
|
324
|
+
switch options.input {
|
|
325
|
+
case .base64:
|
|
326
|
+
if let _base64 = base64 {
|
|
327
|
+
image = ImageCompressor.decodeImage(_base64)
|
|
328
|
+
}
|
|
329
|
+
case .uri:
|
|
330
|
+
if let _imagePath = imagePath {
|
|
331
|
+
image = ImageCompressor.loadImage(_imagePath)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
312
334
|
|
|
313
335
|
if var image = image {
|
|
314
336
|
image = ImageCompressor.scaleAndRotateImage(image)
|
|
@@ -343,9 +365,13 @@ class ImageCompressor {
|
|
|
343
365
|
let isBase64 = options.returnableOutputType == .rbase64
|
|
344
366
|
|
|
345
367
|
if let img = UIGraphicsGetImageFromCurrentImageContext() {
|
|
346
|
-
return writeImage(img, output: options.output.rawValue, quality: Float(compressionQuality), outputExtension: outputExtension, isBase64: isBase64, disablePngTransparency: options.disablePngTransparency,isEnableAutoCompress: true,actualImagePath: imagePath)
|
|
368
|
+
return writeImage(img, output: options.output.rawValue, quality: Float(compressionQuality), outputExtension: outputExtension, isBase64: isBase64, disablePngTransparency: options.disablePngTransparency, isEnableAutoCompress: true, actualImagePath: imagePath)
|
|
347
369
|
}
|
|
370
|
+
} else {
|
|
371
|
+
exception = NSException(name: NSExceptionName(rawValue: "unsupported_value"), reason: "Unsupported value type.", userInfo: nil)
|
|
372
|
+
exception?.raise()
|
|
348
373
|
}
|
|
374
|
+
|
|
349
375
|
return ""
|
|
350
376
|
}
|
|
351
377
|
|
|
@@ -7,18 +7,29 @@
|
|
|
7
7
|
|
|
8
8
|
import Foundation
|
|
9
9
|
class ImageMain {
|
|
10
|
-
static func image_compress(_
|
|
10
|
+
static func image_compress(_ value: String, optionMap: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
11
11
|
do {
|
|
12
12
|
let options = ImageCompressorOptions.fromDictionary(optionMap as! [String : Any])
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
if options.input != InputType.base64 {
|
|
15
|
+
ImageCompressor.getAbsoluteImagePath(value, options: options) { absoluteImagePath in
|
|
16
|
+
if options.autoCompress {
|
|
17
|
+
let result = ImageCompressor.autoCompressHandler(imagePath: absoluteImagePath, base64: nil, options: options)
|
|
18
|
+
resolve(result)
|
|
19
|
+
} else {
|
|
20
|
+
let result = ImageCompressor.manualCompressHandler(imagePath: absoluteImagePath, base64: nil, options: options)
|
|
21
|
+
resolve(result)
|
|
22
|
+
}
|
|
23
|
+
MediaCache.removeCompletedImagePath(absoluteImagePath)
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
14
26
|
if options.autoCompress {
|
|
15
|
-
let result = ImageCompressor.autoCompressHandler(
|
|
27
|
+
let result = ImageCompressor.autoCompressHandler(imagePath: nil, base64: value, options: options)
|
|
16
28
|
resolve(result)
|
|
17
29
|
} else {
|
|
18
|
-
let result = ImageCompressor.manualCompressHandler(
|
|
30
|
+
let result = ImageCompressor.manualCompressHandler(imagePath: nil, base64: value, options: options)
|
|
19
31
|
resolve(result)
|
|
20
32
|
}
|
|
21
|
-
MediaCache.removeCompletedImagePath(absoluteImagePath)
|
|
22
33
|
}
|
|
23
34
|
} catch {
|
|
24
35
|
reject(error.localizedDescription, error.localizedDescription, nil)
|
package/ios/Utils/Utils.swift
CHANGED
|
@@ -106,9 +106,9 @@ class Utils {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
static func getfileSizeInBytes(forURL url: Any) ->
|
|
109
|
+
static func getfileSizeInBytes(forURL url: Any) -> Int {
|
|
110
110
|
var fileURL: URL?
|
|
111
|
-
var fileSize:
|
|
111
|
+
var fileSize: Int = 0
|
|
112
112
|
|
|
113
113
|
if (url is URL) {
|
|
114
114
|
let urlWithSlash = Utils.slashifyFilePath(path: (url as? URL)?.absoluteString)
|
|
@@ -120,11 +120,12 @@ class Utils {
|
|
|
120
120
|
return fileSize
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
var fileSizeValue = 0
|
|
123
|
+
var fileSizeValue = 0
|
|
124
124
|
|
|
125
|
-
try? fileSizeValue = (fileURL?.resourceValues(forKeys: [URLResourceKey.fileSizeKey]).allValues.first?.value as!
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
try? fileSizeValue = (fileURL?.resourceValues(forKeys: [URLResourceKey.fileSizeKey]).allValues.first?.value as! Int)
|
|
126
|
+
|
|
127
|
+
if fileSizeValue > 0 {
|
|
128
|
+
fileSize = fileSizeValue
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
return fileSize
|
|
@@ -8,8 +8,7 @@ var _Main = require("../Main");
|
|
|
8
8
|
var _utils = require("../utils");
|
|
9
9
|
const NativeAudio = _Main.Compressor;
|
|
10
10
|
const Audio = {
|
|
11
|
-
compress: async
|
|
12
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.DEFAULT_COMPRESS_AUDIO_OPTIONS;
|
|
11
|
+
compress: async (url, options = _utils.DEFAULT_COMPRESS_AUDIO_OPTIONS) => {
|
|
13
12
|
try {
|
|
14
13
|
return NativeAudio.compress_audio(url, options);
|
|
15
14
|
} catch (error) {
|
|
@@ -17,6 +16,5 @@ const Audio = {
|
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
};
|
|
20
|
-
var _default = Audio;
|
|
21
|
-
exports.default = _default;
|
|
19
|
+
var _default = exports.default = Audio;
|
|
22
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Main","require","_utils","NativeAudio","Compressor","Audio","compress","url","options","
|
|
1
|
+
{"version":3,"names":["_Main","require","_utils","NativeAudio","Compressor","Audio","compress","url","options","DEFAULT_COMPRESS_AUDIO_OPTIONS","compress_audio","error","message","_default","exports","default"],"sourceRoot":"../../../src","sources":["Audio/index.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEA,MAAME,WAAW,GAAGC,gBAAU;AAE9B,MAAMC,KAAgB,GAAG;EACvBC,QAAQ,EAAE,MAAAA,CAAOC,GAAG,EAAEC,OAAO,GAAGC,qCAA8B,KAAK;IACjE,IAAI;MACF,OAAON,WAAW,CAACO,cAAc,CAACH,GAAG,EAAEC,OAAO,CAAC;IACjD,CAAC,CAAC,OAAOG,KAAU,EAAE;MACnB,MAAMA,KAAK,CAACC,OAAO;IACrB;EACF;AACF,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaV,KAAK","ignoreList":[]}
|
|
@@ -11,14 +11,13 @@ const base64UrlRegex = /^data:image\/.*;(?:charset=.{3,5};)?base64,/;
|
|
|
11
11
|
const ImageCompressEventEmitter = new _reactNative.NativeEventEmitter(_Main.Compressor);
|
|
12
12
|
const NativeImage = _Main.Compressor;
|
|
13
13
|
const Image = {
|
|
14
|
-
compress: async
|
|
15
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
14
|
+
compress: async (value, options = {}) => {
|
|
16
15
|
if (!value) {
|
|
17
16
|
throw new Error('Compression value is empty, please provide a value for compression.');
|
|
18
17
|
}
|
|
19
18
|
let subscription;
|
|
20
19
|
try {
|
|
21
|
-
if (options
|
|
20
|
+
if (options?.downloadProgress) {
|
|
22
21
|
const uuid = (0, _utils.uuidv4)();
|
|
23
22
|
//@ts-ignore
|
|
24
23
|
options.uuid = uuid;
|
|
@@ -38,6 +37,5 @@ const Image = {
|
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
};
|
|
41
|
-
var _default = Image;
|
|
42
|
-
exports.default = _default;
|
|
40
|
+
var _default = exports.default = Image;
|
|
43
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Main","require","_utils","_reactNative","base64UrlRegex","ImageCompressEventEmitter","NativeEventEmitter","Compressor","NativeImage","Image","compress","value","options","
|
|
1
|
+
{"version":3,"names":["_Main","require","_utils","_reactNative","base64UrlRegex","ImageCompressEventEmitter","NativeEventEmitter","Compressor","NativeImage","Image","compress","value","options","Error","subscription","downloadProgress","uuid","uuidv4","addListener","event","data","progress","cleanData","replace","image_compress","remove","_default","exports","default"],"sourceRoot":"../../../src","sources":["Image/index.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAGA,IAAAE,YAAA,GAAAF,OAAA;AAFA,MAAMG,cAAc,GAAG,6CAA6C;AAuDpE,MAAMC,yBAAyB,GAAG,IAAIC,+BAAkB,CAACC,gBAAU,CAAC;AAEpE,MAAMC,WAAW,GAAGD,gBAAU;AAM9B,MAAME,KAAgB,GAAG;EACvBC,QAAQ,EAAE,MAAAA,CAAOC,KAAK,EAAEC,OAAO,GAAG,CAAC,CAAC,KAAK;IACvC,IAAI,CAACD,KAAK,EAAE;MACV,MAAM,IAAIE,KAAK,CAAC,qEAAqE,CAAC;IACxF;IAEA,IAAIC,YAAqC;IACzC,IAAI;MACF,IAAIF,OAAO,EAAEG,gBAAgB,EAAE;QAC7B,MAAMC,IAAI,GAAG,IAAAC,aAAM,EAAC,CAAC;QACrB;QACAL,OAAO,CAACI,IAAI,GAAGA,IAAI;QACnBF,YAAY,GAAGT,yBAAyB,CAACa,WAAW,CAAC,kBAAkB,EAAGC,KAAU,IAAK;UACvF,IAAIA,KAAK,CAACH,IAAI,KAAKA,IAAI,EAAE;YACvBJ,OAAO,CAACG,gBAAgB,IAAIH,OAAO,CAACG,gBAAgB,CAACI,KAAK,CAACC,IAAI,CAACC,QAAQ,CAAC;UAC3E;QACF,CAAC,CAAC;MACJ;MAEA,MAAMC,SAAS,GAAGX,KAAK,CAACY,OAAO,CAACnB,cAAc,EAAE,EAAE,CAAC;MACnD,OAAO,MAAMI,WAAW,CAACgB,cAAc,CAACF,SAAS,EAAEV,OAAO,CAAC;IAC7D,CAAC,SAAS;MACR;MACA,IAAIE,YAAY,EAAE;QAChBA,YAAY,CAACW,MAAM,CAAC,CAAC;MACvB;IACF;EACF;AACF,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEanB,KAAK","ignoreList":[]}
|
package/lib/commonjs/Main.js
CHANGED
|
@@ -13,10 +13,9 @@ const LINKING_ERROR = `The package 'react-native-compressor' doesn't seem to be
|
|
|
13
13
|
// @ts-expect-error
|
|
14
14
|
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
15
15
|
const CompressorModule = isTurboModuleEnabled ? require('./Spec/NativeCompressor').default : _reactNative.NativeModules.Compressor;
|
|
16
|
-
const Compressor = CompressorModule ? CompressorModule : new Proxy({}, {
|
|
16
|
+
const Compressor = exports.Compressor = CompressorModule ? CompressorModule : new Proxy({}, {
|
|
17
17
|
get() {
|
|
18
18
|
throw new Error(LINKING_ERROR);
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
|
-
exports.Compressor = Compressor;
|
|
22
21
|
//# sourceMappingURL=Main.js.map
|
package/lib/commonjs/Main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","CompressorModule","NativeModules","Compressor","Proxy","get","Error"
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","CompressorModule","NativeModules","Compressor","exports","Proxy","get","Error"],"sourceRoot":"../../src","sources":["Main.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,kFAAkF,GAClFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,gBAAgB,GAAGH,oBAAoB,GAAGN,OAAO,CAAC,yBAAyB,CAAC,CAACK,OAAO,GAAGK,0BAAa,CAACC,UAAU;AAErH,MAAMA,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAGF,gBAAgB,GAC/BA,gBAAgB,GAChB,IAAII,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACd,aAAa,CAAC;EAChC;AACF,CACF,CAAC","ignoreList":[]}
|
|
@@ -5,6 +5,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
|
-
var _default = _reactNative.TurboModuleRegistry.getEnforcing('Compressor');
|
|
9
|
-
exports.default = _default;
|
|
8
|
+
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('Compressor');
|
|
10
9
|
//# sourceMappingURL=NativeCompressor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_default","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../../src","sources":["Spec/NativeCompressor.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAuCpCC,gCAAmB,CAACC,YAAY,CAAO,YAAY,CAAC","ignoreList":[]}
|
|
@@ -26,7 +26,7 @@ const Video = {
|
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
if (options
|
|
29
|
+
if (options?.downloadProgress) {
|
|
30
30
|
//@ts-ignore
|
|
31
31
|
subscription2 = VideoCompressEventEmitter.addListener('downloadProgress', event => {
|
|
32
32
|
if (event.uuid === uuid) {
|
|
@@ -37,23 +37,23 @@ const Video = {
|
|
|
37
37
|
const modifiedOptions = {
|
|
38
38
|
uuid
|
|
39
39
|
};
|
|
40
|
-
if (options
|
|
41
|
-
if (options
|
|
42
|
-
if (options
|
|
43
|
-
modifiedOptions.compressionMethod = options
|
|
40
|
+
if (options?.progressDivider) modifiedOptions.progressDivider = options?.progressDivider;
|
|
41
|
+
if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;
|
|
42
|
+
if (options?.compressionMethod) {
|
|
43
|
+
modifiedOptions.compressionMethod = options?.compressionMethod;
|
|
44
44
|
} else {
|
|
45
45
|
modifiedOptions.compressionMethod = 'auto';
|
|
46
46
|
}
|
|
47
|
-
if (options
|
|
48
|
-
modifiedOptions.maxSize = options
|
|
47
|
+
if (options?.maxSize) {
|
|
48
|
+
modifiedOptions.maxSize = options?.maxSize;
|
|
49
49
|
} else {
|
|
50
50
|
modifiedOptions.maxSize = 640;
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
53
|
-
modifiedOptions.minimumFileSizeForCompress = options
|
|
52
|
+
if (options?.minimumFileSizeForCompress !== undefined) {
|
|
53
|
+
modifiedOptions.minimumFileSizeForCompress = options?.minimumFileSizeForCompress;
|
|
54
54
|
}
|
|
55
|
-
if (options
|
|
56
|
-
options
|
|
55
|
+
if (options?.getCancellationId) {
|
|
56
|
+
options?.getCancellationId(uuid);
|
|
57
57
|
}
|
|
58
58
|
const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
|
|
59
59
|
return result;
|
|
@@ -85,6 +85,5 @@ const Video = {
|
|
|
85
85
|
return NativeVideoCompressor.deactivateBackgroundTask({});
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
|
-
var _default = Video;
|
|
89
|
-
exports.default = _default;
|
|
88
|
+
var _default = exports.default = Video;
|
|
90
89
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_Main","_utils","VideoCompressEventEmitter","NativeEventEmitter","Compressor","NativeVideoCompressor","cancelCompression","cancellationId","exports","Video","compress","fileUrl","options","onProgress","uuid","uuidv4","subscription","subscription2","addListener","event","data","progress","downloadProgress","modifiedOptions","progressDivider","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","undefined","getCancellationId","result","remove","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners","_default","default"],"sourceRoot":"../../../src","sources":["Video/index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_Main","_utils","VideoCompressEventEmitter","NativeEventEmitter","Compressor","NativeVideoCompressor","cancelCompression","cancellationId","exports","Video","compress","fileUrl","options","onProgress","uuid","uuidv4","subscription","subscription2","addListener","event","data","progress","downloadProgress","modifiedOptions","progressDivider","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","undefined","getCancellationId","result","remove","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners","_default","default"],"sourceRoot":"../../../src","sources":["Video/index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAuBA,MAAMG,yBAAyB,GAAG,IAAIC,+BAAkB,CAACC,gBAAU,CAAC;AAEpE,MAAMC,qBAAqB,GAAGD,gBAAU;AA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QAAA,GAAA7B,OAAA,CAAA8B,OAAA,GAEV7B,KAAK","ignoreList":[]}
|
|
@@ -9,6 +9,5 @@ var _configPlugins = require("@expo/config-plugins");
|
|
|
9
9
|
|
|
10
10
|
const pkg = require('../../../package.json');
|
|
11
11
|
const withCompressor = config => config;
|
|
12
|
-
var _default = (0, _configPlugins.createRunOncePlugin)(withCompressor, pkg.name, pkg.version);
|
|
13
|
-
exports.default = _default;
|
|
12
|
+
var _default = exports.default = (0, _configPlugins.createRunOncePlugin)(withCompressor, pkg.name, pkg.version);
|
|
14
13
|
//# sourceMappingURL=compressor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_configPlugins","require","pkg","withCompressor","config","_default","
|
|
1
|
+
{"version":3,"names":["_configPlugins","require","pkg","withCompressor","config","_default","exports","default","createRunOncePlugin","name","version"],"sourceRoot":"../../../src","sources":["expo-plugin/compressor.ts"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AADA;;AAEA,MAAMC,GAAG,GAAGD,OAAO,CAAC,uBAAuB,CAAC;AAI5C,MAAME,cAAmC,GAAIC,MAAW,IAAKA,MAAM;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAErD,IAAAC,kCAAmB,EAACL,cAAc,EAAED,GAAG,CAACO,IAAI,EAAEP,GAAG,CAACQ,OAAO,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["global.d.ts"],"mappings":"","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -110,8 +110,8 @@ var _Video = _interopRequireDefault(require("./Video"));
|
|
|
110
110
|
var _Audio = _interopRequireDefault(require("./Audio"));
|
|
111
111
|
var _Image = _interopRequireDefault(require("./Image"));
|
|
112
112
|
var _utils = require("./utils");
|
|
113
|
-
function _interopRequireDefault(
|
|
114
|
-
var _default = {
|
|
113
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
114
|
+
var _default = exports.default = {
|
|
115
115
|
Video: _Video.default,
|
|
116
116
|
Audio: _Audio.default,
|
|
117
117
|
Image: _Image.default,
|
|
@@ -129,5 +129,4 @@ var _default = {
|
|
|
129
129
|
UploadType: _utils.UploadType,
|
|
130
130
|
UploaderHttpMethod: _utils.UploaderHttpMethod
|
|
131
131
|
};
|
|
132
|
-
exports.default = _default;
|
|
133
132
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Video","_interopRequireDefault","require","_Audio","_Image","_utils","
|
|
1
|
+
{"version":3,"names":["_Video","_interopRequireDefault","require","_Audio","_Image","_utils","e","__esModule","default","_default","exports","Video","Audio","Image","getDetails","uuidv4","generateFilePath","getRealPath","getVideoMetaData","getImageMetaData","getFileSize","backgroundUpload","createVideoThumbnail","clearCache","download","UploadType","UploaderHttpMethod"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAeiB,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAuBF;EACbG,KAAK,EAALA,cAAK;EACLC,KAAK,EAALA,cAAK;EACLC,KAAK,EAALA,cAAK;EACLC,UAAU,EAAVA,iBAAU;EACVC,MAAM,EAANA,aAAM;EACNC,gBAAgB,EAAhBA,uBAAgB;EAChBC,WAAW,EAAXA,kBAAW;EACXC,gBAAgB,EAAhBA,uBAAgB;EAChBC,gBAAgB,EAAhBA,uBAAgB;EAChBC,WAAW,EAAXA,kBAAW;EACXC,gBAAgB,EAAhBA,uBAAgB;EAChBC,oBAAoB,EAApBA,2BAAoB;EACpBC,UAAU,EAAVA,iBAAU;EACVC,QAAQ,EAARA,eAAQ;EACRC,UAAU,EAAVA,iBAAU;EACVC,kBAAkB,EAAlBA;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.download = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
8
|
var _Main = require("../Main");
|
|
9
|
-
var
|
|
9
|
+
var _helpers = require("./helpers");
|
|
10
10
|
const CompressEventEmitter = new _reactNative.NativeEventEmitter(_Main.Compressor);
|
|
11
11
|
const download = async (fileUrl, downloadProgress, progressDivider) => {
|
|
12
12
|
let subscription;
|
|
13
13
|
try {
|
|
14
|
-
const uuid = (0,
|
|
14
|
+
const uuid = (0, _helpers.uuidv4)();
|
|
15
15
|
if (downloadProgress) {
|
|
16
16
|
subscription = CompressEventEmitter.addListener('downloadProgress', event => {
|
|
17
17
|
if (event.uuid === uuid) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_Main","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_Main","_helpers","CompressEventEmitter","NativeEventEmitter","Compressor","download","fileUrl","downloadProgress","progressDivider","subscription","uuid","uuidv4","addListener","event","data","progress","Platform","OS","includes","replace","result","remove","exports"],"sourceRoot":"../../../src","sources":["utils/Downloader.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AADA,MAAMG,oBAAoB,GAAG,IAAIC,+BAAkB,CAACC,gBAAU,CAAC;AAExD,MAAMC,QAAQ,GAAG,MAAAA,CAAOC,OAAe,EAAEC,gBAA6C,EAAEC,eAAwB,KAAmB;EACxI,IAAIC,YAAqC;EACzC,IAAI;IACF,MAAMC,IAAI,GAAG,IAAAC,eAAM,EAAC,CAAC;IACrB,IAAIJ,gBAAgB,EAAE;MACpBE,YAAY,GAAGP,oBAAoB,CAACU,WAAW,CAAC,kBAAkB,EAAGC,KAAU,IAAK;QAClF,IAAIA,KAAK,CAACH,IAAI,KAAKA,IAAI,EAAE;UACvBH,gBAAgB,CAACM,KAAK,CAACC,IAAI,CAACC,QAAQ,CAAC;QACvC;MACF,CAAC,CAAC;IACJ;IACA,IAAIC,qBAAQ,CAACC,EAAE,KAAK,SAAS,IAAIX,OAAO,CAACY,QAAQ,CAAC,SAAS,CAAC,EAAE;MAC5DZ,OAAO,GAAGA,OAAO,CAACa,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;IAC1C;IACA,MAAMC,MAAM,GAAG,MAAMhB,gBAAU,CAACC,QAAQ,CAACC,OAAO,EAAE;MAChDI,IAAI;MACJF;IACF,CAAC,CAAC;IACF,OAAOY,MAAM;EACf,CAAC,SAAS;IACR;IACA,IAAIX,YAAY,EAAE;MAChBA,YAAY,CAACY,MAAM,CAAC,CAAC;IACvB;EACF;AACF,CAAC;AAACC,OAAA,CAAAjB,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
@@ -6,29 +6,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.cancelUpload = exports.backgroundUpload = exports.UploaderHttpMethod = exports.UploadType = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
8
|
var _Main = require("../Main");
|
|
9
|
-
var
|
|
9
|
+
var _helpers = require("./helpers");
|
|
10
10
|
const CompressEventEmitter = new _reactNative.NativeEventEmitter(_Main.Compressor);
|
|
11
|
-
let UploadType = /*#__PURE__*/function (UploadType) {
|
|
11
|
+
let UploadType = exports.UploadType = /*#__PURE__*/function (UploadType) {
|
|
12
12
|
UploadType[UploadType["BINARY_CONTENT"] = 0] = "BINARY_CONTENT";
|
|
13
13
|
UploadType[UploadType["MULTIPART"] = 1] = "MULTIPART";
|
|
14
14
|
return UploadType;
|
|
15
15
|
}({});
|
|
16
|
-
exports.
|
|
17
|
-
let UploaderHttpMethod = /*#__PURE__*/function (UploaderHttpMethod) {
|
|
16
|
+
let UploaderHttpMethod = exports.UploaderHttpMethod = /*#__PURE__*/function (UploaderHttpMethod) {
|
|
18
17
|
UploaderHttpMethod["POST"] = "POST";
|
|
19
18
|
UploaderHttpMethod["PUT"] = "PUT";
|
|
20
19
|
UploaderHttpMethod["PATCH"] = "PATCH";
|
|
21
20
|
return UploaderHttpMethod;
|
|
22
21
|
}({});
|
|
23
|
-
|
|
24
|
-
const cancelUpload = function () {
|
|
25
|
-
let uuid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
26
|
-
let shouldCancelAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
22
|
+
const cancelUpload = (uuid = '', shouldCancelAll = false) => {
|
|
27
23
|
return _Main.Compressor.cancelUpload(uuid, shouldCancelAll);
|
|
28
24
|
};
|
|
29
25
|
exports.cancelUpload = cancelUpload;
|
|
30
26
|
const backgroundUpload = async (url, fileUrl, options, onProgress, abortSignal) => {
|
|
31
|
-
const uuid = (0,
|
|
27
|
+
const uuid = (0, _helpers.uuidv4)();
|
|
32
28
|
let subscription;
|
|
33
29
|
try {
|
|
34
30
|
if (onProgress) {
|
|
@@ -41,10 +37,10 @@ const backgroundUpload = async (url, fileUrl, options, onProgress, abortSignal)
|
|
|
41
37
|
if (_reactNative.Platform.OS === 'android' && fileUrl.includes('file://')) {
|
|
42
38
|
fileUrl = fileUrl.replace('file://', '');
|
|
43
39
|
}
|
|
44
|
-
if (options
|
|
45
|
-
options
|
|
40
|
+
if (options?.getCancellationId) {
|
|
41
|
+
options?.getCancellationId(uuid);
|
|
46
42
|
}
|
|
47
|
-
abortSignal
|
|
43
|
+
abortSignal?.addEventListener('abort', () => cancelUpload(uuid));
|
|
48
44
|
const result = await _Main.Compressor.upload(fileUrl, {
|
|
49
45
|
uuid,
|
|
50
46
|
method: options.httpMethod,
|
|
@@ -59,7 +55,7 @@ const backgroundUpload = async (url, fileUrl, options, onProgress, abortSignal)
|
|
|
59
55
|
if (subscription) {
|
|
60
56
|
subscription.remove();
|
|
61
57
|
}
|
|
62
|
-
abortSignal
|
|
58
|
+
abortSignal?.removeEventListener('abort', () => cancelUpload(uuid));
|
|
63
59
|
}
|
|
64
60
|
};
|
|
65
61
|
exports.backgroundUpload = backgroundUpload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_Main","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_Main","_helpers","CompressEventEmitter","NativeEventEmitter","Compressor","UploadType","exports","UploaderHttpMethod","cancelUpload","uuid","shouldCancelAll","backgroundUpload","url","fileUrl","options","onProgress","abortSignal","uuidv4","subscription","addListener","event","data","written","total","Platform","OS","includes","replace","getCancellationId","addEventListener","result","upload","method","httpMethod","headers","uploadType","remove","removeEventListener"],"sourceRoot":"../../../src","sources":["utils/Uploader.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AADA,MAAMG,oBAAoB,GAAG,IAAIC,+BAAkB,CAACC,gBAAU,CAAC;AAAC,IAEpDC,UAAU,GAAAC,OAAA,CAAAD,UAAA,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAAA,IAKVE,kBAAkB,GAAAD,OAAA,CAAAC,kBAAA,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA;AA+BvB,MAAM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GrB,OAAO;MACVF;IACF,CAAC,CAAC;IACF,OAAOkB,MAAM;EACf,CAAC,SAAS;IACR;IACA,IAAIZ,YAAY,EAAE;MAChBA,YAAY,CAACkB,MAAM,CAAC,CAAC;IACvB;IACApB,WAAW,EAAEqB,mBAAmB,CAAC,OAAO,EAAE,MAAM7B,YAAY,CAACC,IAAI,CAAC,CAAC;EACrE;AACF,CAAC;AAACH,OAAA,CAAAK,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.uuidv4 = void 0;
|
|
7
|
+
const uuidv4 = () => {
|
|
8
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
9
|
+
const r = parseFloat('0.' + Math.random().toString().replace('0.', '') + new Date().getTime()) * 16 | 0,
|
|
10
|
+
// eslint-disable-next-line eqeqeq
|
|
11
|
+
v = c == 'x' ? r : r & 0x3 | 0x8;
|
|
12
|
+
return v.toString(16);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
exports.uuidv4 = uuidv4;
|
|
16
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v","exports"],"sourceRoot":"../../../src","sources":["utils/helpers.ts"],"mappings":";;;;;;AAAO,MAAMA,MAAM,GAAGA,CAAA,KAAM;EAC1B,OAAO,sCAAsC,CAACC,OAAO,CAAC,OAAO,EAAE,UAAUC,CAAC,EAAE;IAC1E,MAAMC,CAAC,GAAIC,UAAU,CAAC,IAAI,GAAGC,IAAI,CAACC,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC,CAACN,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAIO,IAAI,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GAAI,CAAC;MACvG;MACAC,CAAC,GAAGR,CAAC,IAAI,GAAG,GAAGC,CAAC,GAAIA,CAAC,GAAG,GAAG,GAAI,GAAG;IACpC,OAAOO,CAAC,CAACH,QAAQ,CAAC,EAAE,CAAC;EACvB,CAAC,CAAC;AACJ,CAAC;AAACI,OAAA,CAAAX,MAAA,GAAAA,MAAA","ignoreList":[]}
|