From bb44eb6cf534886bfc720cc9cd9ecc1c75fb9726 Mon Sep 17 00:00:00 2001 From: Albert Luo Date: Mon, 18 Jun 2018 12:11:01 +0800 Subject: [PATCH] feat:add react native sdk for oss --- .gitignore | 7 + .npmignore | 56 + Example/.babelrc | 3 + Example/.buckconfig | 6 + Example/.flowconfig | 54 + Example/.gitattributes | 1 + Example/.gitignore | 56 + Example/.watchmanconfig | 1 + Example/App.js | 60 + Example/CSS/global.js | 28 + Example/Component/AuthManager.js | 112 ++ Example/Component/BucketManager.js | 95 ++ Example/Component/DownloadManager.js | 50 + Example/Component/ImageProcessManager.js | 142 ++ Example/Component/ObjectManager.js | 112 ++ Example/Component/UploadManager.js | 251 +++ Example/android/app/BUCK | 65 + Example/android/app/build.gradle | 152 ++ Example/android/app/proguard-rules.pro | 70 + .../android/app/src/main/AndroidManifest.xml | 35 + .../main/java/com/example/MainActivity.java | 15 + .../java/com/example/MainApplication.java | 49 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 8 + Example/android/build.gradle | 24 + Example/android/gradle.properties | 20 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 52266 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 + Example/android/gradlew | 164 ++ Example/android/gradlew.bat | 90 + Example/android/keystores/BUCK | 8 + .../keystores/debug.keystore.properties | 4 + Example/android/settings.gradle | 7 + Example/app.json | 4 + Example/index.js | 4 + Example/ios/Example-tvOS/Info.plist | 54 + Example/ios/Example-tvOSTests/Info.plist | 24 + Example/ios/Example.xcodeproj/project.pbxproj | 1476 +++++++++++++++++ .../xcschemes/Example-tvOS.xcscheme | 129 ++ .../xcshareddata/xcschemes/Example.xcscheme | 129 ++ Example/ios/Example/AppDelegate.h | 14 + Example/ios/Example/AppDelegate.m | 35 + .../ios/Example/Base.lproj/LaunchScreen.xib | 42 + .../AppIcon.appiconset/Contents.json | 38 + .../ios/Example/Images.xcassets/Contents.json | 6 + Example/ios/Example/Info.plist | 56 + Example/ios/Example/main.m | 16 + Example/ios/ExampleTests/ExampleTests.m | 68 + Example/ios/ExampleTests/Info.plist | 24 + Example/package.json | 24 + Example/resource/putao.jpeg | Bin 0 -> 12886 bytes LICENSE | 21 + README-CN.md | 441 +++++ README.md | 443 ++++- aliyun-oss-react-native.podspec | 19 + android/build.gradle | 37 + android/src/main/AndroidManifest.xml | 6 + .../com/reactlibrary/AliyunAuthManager.java | 175 ++ .../com/reactlibrary/AliyunBucketManager.java | 133 ++ .../reactlibrary/AliyunDownloadManager.java | 133 ++ .../com/reactlibrary/AliyunObjectManager.java | 180 ++ .../com/reactlibrary/AliyunUploadManager.java | 410 +++++ .../reactlibrary/PromiseExceptionManager.java | 30 + .../com/reactlibrary/RNAliyunOssModule.java | 375 +++++ .../com/reactlibrary/RNAliyunOssPackage.java | 27 + .../com/reactlibrary/utils/ConfigUtils.java | 21 + .../com/reactlibrary/utils/FileUtils.java | 76 + index.js | 244 +++ .../AliyunOSSiOS.framework/AliyunOSSiOS | Bin 0 -> 7489336 bytes .../Headers/AliyunOSSiOS.h | 20 + .../AliyunOSSiOS.framework/Headers/OSSBolts.h | 26 + .../Headers/OSSCancellationToken.h | 42 + .../OSSCancellationTokenRegistration.h | 29 + .../Headers/OSSCancellationTokenSource.h | 60 + .../Headers/OSSClient.h | 273 +++ .../Headers/OSSCompat.h | 81 + .../Headers/OSSDefine.h | 67 + .../Headers/OSSExecutor.h | 62 + .../AliyunOSSiOS.framework/Headers/OSSLog.h | 40 + .../AliyunOSSiOS.framework/Headers/OSSModel.h | 1303 +++++++++++++++ .../Headers/OSSNetworking.h | 143 ++ .../Headers/OSSService.h | 20 + .../AliyunOSSiOS.framework/Headers/OSSTask.h | 281 ++++ .../Headers/OSSTaskCompletionSource.h | 89 + .../AliyunOSSiOS.framework/Headers/OSSUtil.h | 37 + .../Modules/module.modulemap | 6 + ios/RNAliyunOSS+AUTH.h | 12 + ios/RNAliyunOSS+AUTH.m | 78 + ios/RNAliyunOSS+BUCKET.h | 12 + ios/RNAliyunOSS+BUCKET.m | 97 ++ ios/RNAliyunOSS+DOWNLOAD.h | 12 + ios/RNAliyunOSS+DOWNLOAD.m | 65 + ios/RNAliyunOSS+LOG.h | 12 + ios/RNAliyunOSS+LOG.m | 19 + ios/RNAliyunOSS+MULTIPARTUPLOAD.h | 12 + ios/RNAliyunOSS+MULTIPARTUPLOAD.m | 141 ++ ios/RNAliyunOSS+OBJECT.h | 12 + ios/RNAliyunOSS+OBJECT.m | 123 ++ ios/RNAliyunOSS+UPLOAD.h | 12 + ios/RNAliyunOSS+UPLOAD.m | 55 + ios/RNAliyunOSS.h | 28 + ios/RNAliyunOSS.m | 187 +++ ios/RNAliyunOSS.xcodeproj/project.pbxproj | 277 ++++ .../xcschemes/RNAliyunOss.xcscheme | 80 + package.json | 25 + script/sts-app-server-node/.gitignore | 1 + script/sts-app-server-node/README.md | 30 + script/sts-app-server-node/config.json | 7 + script/sts-app-server-node/index.js | 45 + script/sts-app-server-node/package.json | 25 + .../sts-app-server-node/policy/all_policy.txt | 12 + .../policy/bucket_read_policy.txt | 13 + .../policy/bucket_read_write_policy.txt | 17 + 117 files changed, 10654 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 Example/.babelrc create mode 100644 Example/.buckconfig create mode 100644 Example/.flowconfig create mode 100644 Example/.gitattributes create mode 100644 Example/.gitignore create mode 100644 Example/.watchmanconfig create mode 100644 Example/App.js create mode 100644 Example/CSS/global.js create mode 100644 Example/Component/AuthManager.js create mode 100644 Example/Component/BucketManager.js create mode 100644 Example/Component/DownloadManager.js create mode 100644 Example/Component/ImageProcessManager.js create mode 100644 Example/Component/ObjectManager.js create mode 100644 Example/Component/UploadManager.js create mode 100644 Example/android/app/BUCK create mode 100644 Example/android/app/build.gradle create mode 100644 Example/android/app/proguard-rules.pro create mode 100644 Example/android/app/src/main/AndroidManifest.xml create mode 100644 Example/android/app/src/main/java/com/example/MainActivity.java create mode 100644 Example/android/app/src/main/java/com/example/MainApplication.java create mode 100644 Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/values/strings.xml create mode 100644 Example/android/app/src/main/res/values/styles.xml create mode 100644 Example/android/build.gradle create mode 100644 Example/android/gradle.properties create mode 100644 Example/android/gradle/wrapper/gradle-wrapper.jar create mode 100644 Example/android/gradle/wrapper/gradle-wrapper.properties create mode 100755 Example/android/gradlew create mode 100644 Example/android/gradlew.bat create mode 100644 Example/android/keystores/BUCK create mode 100644 Example/android/keystores/debug.keystore.properties create mode 100644 Example/android/settings.gradle create mode 100644 Example/app.json create mode 100644 Example/index.js create mode 100644 Example/ios/Example-tvOS/Info.plist create mode 100644 Example/ios/Example-tvOSTests/Info.plist create mode 100644 Example/ios/Example.xcodeproj/project.pbxproj create mode 100644 Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example-tvOS.xcscheme create mode 100644 Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme create mode 100644 Example/ios/Example/AppDelegate.h create mode 100644 Example/ios/Example/AppDelegate.m create mode 100644 Example/ios/Example/Base.lproj/LaunchScreen.xib create mode 100644 Example/ios/Example/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Example/ios/Example/Images.xcassets/Contents.json create mode 100644 Example/ios/Example/Info.plist create mode 100644 Example/ios/Example/main.m create mode 100644 Example/ios/ExampleTests/ExampleTests.m create mode 100644 Example/ios/ExampleTests/Info.plist create mode 100644 Example/package.json create mode 100644 Example/resource/putao.jpeg create mode 100644 LICENSE create mode 100644 README-CN.md create mode 100644 aliyun-oss-react-native.podspec create mode 100644 android/build.gradle create mode 100644 android/src/main/AndroidManifest.xml create mode 100644 android/src/main/java/com/reactlibrary/AliyunAuthManager.java create mode 100644 android/src/main/java/com/reactlibrary/AliyunBucketManager.java create mode 100644 android/src/main/java/com/reactlibrary/AliyunDownloadManager.java create mode 100644 android/src/main/java/com/reactlibrary/AliyunObjectManager.java create mode 100644 android/src/main/java/com/reactlibrary/AliyunUploadManager.java create mode 100644 android/src/main/java/com/reactlibrary/PromiseExceptionManager.java create mode 100644 android/src/main/java/com/reactlibrary/RNAliyunOssModule.java create mode 100644 android/src/main/java/com/reactlibrary/RNAliyunOssPackage.java create mode 100644 android/src/main/java/com/reactlibrary/utils/ConfigUtils.java create mode 100644 android/src/main/java/com/reactlibrary/utils/FileUtils.java create mode 100644 index.js create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/AliyunOSSiOS create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/AliyunOSSiOS.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSBolts.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSCancellationToken.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSCancellationTokenRegistration.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSCancellationTokenSource.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSClient.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSCompat.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSDefine.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSExecutor.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSLog.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSModel.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSNetworking.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSService.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSTask.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSTaskCompletionSource.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Headers/OSSUtil.h create mode 100644 ios/AliyunSDK/AliyunOSSiOS.framework/Modules/module.modulemap create mode 100644 ios/RNAliyunOSS+AUTH.h create mode 100644 ios/RNAliyunOSS+AUTH.m create mode 100644 ios/RNAliyunOSS+BUCKET.h create mode 100644 ios/RNAliyunOSS+BUCKET.m create mode 100644 ios/RNAliyunOSS+DOWNLOAD.h create mode 100644 ios/RNAliyunOSS+DOWNLOAD.m create mode 100644 ios/RNAliyunOSS+LOG.h create mode 100644 ios/RNAliyunOSS+LOG.m create mode 100644 ios/RNAliyunOSS+MULTIPARTUPLOAD.h create mode 100644 ios/RNAliyunOSS+MULTIPARTUPLOAD.m create mode 100644 ios/RNAliyunOSS+OBJECT.h create mode 100644 ios/RNAliyunOSS+OBJECT.m create mode 100644 ios/RNAliyunOSS+UPLOAD.h create mode 100644 ios/RNAliyunOSS+UPLOAD.m create mode 100644 ios/RNAliyunOSS.h create mode 100644 ios/RNAliyunOSS.m create mode 100644 ios/RNAliyunOSS.xcodeproj/project.pbxproj create mode 100644 ios/RNAliyunOSS.xcodeproj/xcshareddata/xcschemes/RNAliyunOss.xcscheme create mode 100644 package.json create mode 100755 script/sts-app-server-node/.gitignore create mode 100755 script/sts-app-server-node/README.md create mode 100755 script/sts-app-server-node/config.json create mode 100755 script/sts-app-server-node/index.js create mode 100755 script/sts-app-server-node/package.json create mode 100755 script/sts-app-server-node/policy/all_policy.txt create mode 100755 script/sts-app-server-node/policy/bucket_read_policy.txt create mode 100755 script/sts-app-server-node/policy/bucket_read_write_policy.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d3cfdf1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +android/build/ +android/aliyun-oss-react-native.iml +node_modules/ +.idea +.DS_Store +Example/ios/Pods/ +package-lock.json \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..785470e --- /dev/null +++ b/.npmignore @@ -0,0 +1,56 @@ +# IntelliJ project files +.idea +*.iml +out +gen + +Example/ +.gitignore + +.vscode + +# typings +# +typings +typings.json +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# Android/IJ +# +*.iml +.idea +.gradle +local.properties + +# node.js +# +node_modules/ +npm-debug.log + +# BUCK +buck-out/ +\.buckd/ +android/app/libs +android/keystores/debug.keystore \ No newline at end of file diff --git a/Example/.babelrc b/Example/.babelrc new file mode 100644 index 0000000..a9ce136 --- /dev/null +++ b/Example/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["react-native"] +} diff --git a/Example/.buckconfig b/Example/.buckconfig new file mode 100644 index 0000000..934256c --- /dev/null +++ b/Example/.buckconfig @@ -0,0 +1,6 @@ + +[android] + target = Google Inc.:Google APIs:23 + +[maven_repositories] + central = https://repo1.maven.org/maven2 diff --git a/Example/.flowconfig b/Example/.flowconfig new file mode 100644 index 0000000..7d5e2d3 --- /dev/null +++ b/Example/.flowconfig @@ -0,0 +1,54 @@ +[ignore] +; We fork some components by platform +.*/*[.]android.js + +; Ignore "BUCK" generated dirs +/\.buckd/ + +; Ignore unexpected extra "@providesModule" +.*/node_modules/.*/node_modules/fbjs/.* + +; Ignore duplicate module providers +; For RN Apps installed via npm, "Libraries" folder is inside +; "node_modules/react-native" but in the source repo it is in the root +.*/Libraries/react-native/React.js + +; Ignore polyfills +.*/Libraries/polyfills/.* + +; Ignore metro +.*/node_modules/metro/.* + +[include] + +[libs] +node_modules/react-native/Libraries/react-native/react-native-interface.js +node_modules/react-native/flow/ +node_modules/react-native/flow-github/ + +[options] +emoji=true + +module.system=haste + +munge_underscores=true + +module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' + +module.file_ext=.js +module.file_ext=.jsx +module.file_ext=.json +module.file_ext=.native.js + +suppress_type=$FlowIssue +suppress_type=$FlowFixMe +suppress_type=$FlowFixMeProps +suppress_type=$FlowFixMeState + +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy +suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError + +[version] +^0.67.0 diff --git a/Example/.gitattributes b/Example/.gitattributes new file mode 100644 index 0000000..d42ff18 --- /dev/null +++ b/Example/.gitattributes @@ -0,0 +1 @@ +*.pbxproj -text diff --git a/Example/.gitignore b/Example/.gitignore new file mode 100644 index 0000000..5d64756 --- /dev/null +++ b/Example/.gitignore @@ -0,0 +1,56 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# BUCK +buck-out/ +\.buckd/ +*.keystore + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/ + +*/fastlane/report.xml +*/fastlane/Preview.html +*/fastlane/screenshots + +# Bundle artifact +*.jsbundle diff --git a/Example/.watchmanconfig b/Example/.watchmanconfig new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/Example/.watchmanconfig @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/Example/App.js b/Example/App.js new file mode 100644 index 0000000..ab244db --- /dev/null +++ b/Example/App.js @@ -0,0 +1,60 @@ +import React, { Component } from 'react'; + +import { + StyleSheet, + View, + ScrollView, +} from 'react-native'; + +import { AuthManager } from './Component/AuthManager' +import { UploadManager } from './Component/UploadManager' +import { DownloadManager } from './Component/DownloadManager' +import { ImageProcessManager } from './Component/ImageProcessManager' +import { BucketManager } from './Component/BucketManager' +import { ObjectManager } from './Component/ObjectManager' + +import AliyunOSS from 'aliyun-oss-react-native' +//open log +AliyunOSS.enableDevMode() +// defalut configraiton +const configuration = { + maxRetryCount: 3, + timeoutIntervalForRequest: 30, + timeoutIntervalForResource: 24 * 60 * 60 +}; +const config = { + AccessKey: 'XXX', + SecretKey: 'XXX', +}; +const endPoint = 'oss-cn-zhangjiakou.aliyuncs.com'; +const companyserver = "http://XXX:PORT"; +const familyserver = "http://XXX:PORT"; + +// AliyunOSS.initWithPlainTextAccessKey(config.AccessKey, config.SecretKey, endPoint, configuration); +AliyunOSS.initWithServerSTS(familyserver,endPoint, configuration) + +type Props = {}; + +export default class App extends Component { + render() { + return ( + + + + + + + + + + + ); + } +} +const styles = StyleSheet.create({ + container: { + flexDirection:'column', + backgroundColor: '#F5FCFF', + flexWrap:'wrap' + } +}); diff --git a/Example/CSS/global.js b/Example/CSS/global.js new file mode 100644 index 0000000..dae0e49 --- /dev/null +++ b/Example/CSS/global.js @@ -0,0 +1,28 @@ + +import { StyleSheet } from 'react-native' + +export const styles = StyleSheet.create({ + container: { + flexDirection:'column', + backgroundColor: '#F5FCFF', + flexWrap:'wrap' + }, + description: { + fontSize:20, + marginTop:10, + marginLeft:10, + marginBottom:20 + }, + item: { + justifyContent:'space-around', + marginBottom:10 + }, + button:{ + margin:10 + }, + detailitem: { + flexDirection:'row', + justifyContent:'flex-start', + flexWrap:'wrap' + } +}); \ No newline at end of file diff --git a/Example/Component/AuthManager.js b/Example/Component/AuthManager.js new file mode 100644 index 0000000..fa2b159 --- /dev/null +++ b/Example/Component/AuthManager.js @@ -0,0 +1,112 @@ +import React, { Component } from 'react'; +import { + Platform, + StyleSheet, + Text, + View, + Alert, + Button, + ScrollView, + Image +} from 'react-native'; + + +const configuration = { + maxRetryCount: 3, + timeoutIntervalForRequest: 30, + timeoutIntervalForResource: 24 * 60 * 60 +}; + +const config = { + AccessKey: 'XXX', + SecretKey: 'XXX', +}; + +const STSConfig = { + AccessKeyId:'XXX', + SecretKeyId:'XXX', + SecurityToken:'XXX' +} + +const endPoint = 'oss-cn-zhangjiakou.aliyuncs.com'; +const companyserver = "http://XXX:PORT" +const familyserver = "http://XXX:PORT" + +//导入样式 +import { styles } from '../CSS/global.js' + +export class AuthManager extends Component { + + render() { + return ( + + Client初始化 + + + +