react-native-compressor 0.5.5 → 1.0.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/android/.gradle/6.1.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_0_2_aar.xml +4 -0
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_asynclayoutinflater_asynclayoutinflater_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_0_0_aar.xml +4 -0
- package/android/.idea/libraries/Gradle__androidx_core_core_1_0_1_aar.xml +4 -0
- package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_documentfile_documentfile_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +3 -0
- package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_0_0_aar.xml +3 -0
- package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_ui_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_utils_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_localbroadcastmanager_localbroadcastmanager_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_print_print_1_0_0_aar.xml +3 -0
- package/android/.idea/libraries/Gradle__androidx_slidingpanelayout_slidingpanelayout_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_swiperefreshlayout_swiperefreshlayout_1_0_0_aar.xml +3 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_0_1_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_drawee_2_0_0_aar.xml +3 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fbcore_2_0_0_aar.xml +3 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fresco_2_0_0_aar.xml +3 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_2_0_0_aar.xml +3 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_base_2_0_0_aar.xml +3 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_okhttp3_2_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagefilters_2_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagetranscoder_2_0_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__com_facebook_react_react_native_0_63_4_aar.xml +4 -0
- package/android/.idea/libraries/Gradle__com_facebook_soloader_soloader_0_9_0_aar.xml +2 -0
- package/android/.idea/libraries/Gradle__com_zolad_videoslimmer_1_0_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__io_github_lizhangqu_coreprogress_1_0_2_aar.xml +15 -0
- package/android/.idea/modules/android.iml +4 -1
- package/android/build.gradle +1 -1
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/lib/commonjs/Video/index.js +43 -34
- package/lib/commonjs/Video/index.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Video/index.js +39 -33
- package/lib/module/Video/index.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/Video/index.d.ts +1 -0
- package/lib/typescript/index.d.ts +3 -2
- package/package.json +3 -3
- package/react-native-compressor.podspec +1 -1
- package/src/Video/index.tsx +55 -38
- package/src/index.tsx +3 -1
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk7_1_3_72.xml +0 -13
package/android/build.gradle
CHANGED
|
@@ -58,6 +58,6 @@ dependencies {
|
|
|
58
58
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0"
|
|
59
59
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.0"
|
|
60
60
|
implementation "com.googlecode.mp4parser:isoparser:1.0.6"
|
|
61
|
-
implementation 'com.zolad:
|
|
61
|
+
implementation 'com.github.zolad:VideoSlimmer:master-SNAPSHOT'
|
|
62
62
|
implementation 'io.github.lizhangqu:coreprogress:1.0.2'
|
|
63
63
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
distributionBase=GRADLE_USER_HOME
|
|
2
2
|
distributionPath=wrapper/dists
|
|
3
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.
|
|
3
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
|
|
4
4
|
zipStoreBase=GRADLE_USER_HOME
|
|
5
5
|
zipStorePath=wrapper/dists
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.backgroundUpload = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
@@ -11,10 +11,44 @@ var _uuid = require("uuid");
|
|
|
11
11
|
|
|
12
12
|
const VideoCompressEventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.VideoCompressor);
|
|
13
13
|
const NativeVideoCompressor = _reactNative.NativeModules.VideoCompressor;
|
|
14
|
+
|
|
15
|
+
const backgroundUpload = async (url, fileUrl, options, onProgress) => {
|
|
16
|
+
const uuid = (0, _uuid.v4)();
|
|
17
|
+
let subscription;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
if (onProgress) {
|
|
21
|
+
subscription = VideoCompressEventEmitter.addListener('VideoCompressorProgress', event => {
|
|
22
|
+
if (event.uuid === uuid) {
|
|
23
|
+
onProgress(event.data.written, event.data.total);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (_reactNative.Platform.OS === 'android' && fileUrl.includes('file://')) {
|
|
29
|
+
fileUrl = fileUrl.replace('file://', '');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const result = await NativeVideoCompressor.upload(fileUrl, {
|
|
33
|
+
uuid,
|
|
34
|
+
method: options.httpMethod,
|
|
35
|
+
headers: options.headers,
|
|
36
|
+
url
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
} finally {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
if (subscription) {
|
|
42
|
+
subscription.remove();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.backgroundUpload = backgroundUpload;
|
|
14
48
|
const Video = {
|
|
15
49
|
compress: async (fileUrl, options, onProgress) => {
|
|
16
50
|
const uuid = (0, _uuid.v4)();
|
|
17
|
-
let subscription
|
|
51
|
+
let subscription;
|
|
18
52
|
|
|
19
53
|
try {
|
|
20
54
|
if (onProgress) {
|
|
@@ -45,47 +79,22 @@ const Video = {
|
|
|
45
79
|
const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
|
|
46
80
|
return result;
|
|
47
81
|
} finally {
|
|
82
|
+
// @ts-ignore
|
|
48
83
|
if (subscription) {
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
backgroundUpload: async (url, fileUrl, options, onProgress) => {
|
|
54
|
-
const uuid = (0, _uuid.v4)();
|
|
55
|
-
let subscription = null;
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
if (onProgress) {
|
|
59
|
-
subscription = VideoCompressEventEmitter.addListener('VideoCompressorProgress', event => {
|
|
60
|
-
if (event.uuid === uuid) {
|
|
61
|
-
onProgress(event.data.written, event.data.total);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (_reactNative.Platform.OS === 'android' && fileUrl.includes('file://')) {
|
|
67
|
-
fileUrl = fileUrl.replace('file://', '');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const result = await NativeVideoCompressor.upload(fileUrl, {
|
|
71
|
-
uuid,
|
|
72
|
-
method: options.httpMethod,
|
|
73
|
-
headers: options.headers,
|
|
74
|
-
url
|
|
75
|
-
});
|
|
76
|
-
return result;
|
|
77
|
-
} finally {
|
|
78
|
-
if (subscription) {
|
|
79
|
-
VideoCompressEventEmitter.removeSubscription(subscription);
|
|
84
|
+
subscription.remove();
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
},
|
|
88
|
+
backgroundUpload,
|
|
83
89
|
|
|
84
90
|
activateBackgroundTask(onExpired) {
|
|
85
91
|
if (onExpired) {
|
|
86
92
|
const subscription = VideoCompressEventEmitter.addListener('backgroundTaskExpired', event => {
|
|
87
93
|
onExpired(event);
|
|
88
|
-
|
|
94
|
+
|
|
95
|
+
if (subscription) {
|
|
96
|
+
subscription.remove();
|
|
97
|
+
}
|
|
89
98
|
});
|
|
90
99
|
}
|
|
91
100
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["VideoCompressEventEmitter","NativeEventEmitter","NativeModules","VideoCompressor","NativeVideoCompressor","
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["VideoCompressEventEmitter","NativeEventEmitter","NativeModules","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","Platform","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":";;;;;;;AAAA;;AAMA;;AA4DA,MAAMA,yBAAyB,GAAG,IAAIC,+BAAJ,CAChCC,2BAAcC,eADkB,CAAlC;AAIA,MAAMC,qBAAqB,GAAGF,2BAAcC,eAA5C;;AAEO,MAAME,gBAAgB,GAAG,OAC9BC,GAD8B,EAE9BC,OAF8B,EAG9BC,OAH8B,EAI9BC,UAJ8B,KAKb;AACjB,QAAMC,IAAI,GAAG,eAAb;AACA,MAAIC,YAAJ;;AACA,MAAI;AACF,QAAIF,UAAJ,EAAgB;AACdE,MAAAA,YAAY,GAAGX,yBAAyB,CAACY,WAA1B,CACb,yBADa,EAEZC,KAAD,IAAgB;AACd,YAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,UAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWC,OAAZ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AACD;;AAvEgC,CAAnC;eA0EeT,K","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport { v4 as uuidv4 } from 'uuid';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'VideoCompressorProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.written, event.data.total);\n }\n }\n );\n }\n if (Platform.OS === 'android' && fileUrl.includes('file://')) {\n fileUrl = fileUrl.replace('file://', '');\n }\n const result = await NativeVideoCompressor.upload(fileUrl, {\n uuid,\n method: options.httpMethod,\n headers: options.headers,\n url,\n });\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n },\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'videoCompressProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.progress);\n }\n }\n );\n }\n const modifiedOptions: {\n uuid: string;\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n } = { uuid };\n if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;\n if (options?.compressionMethod) {\n modifiedOptions.compressionMethod = options?.compressionMethod;\n } else {\n modifiedOptions.compressionMethod = 'manual';\n }\n if (options?.maxSize) {\n modifiedOptions.maxSize = options?.maxSize;\n } else {\n modifiedOptions.maxSize = 640;\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription: NativeEventSubscription =\n VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n if (subscription) {\n subscription.remove();\n }\n }\n );\n }\n return NativeVideoCompressor.activateBackgroundTask({});\n },\n deactivateBackgroundTask() {\n VideoCompressEventEmitter.removeAllListeners('backgroundTaskExpired');\n return NativeVideoCompressor.deactivateBackgroundTask({});\n },\n} as VideoCompressorType;\n\nexport default Video;\n"]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "VideoCompressorType", {
|
|
|
15
15
|
return _Video.VideoCompressorType;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "backgroundUpload", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _Video.backgroundUpload;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "Audio", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
@@ -53,6 +59,7 @@ var _default = {
|
|
|
53
59
|
Video: _Video.default,
|
|
54
60
|
Audio: _Audio.default,
|
|
55
61
|
Image: _Image.default,
|
|
62
|
+
backgroundUpload: _Video.backgroundUpload,
|
|
56
63
|
getDetails: _utils.getDetails
|
|
57
64
|
};
|
|
58
65
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","getDetails"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","backgroundUpload","getDetails"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;eAWe;AACbA,EAAAA,KAAK,EAALA,cADa;AAEbC,EAAAA,KAAK,EAALA,cAFa;AAGbC,EAAAA,KAAK,EAALA,cAHa;AAIbC,EAAAA,gBAAgB,EAAhBA,uBAJa;AAKbC,EAAAA,UAAU,EAAVA;AALa,C","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n};\n"]}
|
|
@@ -2,10 +2,41 @@ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
|
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
const VideoCompressEventEmitter = new NativeEventEmitter(NativeModules.VideoCompressor);
|
|
4
4
|
const NativeVideoCompressor = NativeModules.VideoCompressor;
|
|
5
|
+
export const backgroundUpload = async (url, fileUrl, options, onProgress) => {
|
|
6
|
+
const uuid = uuidv4();
|
|
7
|
+
let subscription;
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
if (onProgress) {
|
|
11
|
+
subscription = VideoCompressEventEmitter.addListener('VideoCompressorProgress', event => {
|
|
12
|
+
if (event.uuid === uuid) {
|
|
13
|
+
onProgress(event.data.written, event.data.total);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (Platform.OS === 'android' && fileUrl.includes('file://')) {
|
|
19
|
+
fileUrl = fileUrl.replace('file://', '');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const result = await NativeVideoCompressor.upload(fileUrl, {
|
|
23
|
+
uuid,
|
|
24
|
+
method: options.httpMethod,
|
|
25
|
+
headers: options.headers,
|
|
26
|
+
url
|
|
27
|
+
});
|
|
28
|
+
return result;
|
|
29
|
+
} finally {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
if (subscription) {
|
|
32
|
+
subscription.remove();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
5
36
|
const Video = {
|
|
6
37
|
compress: async (fileUrl, options, onProgress) => {
|
|
7
38
|
const uuid = uuidv4();
|
|
8
|
-
let subscription
|
|
39
|
+
let subscription;
|
|
9
40
|
|
|
10
41
|
try {
|
|
11
42
|
if (onProgress) {
|
|
@@ -36,47 +67,22 @@ const Video = {
|
|
|
36
67
|
const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
|
|
37
68
|
return result;
|
|
38
69
|
} finally {
|
|
70
|
+
// @ts-ignore
|
|
39
71
|
if (subscription) {
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
backgroundUpload: async (url, fileUrl, options, onProgress) => {
|
|
45
|
-
const uuid = uuidv4();
|
|
46
|
-
let subscription = null;
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
if (onProgress) {
|
|
50
|
-
subscription = VideoCompressEventEmitter.addListener('VideoCompressorProgress', event => {
|
|
51
|
-
if (event.uuid === uuid) {
|
|
52
|
-
onProgress(event.data.written, event.data.total);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (Platform.OS === 'android' && fileUrl.includes('file://')) {
|
|
58
|
-
fileUrl = fileUrl.replace('file://', '');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const result = await NativeVideoCompressor.upload(fileUrl, {
|
|
62
|
-
uuid,
|
|
63
|
-
method: options.httpMethod,
|
|
64
|
-
headers: options.headers,
|
|
65
|
-
url
|
|
66
|
-
});
|
|
67
|
-
return result;
|
|
68
|
-
} finally {
|
|
69
|
-
if (subscription) {
|
|
70
|
-
VideoCompressEventEmitter.removeSubscription(subscription);
|
|
72
|
+
subscription.remove();
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
},
|
|
76
|
+
backgroundUpload,
|
|
74
77
|
|
|
75
78
|
activateBackgroundTask(onExpired) {
|
|
76
79
|
if (onExpired) {
|
|
77
80
|
const subscription = VideoCompressEventEmitter.addListener('backgroundTaskExpired', event => {
|
|
78
81
|
onExpired(event);
|
|
79
|
-
|
|
82
|
+
|
|
83
|
+
if (subscription) {
|
|
84
|
+
subscription.remove();
|
|
85
|
+
}
|
|
80
86
|
});
|
|
81
87
|
}
|
|
82
88
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","v4","uuidv4","VideoCompressEventEmitter","VideoCompressor","NativeVideoCompressor","
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","v4","uuidv4","VideoCompressEventEmitter","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":"AAAA,SACEA,aADF,EAEEC,kBAFF,EAGEC,QAHF,QAKO,cALP;AAMA,SAASC,EAAE,IAAIC,MAAf,QAA6B,MAA7B;AA4DA,MAAMC,yBAAyB,GAAG,IAAIJ,kBAAJ,CAChCD,aAAa,CAACM,eADkB,CAAlC;AAIA,MAAMC,qBAAqB,GAAGP,aAAa,CAACM,eAA5C;AAEA,OAAO,MAAME,gBAAgB,GAAG,OAC9BC,GAD8B,EAE9BC,OAF8B,EAG9BC,OAH8B,EAI9BC,UAJ8B,KAKb;AACjB,QAAMC,IAAI,GAAGT,MAAM,EAAnB;AACA,MAAIU,YAAJ;;AACA,MAAI;AACF,QAAIF,UAAJ,EAAgB;AACdE,MAAAA,YAAY,GAAGT,yBAAyB,CAACU,WAA1B,CACb,yBADa,EAEZC,KAAD,IAAgB;AACd,YAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,UAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWC,OAAZ,EAAqBF,KAAK,CAACC,IAAN,CAAWE,KAAhC,CAAV;AACD;AACF,OANY,CAAf;AAQD;;AACD,QAAIjB,QAAQ,CAACkB,EAAT,KAAgB,SAAhB,IAA6BV,OAAO,CAACW,QAAR,CAAiB,SAAjB,CAAjC,EAA8D;AAC5DX,MAAAA,OAAO,GAAGA,OAAO,CAACY,OAAR,CAAgB,SAAhB,EAA2B,EAA3B,CAAV;AACD;;AACD,UAAMC,MAAM,GAAG,MAAMhB,qBAAqB,CAACiB,MAAtB,CAA6Bd,OAA7B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QAAAA,eAAe,CAACG,OAAhB,GAA0BxB,OAA1B,aAA0BA,OAA1B,uBAA0BA,OAAO,CAAEwB,OAAnC;AACD,OAFD,MAEO;AACLH,QAAAA,eAAe,CAACG,OAAhB,GAA0B,GAA1B;AACD;;AACD,YAAMZ,MAAM,GAAG,MAAMhB,qBAAqB,CAACuB,QAAtB,CACnBpB,OADmB,EAEnBsB,eAFmB,CAArB;AAIA,aAAOT,MAAP;AACD,KAjCD,SAiCU;AACR;AACA,UAAIT,YAAJ,EAAkB;AAChBA,QAAAA,YAAY,CAACc,MAAb;AACD;AACF;AACF,GAnDgC;AAoDjCpB,EAAAA,gBApDiC;;AAqDjC4B,EAAAA,sBAAsB,CAACC,SAAD,EAAa;AACjC,QAAIA,SAAJ,EAAe;AACb,YAAMvB,YAAqC,GACzCT,yBAAyB,CAACU,WAA1B,CACE,uBADF,EAEGC,KAAD,IAAgB;AACdqB,QAAAA,SAAS,CAACrB,KAAD,CAAT;;AACA,YAAIF,YAAJ,EAAkB;AAChBA,UAAAA,YAAY,CAACc,MAAb;AACD;AACF,OAPH,CADF;AAUD;;AACD,WAAOrB,qBAAqB,CAAC6B,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAnEgC;;AAoEjCE,EAAAA,wBAAwB,GAAG;AACzBjC,IAAAA,yBAAyB,CAACkC,kBAA1B,CAA6C,uBAA7C;AACA,WAAOhC,qBAAqB,CAAC+B,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AAvEgC,CAAnC;AA0EA,eAAeT,KAAf","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport { v4 as uuidv4 } from 'uuid';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'VideoCompressorProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.written, event.data.total);\n }\n }\n );\n }\n if (Platform.OS === 'android' && fileUrl.includes('file://')) {\n fileUrl = fileUrl.replace('file://', '');\n }\n const result = await NativeVideoCompressor.upload(fileUrl, {\n uuid,\n method: options.httpMethod,\n headers: options.headers,\n url,\n });\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n },\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'videoCompressProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.progress);\n }\n }\n );\n }\n const modifiedOptions: {\n uuid: string;\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n } = { uuid };\n if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;\n if (options?.compressionMethod) {\n modifiedOptions.compressionMethod = options?.compressionMethod;\n } else {\n modifiedOptions.compressionMethod = 'manual';\n }\n if (options?.maxSize) {\n modifiedOptions.maxSize = options?.maxSize;\n } else {\n modifiedOptions.maxSize = 640;\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription: NativeEventSubscription =\n VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n if (subscription) {\n subscription.remove();\n }\n }\n );\n }\n return NativeVideoCompressor.activateBackgroundTask({});\n },\n deactivateBackgroundTask() {\n VideoCompressEventEmitter.removeAllListeners('backgroundTaskExpired');\n return NativeVideoCompressor.deactivateBackgroundTask({});\n },\n} as VideoCompressorType;\n\nexport default Video;\n"]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import Video, { VideoCompressorType } from './Video';
|
|
1
|
+
import Video, { VideoCompressorType, backgroundUpload } from './Video';
|
|
2
2
|
import Audio from './Audio';
|
|
3
3
|
import Image from './Image';
|
|
4
4
|
import { getDetails } from './utils';
|
|
5
|
-
export { Video, Audio, Image //type
|
|
5
|
+
export { Video, Audio, Image, backgroundUpload //type
|
|
6
6
|
, VideoCompressorType, getDetails };
|
|
7
7
|
export default {
|
|
8
8
|
Video,
|
|
9
9
|
Audio,
|
|
10
10
|
Image,
|
|
11
|
+
backgroundUpload,
|
|
11
12
|
getDetails
|
|
12
13
|
};
|
|
13
14
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","Audio","Image","getDetails"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","backgroundUpload","Audio","Image","getDetails"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,EAAqCC,gBAArC,QAA6D,SAA7D;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,UAAT,QAA2B,SAA3B;AAEA,SACEL,KADF,EAEEG,KAFF,EAGEC,KAHF,EAIEF,gBAJF,CAKE;AALF,EAMED,mBANF,EAOEI,UAPF;AASA,eAAe;AACbL,EAAAA,KADa;AAEbG,EAAAA,KAFa;AAGbC,EAAAA,KAHa;AAIbF,EAAAA,gBAJa;AAKbG,EAAAA;AALa,CAAf","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n};\n"]}
|
|
@@ -35,5 +35,6 @@ export declare type VideoCompressorType = {
|
|
|
35
35
|
activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;
|
|
36
36
|
deactivateBackgroundTask(): Promise<any>;
|
|
37
37
|
};
|
|
38
|
+
export declare const backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
|
|
38
39
|
declare const Video: VideoCompressorType;
|
|
39
40
|
export default Video;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import Video, { VideoCompressorType } from './Video';
|
|
1
|
+
import Video, { VideoCompressorType, backgroundUpload } from './Video';
|
|
2
2
|
import Audio from './Audio';
|
|
3
3
|
import Image from './Image';
|
|
4
4
|
import { getDetails } from './utils';
|
|
5
|
-
export { Video, Audio, Image, VideoCompressorType, getDetails, };
|
|
5
|
+
export { Video, Audio, Image, backgroundUpload, VideoCompressorType, getDetails, };
|
|
6
6
|
declare const _default: {
|
|
7
7
|
Video: VideoCompressorType;
|
|
8
8
|
Audio: import("./utils").AudioType;
|
|
9
9
|
Image: {
|
|
10
10
|
compress(value: string, options?: import("./Image").CompressorOptions | undefined): Promise<string>;
|
|
11
11
|
};
|
|
12
|
+
backgroundUpload: (url: string, fileUrl: string, options: import("./Video").FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
|
|
12
13
|
getDetails: (mediaFullPath: string, extesnion?: "mp3" | "mp4") => Promise<any>;
|
|
13
14
|
};
|
|
14
15
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-compressor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "This library compress image, video and audio",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"jest": "^26.0.1",
|
|
74
74
|
"pod-install": "^0.1.0",
|
|
75
75
|
"prettier": "^2.0.5",
|
|
76
|
-
"react": "
|
|
77
|
-
"react-native": "0.
|
|
76
|
+
"react": "^17.0.2",
|
|
77
|
+
"react-native": "^0.66.1",
|
|
78
78
|
"react-native-builder-bob": "^0.18.0",
|
|
79
79
|
"release-it": "^14.2.2",
|
|
80
80
|
"typescript": "^4.1.3"
|
|
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.license = package["license"]
|
|
11
11
|
s.authors = package["author"]
|
|
12
12
|
|
|
13
|
-
s.platforms = { :ios => "
|
|
13
|
+
s.platforms = { :ios => "11.0" }
|
|
14
14
|
s.source = { :git => "https://github.com/Shobbak/react-native-compressor.git", :tag => "#{s.version}" }
|
|
15
15
|
|
|
16
16
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
package/src/Video/index.tsx
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NativeModules,
|
|
3
|
+
NativeEventEmitter,
|
|
4
|
+
Platform,
|
|
5
|
+
NativeEventSubscription,
|
|
6
|
+
} from 'react-native';
|
|
2
7
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
8
|
|
|
4
9
|
export declare enum FileSystemUploadType {
|
|
@@ -65,6 +70,43 @@ const VideoCompressEventEmitter = new NativeEventEmitter(
|
|
|
65
70
|
|
|
66
71
|
const NativeVideoCompressor = NativeModules.VideoCompressor;
|
|
67
72
|
|
|
73
|
+
export const backgroundUpload = async (
|
|
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
|
+
};
|
|
109
|
+
|
|
68
110
|
const Video: VideoCompressorType = {
|
|
69
111
|
compress: async (
|
|
70
112
|
fileUrl: string,
|
|
@@ -76,7 +118,7 @@ const Video: VideoCompressorType = {
|
|
|
76
118
|
onProgress?: (progress: number) => void
|
|
77
119
|
) => {
|
|
78
120
|
const uuid = uuidv4();
|
|
79
|
-
let subscription
|
|
121
|
+
let subscription: NativeEventSubscription;
|
|
80
122
|
try {
|
|
81
123
|
if (onProgress) {
|
|
82
124
|
subscription = VideoCompressEventEmitter.addListener(
|
|
@@ -111,50 +153,25 @@ const Video: VideoCompressorType = {
|
|
|
111
153
|
);
|
|
112
154
|
return result;
|
|
113
155
|
} finally {
|
|
156
|
+
// @ts-ignore
|
|
114
157
|
if (subscription) {
|
|
115
|
-
|
|
158
|
+
subscription.remove();
|
|
116
159
|
}
|
|
117
160
|
}
|
|
118
161
|
},
|
|
119
|
-
backgroundUpload
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
'VideoCompressorProgress',
|
|
162
|
+
backgroundUpload,
|
|
163
|
+
activateBackgroundTask(onExpired?) {
|
|
164
|
+
if (onExpired) {
|
|
165
|
+
const subscription: NativeEventSubscription =
|
|
166
|
+
VideoCompressEventEmitter.addListener(
|
|
167
|
+
'backgroundTaskExpired',
|
|
126
168
|
(event: any) => {
|
|
127
|
-
|
|
128
|
-
|
|
169
|
+
onExpired(event);
|
|
170
|
+
if (subscription) {
|
|
171
|
+
subscription.remove();
|
|
129
172
|
}
|
|
130
173
|
}
|
|
131
174
|
);
|
|
132
|
-
}
|
|
133
|
-
if (Platform.OS === 'android' && fileUrl.includes('file://')) {
|
|
134
|
-
fileUrl = fileUrl.replace('file://', '');
|
|
135
|
-
}
|
|
136
|
-
const result = await NativeVideoCompressor.upload(fileUrl, {
|
|
137
|
-
uuid,
|
|
138
|
-
method: options.httpMethod,
|
|
139
|
-
headers: options.headers,
|
|
140
|
-
url,
|
|
141
|
-
});
|
|
142
|
-
return result;
|
|
143
|
-
} finally {
|
|
144
|
-
if (subscription) {
|
|
145
|
-
VideoCompressEventEmitter.removeSubscription(subscription);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
activateBackgroundTask(onExpired?) {
|
|
150
|
-
if (onExpired) {
|
|
151
|
-
const subscription = VideoCompressEventEmitter.addListener(
|
|
152
|
-
'backgroundTaskExpired',
|
|
153
|
-
(event: any) => {
|
|
154
|
-
onExpired(event);
|
|
155
|
-
VideoCompressEventEmitter.removeSubscription(subscription);
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
175
|
}
|
|
159
176
|
return NativeVideoCompressor.activateBackgroundTask({});
|
|
160
177
|
},
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Video, { VideoCompressorType } from './Video';
|
|
1
|
+
import Video, { VideoCompressorType, backgroundUpload } from './Video';
|
|
2
2
|
import Audio from './Audio';
|
|
3
3
|
import Image from './Image';
|
|
4
4
|
import { getDetails } from './utils';
|
|
@@ -7,6 +7,7 @@ export {
|
|
|
7
7
|
Video,
|
|
8
8
|
Audio,
|
|
9
9
|
Image,
|
|
10
|
+
backgroundUpload,
|
|
10
11
|
//type
|
|
11
12
|
VideoCompressorType,
|
|
12
13
|
getDetails,
|
|
@@ -15,5 +16,6 @@ export default {
|
|
|
15
16
|
Video,
|
|
16
17
|
Audio,
|
|
17
18
|
Image,
|
|
19
|
+
backgroundUpload,
|
|
18
20
|
getDetails,
|
|
19
21
|
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<component name="libraryTable">
|
|
2
|
-
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72">
|
|
3
|
-
<CLASSES>
|
|
4
|
-
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.72/3adfc2f4ea4243e01204be8081fe63bde6b12815/kotlin-stdlib-jdk7-1.3.72.jar!/" />
|
|
5
|
-
</CLASSES>
|
|
6
|
-
<JAVADOC>
|
|
7
|
-
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.72/d5c341c5580f6d1289efe06247f4818e57ad24eb/kotlin-stdlib-jdk7-1.3.72-javadoc.jar!/" />
|
|
8
|
-
</JAVADOC>
|
|
9
|
-
<SOURCES>
|
|
10
|
-
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.72/e83fed78d9bc2951a2c7e457969d5fd171cb9d5f/kotlin-stdlib-jdk7-1.3.72-sources.jar!/" />
|
|
11
|
-
</SOURCES>
|
|
12
|
-
</library>
|
|
13
|
-
</component>
|