react-native-compressor 1.7.2 → 1.8.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 +51 -8
- package/android/build.gradle +9 -0
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioCompressor.kt +527 -0
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioMain.kt +31 -0
- package/android/src/main/java/com/reactnativecompressor/CompressorModule.kt +169 -0
- package/android/src/main/java/com/reactnativecompressor/CompressorPackage.kt +34 -0
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressor.kt +199 -0
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressorOptions.kt +57 -0
- package/android/src/main/java/com/reactnativecompressor/Image/ImageMain.kt +31 -0
- package/android/src/main/java/com/reactnativecompressor/Image/ImageSize.kt +3 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/Downloader.kt +119 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/EventEmitterHandler.kt +66 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/MediaCache.kt +61 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/RealPathUtil.kt +177 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/Uploader.kt +117 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.kt +162 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/createVideoThumbnail.kt +158 -0
- package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression.kt +63 -0
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.kt +125 -0
- package/android/src/main/java/com/reactnativecompressor/Video/VideoMain.kt +86 -0
- package/android/src/newarch/CompressorSpec.kt +5 -0
- package/android/src/oldarch/CompressorSpec.kt +34 -0
- package/ios/Audio/AudioMain.swift +115 -0
- package/ios/Compressor-Bridging-Header.h +1 -2
- package/ios/Compressor.h +0 -8
- package/ios/Compressor.mm +37 -389
- package/ios/CompressorManager.swift +107 -0
- package/ios/Image/ImageCompressor.swift +354 -0
- package/ios/Image/ImageCompressorOptions.swift +93 -0
- package/ios/Image/ImageMain.swift +27 -0
- package/ios/Utils/CreateVideoThumbnail.swift +111 -0
- package/ios/Utils/Downloader.swift +157 -0
- package/ios/Utils/EventEmitterHandler.swift +54 -0
- package/ios/Utils/MediaCache.swift +48 -0
- package/ios/Utils/Uploader.swift +99 -0
- package/ios/Utils/Utils.swift +110 -0
- package/ios/Video/{VideoCompressor.swift → VideoMain.swift} +167 -146
- package/lib/commonjs/Image/index.js +1 -1
- package/lib/commonjs/Image/index.js.map +1 -1
- package/lib/commonjs/Main.js +1 -8
- package/lib/commonjs/Main.js.map +1 -1
- package/lib/commonjs/Spec/NativeCompressor.js.map +1 -1
- package/lib/commonjs/Video/index.js +4 -33
- package/lib/commonjs/Video/index.js.map +1 -1
- package/lib/commonjs/expo-plugin/compressor.js.map +1 -1
- package/lib/commonjs/index.js +25 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/Downloader.js +38 -0
- package/lib/commonjs/utils/Downloader.js.map +1 -0
- package/lib/commonjs/utils/Uploader.js +40 -0
- package/lib/commonjs/utils/Uploader.js.map +1 -0
- package/lib/commonjs/utils/index.js +47 -1
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/Image/index.js +1 -1
- package/lib/module/Image/index.js.map +1 -1
- package/lib/module/Main.js +1 -7
- package/lib/module/Main.js.map +1 -1
- package/lib/module/Spec/NativeCompressor.js.map +1 -1
- package/lib/module/Video/index.js +5 -33
- package/lib/module/Video/index.js.map +1 -1
- package/lib/module/expo-plugin/compressor.js.map +1 -1
- package/lib/module/index.js +9 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/Downloader.js +31 -0
- package/lib/module/utils/Downloader.js.map +1 -0
- package/lib/module/utils/Uploader.js +33 -0
- package/lib/module/utils/Uploader.js.map +1 -0
- package/lib/module/utils/index.js +9 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/Image/index.d.ts +4 -0
- package/lib/typescript/Image/index.d.ts.map +1 -1
- package/lib/typescript/Main.d.ts +1 -2
- package/lib/typescript/Main.d.ts.map +1 -1
- package/lib/typescript/Spec/NativeCompressor.d.ts +16 -2
- package/lib/typescript/Spec/NativeCompressor.d.ts.map +1 -1
- package/lib/typescript/Video/index.d.ts +4 -28
- package/lib/typescript/Video/index.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +7 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/Downloader.d.ts +2 -0
- package/lib/typescript/utils/Downloader.d.ts.map +1 -0
- package/lib/typescript/utils/Uploader.d.ts +28 -0
- package/lib/typescript/utils/Uploader.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +4 -1
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/Image/index.tsx +5 -1
- package/src/Main.tsx +1 -15
- package/src/Spec/NativeCompressor.ts +25 -2
- package/src/Video/index.tsx +11 -84
- package/src/expo-plugin/compressor.ts +1 -1
- package/src/index.tsx +12 -3
- package/src/utils/Downloader.tsx +38 -0
- package/src/utils/Uploader.tsx +78 -0
- package/src/utils/index.tsx +15 -0
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioCompressor.java +0 -605
- package/android/src/main/java/com/reactnativecompressor/CompressorModule.java +0 -220
- package/android/src/main/java/com/reactnativecompressor/CompressorPackage.java +0 -58
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressor.java +0 -257
- package/android/src/main/java/com/reactnativecompressor/Image/utils/ImageCompressorOptions.java +0 -69
- package/android/src/main/java/com/reactnativecompressor/Image/utils/ImageSize.java +0 -13
- package/android/src/main/java/com/reactnativecompressor/Utils/FileUplaoder/FileUploadHelper.java +0 -39
- package/android/src/main/java/com/reactnativecompressor/Utils/FileUplaoder/FileUploader.java +0 -129
- package/android/src/main/java/com/reactnativecompressor/Utils/MediaCache.java +0 -65
- package/android/src/main/java/com/reactnativecompressor/Utils/RealPathUtil.java +0 -210
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.java +0 -272
- package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression/AutoVideoCompression.java +0 -87
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +0 -182
- package/android/src/main/java/com/reactnativecompressor/Video/VideoModule.java +0 -112
- package/android/src/newarch/CompressorSpec.java +0 -9
- package/android/src/newarch/VideoCompressorSpec.java +0 -9
- package/android/src/oldarch/CompressorSpec.java +0 -34
- package/android/src/oldarch/VideoCompressorSpec.java +0 -26
- package/ios/Image/ImageCompressor.h +0 -22
- package/ios/Image/ImageCompressor.m +0 -540
- package/ios/Image/ImageCompressorOptions.h +0 -28
- package/ios/Image/ImageCompressorOptions.m +0 -97
- package/ios/Utils/Downloader.h +0 -16
- package/ios/Utils/Downloader.m +0 -150
- package/ios/Utils/MediaCache.h +0 -11
- package/ios/Utils/MediaCache.m +0 -51
- package/ios/Video/VideoCompressor.h +0 -5
- package/ios/Video/VideoCompressor.m +0 -1
- package/lib/commonjs/Spec/NativeVideoCompressor.js +0 -10
- package/lib/commonjs/Spec/NativeVideoCompressor.js.map +0 -1
- package/lib/module/Spec/NativeVideoCompressor.js +0 -3
- package/lib/module/Spec/NativeVideoCompressor.js.map +0 -1
- package/lib/typescript/Spec/NativeVideoCompressor.d.ts +0 -13
- package/lib/typescript/Spec/NativeVideoCompressor.d.ts.map +0 -1
- package/src/Spec/NativeVideoCompressor.ts +0 -14
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
export declare enum FileSystemUploadType {
|
|
2
|
-
BINARY_CONTENT = 0,
|
|
3
|
-
MULTIPART = 1
|
|
4
|
-
}
|
|
5
|
-
export declare type FileSystemAcceptedUploadHttpMethod = 'POST' | 'PUT' | 'PATCH';
|
|
6
1
|
export type compressionMethod = 'auto' | 'manual';
|
|
7
2
|
type videoCompresssionType = {
|
|
8
3
|
bitrate?: number;
|
|
@@ -11,36 +6,17 @@ type videoCompresssionType = {
|
|
|
11
6
|
minimumFileSizeForCompress?: number;
|
|
12
7
|
getCancellationId?: (cancellationId: string) => void;
|
|
13
8
|
downloadProgress?: (progress: number) => void;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
export declare type HTTPResponse = {
|
|
20
|
-
status: number;
|
|
21
|
-
headers: Record<string, string>;
|
|
22
|
-
body: string;
|
|
23
|
-
};
|
|
24
|
-
export declare type FileSystemUploadOptions = ({
|
|
25
|
-
uploadType?: FileSystemUploadType.BINARY_CONTENT;
|
|
26
|
-
} | {
|
|
27
|
-
uploadType: FileSystemUploadType.MULTIPART;
|
|
28
|
-
fieldName?: string;
|
|
29
|
-
mimeType?: string;
|
|
30
|
-
parameters?: Record<string, string>;
|
|
31
|
-
}) & {
|
|
32
|
-
headers?: Record<string, string>;
|
|
33
|
-
httpMethod?: FileSystemAcceptedUploadHttpMethod;
|
|
34
|
-
sessionType?: FileSystemSessionType;
|
|
9
|
+
/***
|
|
10
|
+
* Default:0, we uses it when we use downloadProgress/onProgress
|
|
11
|
+
*/
|
|
12
|
+
progressDivider?: number;
|
|
35
13
|
};
|
|
36
14
|
export type VideoCompressorType = {
|
|
37
15
|
compress(fileUrl: string, options?: videoCompresssionType, onProgress?: (progress: number) => void): Promise<string>;
|
|
38
16
|
cancelCompression(cancellationId: string): void;
|
|
39
|
-
backgroundUpload(url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: (writtem: number, total: number) => void): Promise<any>;
|
|
40
17
|
activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;
|
|
41
18
|
deactivateBackgroundTask(): Promise<any>;
|
|
42
19
|
};
|
|
43
|
-
export declare const backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
|
|
44
20
|
export declare const cancelCompression: (cancellationId: string) => any;
|
|
45
21
|
declare const Video: VideoCompressorType;
|
|
46
22
|
export default Video;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Video/index.tsx"],"names":[],"mappings":"AAKA,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Video/index.tsx"],"names":[],"mappings":"AAKA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAClD,KAAK,qBAAqB,GAAG;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,iBAAiB,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CACN,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,qBAAqB,EAC/B,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GACtC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,sBAAsB,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACtE,wBAAwB,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;CAC1C,CAAC;AAMF,eAAO,MAAM,iBAAiB,mBAAoB,MAAM,QAEvD,CAAC;AAEF,QAAA,MAAM,KAAK,EAAE,mBAoGW,CAAC;AAEzB,eAAe,KAAK,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Video
|
|
1
|
+
import Video from './Video';
|
|
2
2
|
import type { VideoCompressorType } from './Video';
|
|
3
3
|
import Audio from './Audio';
|
|
4
4
|
import Image from './Image';
|
|
5
|
-
import { getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData, getFileSize } from './utils';
|
|
6
|
-
export { Video, Audio, Image, backgroundUpload, getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData, getFileSize, };
|
|
5
|
+
import { getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData, getFileSize, backgroundUpload, createVideoThumbnail, download, clearCache } from './utils';
|
|
6
|
+
export { Video, Audio, Image, backgroundUpload, download, getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData, createVideoThumbnail, clearCache, getFileSize, };
|
|
7
7
|
export type { VideoCompressorType };
|
|
8
8
|
declare const _default: {
|
|
9
9
|
Video: VideoCompressorType;
|
|
@@ -11,13 +11,16 @@ declare const _default: {
|
|
|
11
11
|
Image: {
|
|
12
12
|
compress(value: string, options?: import("./Image").CompressorOptions | undefined): Promise<string>;
|
|
13
13
|
};
|
|
14
|
-
backgroundUpload: (url: string, fileUrl: string, options: import("./Video").FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
|
|
15
14
|
getDetails: (mediaFullPath: string, extesnion?: "mp3" | "mp4") => Promise<any>;
|
|
16
15
|
uuidv4: () => string;
|
|
17
16
|
generateFilePath: any;
|
|
18
17
|
getRealPath: any;
|
|
19
18
|
getVideoMetaData: any;
|
|
20
19
|
getFileSize: (filePath: string) => Promise<string>;
|
|
20
|
+
backgroundUpload: (url: string, fileUrl: string, options: import("./utils").FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
|
|
21
|
+
createVideoThumbnail: any;
|
|
22
|
+
clearCache: any;
|
|
23
|
+
download: (fileUrl: string, downloadProgress?: ((progress: number) => void) | undefined, progressDivider?: number | undefined) => Promise<any>;
|
|
21
24
|
};
|
|
22
25
|
export default _default;
|
|
23
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,EACL,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,QAAQ,EACR,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,gBAAgB,EAChB,QAAQ,EAER,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,UAAU,EACV,WAAW,GACZ,CAAC;AACF,YAAY,EAAE,mBAAmB,EAAE,CAAC;;;;;;;;;;;;;;;;;;AACpC,wBAcE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Downloader.d.ts","sourceRoot":"","sources":["../../../src/utils/Downloader.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ,YACV,MAAM,iCACe,MAAM,KAAK,IAAI,iCAC3B,MAAM,KACvB,QAAQ,GAAG,CA4Bb,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare enum FileSystemUploadType {
|
|
2
|
+
BINARY_CONTENT = 0,
|
|
3
|
+
MULTIPART = 1
|
|
4
|
+
}
|
|
5
|
+
export declare enum FileSystemSessionType {
|
|
6
|
+
BACKGROUND = 0,
|
|
7
|
+
FOREGROUND = 1
|
|
8
|
+
}
|
|
9
|
+
export declare type HTTPResponse = {
|
|
10
|
+
status: number;
|
|
11
|
+
headers: Record<string, string>;
|
|
12
|
+
body: string;
|
|
13
|
+
};
|
|
14
|
+
export declare type FileSystemAcceptedUploadHttpMethod = 'POST' | 'PUT' | 'PATCH';
|
|
15
|
+
export declare type FileSystemUploadOptions = ({
|
|
16
|
+
uploadType?: FileSystemUploadType.BINARY_CONTENT;
|
|
17
|
+
} | {
|
|
18
|
+
uploadType: FileSystemUploadType.MULTIPART;
|
|
19
|
+
fieldName?: string;
|
|
20
|
+
mimeType?: string;
|
|
21
|
+
parameters?: Record<string, string>;
|
|
22
|
+
}) & {
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
httpMethod?: FileSystemAcceptedUploadHttpMethod;
|
|
25
|
+
sessionType?: FileSystemSessionType;
|
|
26
|
+
};
|
|
27
|
+
export declare const backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
|
|
28
|
+
//# sourceMappingURL=Uploader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Uploader.d.ts","sourceRoot":"","sources":["../../../src/utils/Uploader.tsx"],"names":[],"mappings":"AAKA,MAAM,CAAC,OAAO,MAAM,oBAAoB;IACtC,cAAc,IAAI;IAClB,SAAS,IAAI;CACd;AAED,MAAM,CAAC,OAAO,MAAM,qBAAqB;IACvC,UAAU,IAAI;IACd,UAAU,IAAI;CACf;AAED,MAAM,CAAC,OAAO,MAAM,YAAY,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,CAAC,OAAO,MAAM,kCAAkC,GAClD,MAAM,GACN,KAAK,GACL,OAAO,CAAC;AAEZ,MAAM,CAAC,OAAO,MAAM,uBAAuB,GAAG,CAC1C;IACE,UAAU,CAAC,EAAE,oBAAoB,CAAC,cAAc,CAAC;CAClD,GACD;IACE,UAAU,EAAE,oBAAoB,CAAC,SAAS,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC,CACJ,GAAG;IACF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,UAAU,CAAC,EAAE,kCAAkC,CAAC;IAChD,WAAW,CAAC,EAAE,qBAAqB,CAAC;CACrC,CAAC;AAEF,eAAO,MAAM,gBAAgB,QACtB,MAAM,WACF,MAAM,WACN,uBAAuB,0BACT,MAAM,SAAS,MAAM,KAAK,IAAI,kBACpD,QAAQ,GAAG,CA8Bb,CAAC"}
|
|
@@ -17,9 +17,12 @@ export type AudioType = {
|
|
|
17
17
|
export declare const generateFilePath: any;
|
|
18
18
|
export declare const getRealPath: any;
|
|
19
19
|
export declare const getVideoMetaData: any;
|
|
20
|
+
export declare const createVideoThumbnail: any;
|
|
21
|
+
export declare const clearCache: any;
|
|
20
22
|
export declare const getDetails: (mediaFullPath: string, extesnion?: 'mp3' | 'mp4') => Promise<any | null>;
|
|
21
23
|
export declare const checkUrlAndOptions: (url: string, options: audioCompresssionType) => Promise<defaultResultType>;
|
|
22
24
|
export declare const getFileSize: (filePath: string) => Promise<string>;
|
|
23
25
|
export declare const uuidv4: () => string;
|
|
24
|
-
export
|
|
26
|
+
export * from './Downloader';
|
|
27
|
+
export * from './Uploader';
|
|
25
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,UAAmC,CAAC;AAC9D,KAAK,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAM7C,KAAK,qBAAqB,GAAG;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,qBAI5C,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3E,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,GAM9B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,GAKzB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,GAE9B,CAAC;AA2CF,eAAO,MAAM,UAAU,kBACN,MAAM,cACV,KAAK,GAAG,KAAK,KACvB,QAAQ,GAAG,GAAG,IAAI,CA6BpB,CAAC;AAEF,eAAO,MAAM,kBAAkB,QACxB,MAAM,WACF,qBAAqB,KAC7B,QAAQ,iBAAiB,CAsC3B,CAAC;AAEF,eAAO,MAAM,WAAW,aAAoB,MAAM,KAAG,QAAQ,MAAM,CAElE,CAAC;AAEF,eAAO,MAAM,MAAM,cAclB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,UAAmC,CAAC;AAC9D,KAAK,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAM7C,KAAK,qBAAqB,GAAG;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,qBAI5C,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3E,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,GAM9B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,GAKzB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,GAE9B,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,GAOlC,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,GAExB,CAAC;AA2CF,eAAO,MAAM,UAAU,kBACN,MAAM,cACV,KAAK,GAAG,KAAK,KACvB,QAAQ,GAAG,GAAG,IAAI,CA6BpB,CAAC;AAEF,eAAO,MAAM,kBAAkB,QACxB,MAAM,WACF,qBAAqB,KAC7B,QAAQ,iBAAiB,CAsC3B,CAAC;AAEF,eAAO,MAAM,WAAW,aAAoB,MAAM,KAAG,QAAQ,MAAM,CAElE,CAAC;AAEF,eAAO,MAAM,MAAM,cAclB,CAAC;AACF,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-compressor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "This library compress image, video and audio",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@commitlint/config-conventional": "^17.0.2",
|
|
72
72
|
"@evilmartians/lefthook": "^1.2.2",
|
|
73
|
+
"@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
|
|
73
74
|
"@react-native-community/eslint-config": "^3.0.2",
|
|
74
75
|
"@release-it/conventional-changelog": "^5.0.0",
|
|
75
76
|
"@types/jest": "^28.1.2",
|
|
@@ -77,12 +78,13 @@
|
|
|
77
78
|
"@types/react-native": "0.70.0",
|
|
78
79
|
"commitlint": "^17.0.2",
|
|
79
80
|
"del-cli": "^5.0.0",
|
|
80
|
-
"eslint": "^8.
|
|
81
|
+
"eslint": "^8.46.0",
|
|
81
82
|
"eslint-config-prettier": "^8.5.0",
|
|
82
|
-
"eslint-plugin-
|
|
83
|
+
"eslint-plugin-ft-flow": "^3.0.0",
|
|
84
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
85
|
+
"prettier": "^3.0.1",
|
|
83
86
|
"jest": "^28.1.1",
|
|
84
87
|
"pod-install": "^0.1.0",
|
|
85
|
-
"prettier": "^2.0.5",
|
|
86
88
|
"react": "18.2.0",
|
|
87
89
|
"react-native": "0.72.4",
|
|
88
90
|
"react-native-builder-bob": "^0.20.0",
|
package/src/Image/index.tsx
CHANGED
|
@@ -45,6 +45,10 @@ export type CompressorOptions = {
|
|
|
45
45
|
* it is callback, only trigger when we pass image url from server
|
|
46
46
|
*/
|
|
47
47
|
downloadProgress?: (progress: number) => void;
|
|
48
|
+
/***
|
|
49
|
+
* Default:0, we uses when we use downloadProgress
|
|
50
|
+
*/
|
|
51
|
+
progressDivider?: number;
|
|
48
52
|
};
|
|
49
53
|
|
|
50
54
|
const ImageCompressEventEmitter = new NativeEventEmitter(Compressor);
|
|
@@ -63,10 +67,10 @@ const Image: ImageType = {
|
|
|
63
67
|
);
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
const uuid = uuidv4();
|
|
67
70
|
let subscription: NativeEventSubscription;
|
|
68
71
|
try {
|
|
69
72
|
if (options?.downloadProgress) {
|
|
73
|
+
const uuid = uuidv4();
|
|
70
74
|
//@ts-ignore
|
|
71
75
|
options.uuid = uuid;
|
|
72
76
|
subscription = ImageCompressEventEmitter.addListener(
|
package/src/Main.tsx
CHANGED
|
@@ -12,9 +12,6 @@ const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
|
12
12
|
const CompressorModule = isTurboModuleEnabled
|
|
13
13
|
? require('./Spec/NativeCompressor').default
|
|
14
14
|
: NativeModules.Compressor;
|
|
15
|
-
const VideoCompressorModule = isTurboModuleEnabled
|
|
16
|
-
? require('./Spec/NativeVideoCompressor').default
|
|
17
|
-
: NativeModules.VideoCompressor;
|
|
18
15
|
|
|
19
16
|
const Compressor = CompressorModule
|
|
20
17
|
? CompressorModule
|
|
@@ -27,15 +24,4 @@ const Compressor = CompressorModule
|
|
|
27
24
|
}
|
|
28
25
|
);
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
? VideoCompressorModule
|
|
32
|
-
: new Proxy(
|
|
33
|
-
{},
|
|
34
|
-
{
|
|
35
|
-
get() {
|
|
36
|
-
throw new Error(LINKING_ERROR);
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
export { Compressor, VideoCompressor };
|
|
27
|
+
export { Compressor };
|
|
@@ -2,14 +2,37 @@ import type { TurboModule } from 'react-native';
|
|
|
2
2
|
import { TurboModuleRegistry } from 'react-native';
|
|
3
3
|
|
|
4
4
|
export interface Spec extends TurboModule {
|
|
5
|
+
// Image
|
|
5
6
|
image_compress(imagePath: string, optionMap: Object): Promise<string>;
|
|
7
|
+
// Video
|
|
8
|
+
compress(fileUrl: string, optionMap: Object): Promise<string>;
|
|
9
|
+
cancelCompression(uuid: string): void;
|
|
10
|
+
getVideoMetaData(filePath: string): Promise<string>;
|
|
11
|
+
activateBackgroundTask(options: Object): Promise<string>;
|
|
12
|
+
deactivateBackgroundTask(options: Object): Promise<string>;
|
|
13
|
+
//Audio
|
|
6
14
|
compress_audio(fileUrl: string, optionMap: Object): Promise<string>;
|
|
7
|
-
|
|
15
|
+
// Upload
|
|
16
|
+
upload(fileUrl: string, options: Object): Promise<string>;
|
|
17
|
+
// Download
|
|
18
|
+
download(fileUrl: string, options: Object): Promise<string>;
|
|
19
|
+
// Others
|
|
20
|
+
generateFilePath(_extension: string): Promise<string>;
|
|
8
21
|
getRealPath(path: string, type: string): Promise<string>;
|
|
9
|
-
getVideoMetaData(filePath: string): Promise<string>;
|
|
10
22
|
getFileSize(filePath: string): Promise<string>;
|
|
11
23
|
addListener(eventName: string): void;
|
|
12
24
|
removeListeners(count: number): void;
|
|
25
|
+
createVideoThumbnail(
|
|
26
|
+
fileUrl: string,
|
|
27
|
+
options: Object
|
|
28
|
+
): Promise<{
|
|
29
|
+
path: string;
|
|
30
|
+
size: number;
|
|
31
|
+
mime: string;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
}>;
|
|
35
|
+
clearCache(cacheDir: string | null): Promise<string>;
|
|
13
36
|
}
|
|
14
37
|
|
|
15
38
|
export default TurboModuleRegistry.getEnforcing<Spec>('Compressor');
|
package/src/Video/index.tsx
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import { NativeEventEmitter
|
|
1
|
+
import { NativeEventEmitter } from 'react-native';
|
|
2
2
|
import type { NativeEventSubscription } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { Compressor } from '../Main';
|
|
4
4
|
import { uuidv4 } from '../utils';
|
|
5
5
|
|
|
6
|
-
export declare enum FileSystemUploadType {
|
|
7
|
-
BINARY_CONTENT = 0,
|
|
8
|
-
MULTIPART = 1,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export declare type FileSystemAcceptedUploadHttpMethod =
|
|
12
|
-
| 'POST'
|
|
13
|
-
| 'PUT'
|
|
14
|
-
| 'PATCH';
|
|
15
6
|
export type compressionMethod = 'auto' | 'manual';
|
|
16
7
|
type videoCompresssionType = {
|
|
17
8
|
bitrate?: number;
|
|
@@ -20,33 +11,10 @@ type videoCompresssionType = {
|
|
|
20
11
|
minimumFileSizeForCompress?: number;
|
|
21
12
|
getCancellationId?: (cancellationId: string) => void;
|
|
22
13
|
downloadProgress?: (progress: number) => void;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
FOREGROUND = 1,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export declare type HTTPResponse = {
|
|
31
|
-
status: number;
|
|
32
|
-
headers: Record<string, string>;
|
|
33
|
-
body: string;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export declare type FileSystemUploadOptions = (
|
|
37
|
-
| {
|
|
38
|
-
uploadType?: FileSystemUploadType.BINARY_CONTENT;
|
|
39
|
-
}
|
|
40
|
-
| {
|
|
41
|
-
uploadType: FileSystemUploadType.MULTIPART;
|
|
42
|
-
fieldName?: string;
|
|
43
|
-
mimeType?: string;
|
|
44
|
-
parameters?: Record<string, string>;
|
|
45
|
-
}
|
|
46
|
-
) & {
|
|
47
|
-
headers?: Record<string, string>;
|
|
48
|
-
httpMethod?: FileSystemAcceptedUploadHttpMethod;
|
|
49
|
-
sessionType?: FileSystemSessionType;
|
|
14
|
+
/***
|
|
15
|
+
* Default:0, we uses it when we use downloadProgress/onProgress
|
|
16
|
+
*/
|
|
17
|
+
progressDivider?: number;
|
|
50
18
|
};
|
|
51
19
|
|
|
52
20
|
export type VideoCompressorType = {
|
|
@@ -56,56 +24,13 @@ export type VideoCompressorType = {
|
|
|
56
24
|
onProgress?: (progress: number) => void
|
|
57
25
|
): Promise<string>;
|
|
58
26
|
cancelCompression(cancellationId: string): void;
|
|
59
|
-
backgroundUpload(
|
|
60
|
-
url: string,
|
|
61
|
-
fileUrl: string,
|
|
62
|
-
options: FileSystemUploadOptions,
|
|
63
|
-
onProgress?: (writtem: number, total: number) => void
|
|
64
|
-
): Promise<any>;
|
|
65
27
|
activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;
|
|
66
28
|
deactivateBackgroundTask(): Promise<any>;
|
|
67
29
|
};
|
|
68
30
|
|
|
69
|
-
const VideoCompressEventEmitter = new NativeEventEmitter(
|
|
70
|
-
|
|
71
|
-
const NativeVideoCompressor = VideoCompressor;
|
|
31
|
+
const VideoCompressEventEmitter = new NativeEventEmitter(Compressor);
|
|
72
32
|
|
|
73
|
-
|
|
74
|
-
url: string,
|
|
75
|
-
fileUrl: string,
|
|
76
|
-
options: FileSystemUploadOptions,
|
|
77
|
-
onProgress?: (writtem: number, total: number) => void
|
|
78
|
-
): Promise<any> => {
|
|
79
|
-
const uuid = uuidv4();
|
|
80
|
-
let subscription: NativeEventSubscription;
|
|
81
|
-
try {
|
|
82
|
-
if (onProgress) {
|
|
83
|
-
subscription = VideoCompressEventEmitter.addListener(
|
|
84
|
-
'VideoCompressorProgress',
|
|
85
|
-
(event: any) => {
|
|
86
|
-
if (event.uuid === uuid) {
|
|
87
|
-
onProgress(event.data.written, event.data.total);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
if (Platform.OS === 'android' && fileUrl.includes('file://')) {
|
|
93
|
-
fileUrl = fileUrl.replace('file://', '');
|
|
94
|
-
}
|
|
95
|
-
const result = await NativeVideoCompressor.upload(fileUrl, {
|
|
96
|
-
uuid,
|
|
97
|
-
method: options.httpMethod,
|
|
98
|
-
headers: options.headers,
|
|
99
|
-
url,
|
|
100
|
-
});
|
|
101
|
-
return result;
|
|
102
|
-
} finally {
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
if (subscription) {
|
|
105
|
-
subscription.remove();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
33
|
+
const NativeVideoCompressor = Compressor;
|
|
109
34
|
|
|
110
35
|
export const cancelCompression = (cancellationId: string) => {
|
|
111
36
|
return NativeVideoCompressor.cancelCompression(cancellationId);
|
|
@@ -152,7 +77,10 @@ const Video: VideoCompressorType = {
|
|
|
152
77
|
compressionMethod?: compressionMethod;
|
|
153
78
|
maxSize?: number;
|
|
154
79
|
minimumFileSizeForCompress?: number;
|
|
80
|
+
progressDivider?: number;
|
|
155
81
|
} = { uuid };
|
|
82
|
+
if (options?.progressDivider)
|
|
83
|
+
modifiedOptions.progressDivider = options?.progressDivider;
|
|
156
84
|
if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;
|
|
157
85
|
if (options?.compressionMethod) {
|
|
158
86
|
modifiedOptions.compressionMethod = options?.compressionMethod;
|
|
@@ -188,7 +116,6 @@ const Video: VideoCompressorType = {
|
|
|
188
116
|
}
|
|
189
117
|
}
|
|
190
118
|
},
|
|
191
|
-
backgroundUpload,
|
|
192
119
|
cancelCompression,
|
|
193
120
|
activateBackgroundTask(onExpired?) {
|
|
194
121
|
if (onExpired) {
|
|
@@ -4,6 +4,6 @@ const pkg = require('../../../package.json');
|
|
|
4
4
|
|
|
5
5
|
type Props = {};
|
|
6
6
|
|
|
7
|
-
const withCompressor: ConfigPlugin<Props> = (config:any) => config;
|
|
7
|
+
const withCompressor: ConfigPlugin<Props> = (config: any) => config;
|
|
8
8
|
|
|
9
9
|
export default createRunOncePlugin(withCompressor, pkg.name, pkg.version);
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Video
|
|
1
|
+
import Video from './Video';
|
|
2
2
|
import type { VideoCompressorType } from './Video';
|
|
3
3
|
import Audio from './Audio';
|
|
4
4
|
import Image from './Image';
|
|
@@ -9,6 +9,10 @@ import {
|
|
|
9
9
|
getRealPath,
|
|
10
10
|
getVideoMetaData,
|
|
11
11
|
getFileSize,
|
|
12
|
+
backgroundUpload,
|
|
13
|
+
createVideoThumbnail,
|
|
14
|
+
download,
|
|
15
|
+
clearCache,
|
|
12
16
|
} from './utils';
|
|
13
17
|
|
|
14
18
|
export {
|
|
@@ -16,13 +20,15 @@ export {
|
|
|
16
20
|
Audio,
|
|
17
21
|
Image,
|
|
18
22
|
backgroundUpload,
|
|
23
|
+
download,
|
|
19
24
|
//type
|
|
20
|
-
|
|
21
25
|
getDetails,
|
|
22
26
|
uuidv4,
|
|
23
27
|
generateFilePath,
|
|
24
28
|
getRealPath,
|
|
25
29
|
getVideoMetaData,
|
|
30
|
+
createVideoThumbnail,
|
|
31
|
+
clearCache,
|
|
26
32
|
getFileSize,
|
|
27
33
|
};
|
|
28
34
|
export type { VideoCompressorType };
|
|
@@ -30,11 +36,14 @@ export default {
|
|
|
30
36
|
Video,
|
|
31
37
|
Audio,
|
|
32
38
|
Image,
|
|
33
|
-
backgroundUpload,
|
|
34
39
|
getDetails,
|
|
35
40
|
uuidv4,
|
|
36
41
|
generateFilePath,
|
|
37
42
|
getRealPath,
|
|
38
43
|
getVideoMetaData,
|
|
39
44
|
getFileSize,
|
|
45
|
+
backgroundUpload,
|
|
46
|
+
createVideoThumbnail,
|
|
47
|
+
clearCache,
|
|
48
|
+
download,
|
|
40
49
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { NativeEventEmitter, Platform } from 'react-native';
|
|
2
|
+
import type { NativeEventSubscription } from 'react-native';
|
|
3
|
+
import { Compressor } from '../Main';
|
|
4
|
+
const CompressEventEmitter = new NativeEventEmitter(Compressor);
|
|
5
|
+
import { uuidv4 } from './index';
|
|
6
|
+
export const download = async (
|
|
7
|
+
fileUrl: string,
|
|
8
|
+
downloadProgress?: (progress: number) => void,
|
|
9
|
+
progressDivider?: number
|
|
10
|
+
): Promise<any> => {
|
|
11
|
+
let subscription: NativeEventSubscription;
|
|
12
|
+
try {
|
|
13
|
+
const uuid = uuidv4();
|
|
14
|
+
if (downloadProgress) {
|
|
15
|
+
subscription = CompressEventEmitter.addListener(
|
|
16
|
+
'downloadProgress',
|
|
17
|
+
(event: any) => {
|
|
18
|
+
if (event.uuid === uuid) {
|
|
19
|
+
downloadProgress(event.data.progress);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
if (Platform.OS === 'android' && fileUrl.includes('file://')) {
|
|
25
|
+
fileUrl = fileUrl.replace('file://', '');
|
|
26
|
+
}
|
|
27
|
+
const result = await Compressor.download(fileUrl, {
|
|
28
|
+
uuid,
|
|
29
|
+
progressDivider,
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
32
|
+
} finally {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
if (subscription) {
|
|
35
|
+
subscription.remove();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { NativeEventEmitter, Platform } from 'react-native';
|
|
2
|
+
import type { NativeEventSubscription } from 'react-native';
|
|
3
|
+
import { Compressor } from '../Main';
|
|
4
|
+
const CompressEventEmitter = new NativeEventEmitter(Compressor);
|
|
5
|
+
import { uuidv4 } from '.';
|
|
6
|
+
export declare enum FileSystemUploadType {
|
|
7
|
+
BINARY_CONTENT = 0,
|
|
8
|
+
MULTIPART = 1,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare enum FileSystemSessionType {
|
|
12
|
+
BACKGROUND = 0,
|
|
13
|
+
FOREGROUND = 1,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare type HTTPResponse = {
|
|
17
|
+
status: number;
|
|
18
|
+
headers: Record<string, string>;
|
|
19
|
+
body: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export declare type FileSystemAcceptedUploadHttpMethod =
|
|
23
|
+
| 'POST'
|
|
24
|
+
| 'PUT'
|
|
25
|
+
| 'PATCH';
|
|
26
|
+
|
|
27
|
+
export declare type FileSystemUploadOptions = (
|
|
28
|
+
| {
|
|
29
|
+
uploadType?: FileSystemUploadType.BINARY_CONTENT;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
uploadType: FileSystemUploadType.MULTIPART;
|
|
33
|
+
fieldName?: string;
|
|
34
|
+
mimeType?: string;
|
|
35
|
+
parameters?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
) & {
|
|
38
|
+
headers?: Record<string, string>;
|
|
39
|
+
httpMethod?: FileSystemAcceptedUploadHttpMethod;
|
|
40
|
+
sessionType?: FileSystemSessionType;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const backgroundUpload = async (
|
|
44
|
+
url: string,
|
|
45
|
+
fileUrl: string,
|
|
46
|
+
options: FileSystemUploadOptions,
|
|
47
|
+
onProgress?: (writtem: number, total: number) => void
|
|
48
|
+
): Promise<any> => {
|
|
49
|
+
const uuid = uuidv4();
|
|
50
|
+
let subscription: NativeEventSubscription;
|
|
51
|
+
try {
|
|
52
|
+
if (onProgress) {
|
|
53
|
+
subscription = CompressEventEmitter.addListener(
|
|
54
|
+
'uploadProgress',
|
|
55
|
+
(event: any) => {
|
|
56
|
+
if (event.uuid === uuid) {
|
|
57
|
+
onProgress(event.data.written, event.data.total);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (Platform.OS === 'android' && fileUrl.includes('file://')) {
|
|
63
|
+
fileUrl = fileUrl.replace('file://', '');
|
|
64
|
+
}
|
|
65
|
+
const result = await Compressor.upload(fileUrl, {
|
|
66
|
+
uuid,
|
|
67
|
+
method: options.httpMethod,
|
|
68
|
+
headers: options.headers,
|
|
69
|
+
url,
|
|
70
|
+
});
|
|
71
|
+
return result;
|
|
72
|
+
} finally {
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
if (subscription) {
|
|
75
|
+
subscription.remove();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
package/src/utils/index.tsx
CHANGED
|
@@ -49,6 +49,19 @@ export const getVideoMetaData: any = (path: string) => {
|
|
|
49
49
|
return Compressor.getVideoMetaData(path);
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
export const createVideoThumbnail: any = (
|
|
53
|
+
url: string,
|
|
54
|
+
options: {
|
|
55
|
+
headers?: object;
|
|
56
|
+
} = {}
|
|
57
|
+
) => {
|
|
58
|
+
return Compressor.createVideoThumbnail(url, options);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const clearCache: any = (cacheDir?: string) => {
|
|
62
|
+
return Compressor.clearCache(cacheDir);
|
|
63
|
+
};
|
|
64
|
+
|
|
52
65
|
const isValidUrl = (url: string) =>
|
|
53
66
|
/^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(url);
|
|
54
67
|
|
|
@@ -186,3 +199,5 @@ export const uuidv4 = () => {
|
|
|
186
199
|
return v.toString(16);
|
|
187
200
|
});
|
|
188
201
|
};
|
|
202
|
+
export * from './Downloader';
|
|
203
|
+
export * from './Uploader';
|