提交 804c9bd7 authored 作者: 吴强's avatar 吴强

Merge branch 'master' of ssh://192.168.1.116:29418/bolan-root/frontend/manager-app-sz into wq

# Conflicts: # android/app/src/main/java/com/bolanmanagerapp/MainApplication.java # android/settings.gradle # ios/bolanManagerApp.xcodeproj/project.pbxproj # package.json
......@@ -166,6 +166,7 @@ android {
}
dependencies {
compile project(':react-native-background-upload')
compile project(':react-native-code-push')
compile project(':react-native-device-info')
compile fileTree(dir: "libs", include: ["*.jar"])
......
......@@ -8,6 +8,7 @@ import com.bolan.android.modules.IDCardReactPackage;
import com.bolan.android.modules.UpdaterReactPackage;
import com.facebook.react.ReactApplication;
import com.lwansbrough.RCTCamera.RCTCameraPackage;
import com.vydia.RNUploader.UploaderReactPackage;
import com.microsoft.codepush.react.CodePush;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.facebook.react.ReactNativeHost;
......@@ -39,6 +40,7 @@ public class MainApplication extends Application implements ReactApplication {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new UploaderReactPackage(),
new RCTCameraPackage(),
new CodePush(BuildConfig.CODEPUSH_KEY, getApplicationContext(), BuildConfig.DEBUG, "http://192.168.1.2:3000"),
new RNDeviceInfo(),
......
rootProject.name = 'bolanManagerApp'
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':react-native-background-upload'
project(':react-native-background-upload').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-upload/android')
include ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
include ':react-native-device-info'
......
......@@ -42,6 +42,7 @@
1A1EABAFBB254C51AA95A884 /* libCodePush.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5049A267195B4A6D95EE87C7 /* libCodePush.a */; };
BDC17299171149F2874B1AB8 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 83AC580FC9064DB19C36CE97 /* libz.tbd */; };
373C7FA9E2A645858860CEE6 /* libRCTCamera.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 57D2AA2056CB4B029AC613BB /* libRCTCamera.a */; };
63F9C160CE05449786E0C256 /* libVydiaRNFileUploader.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D60A2B4F96C34035A331240F /* libVydiaRNFileUploader.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -275,6 +276,8 @@
F140EEF54B894D10B664588B /* CodePush.xcodeproj */ = {isa = PBXFileReference; name = "CodePush.xcodeproj"; path = "../node_modules/react-native-code-push/ios/CodePush.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
5049A267195B4A6D95EE87C7 /* libCodePush.a */ = {isa = PBXFileReference; name = "libCodePush.a"; path = "libCodePush.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
83AC580FC9064DB19C36CE97 /* libz.tbd */ = {isa = PBXFileReference; name = "libz.tbd"; path = "usr/lib/libz.tbd"; sourceTree = SDKROOT; fileEncoding = undefined; lastKnownFileType = sourcecode.text-based-dylib-definition; explicitFileType = undefined; includeInIndex = 0; };
C6C24E880A174F99B0C84663 /* VydiaRNFileUploader.xcodeproj */ = {isa = PBXFileReference; name = "VydiaRNFileUploader.xcodeproj"; path = "../node_modules/react-native-background-upload/ios/VydiaRNFileUploader.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
D60A2B4F96C34035A331240F /* libVydiaRNFileUploader.a */ = {isa = PBXFileReference; name = "libVydiaRNFileUploader.a"; path = "libVydiaRNFileUploader.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
BE6C1D88183E4F098BBEED33 /* SplashScreen.xcodeproj */ = {isa = PBXFileReference; name = "SplashScreen.xcodeproj"; path = "../node_modules/react-native-splash-screen/ios/SplashScreen.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
78557CAE6D494E449ACA2E70 /* libSplashScreen.a */ = {isa = PBXFileReference; name = "libSplashScreen.a"; path = "libSplashScreen.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
0640C8B84C334158A1518970 /* RCTCamera.xcodeproj */ = {isa = PBXFileReference; name = "RCTCamera.xcodeproj"; path = "../node_modules/react-native-camera/ios/RCTCamera.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
......@@ -311,6 +314,7 @@
53E9F8ADCC714D9693F0C068 /* libRNDeviceInfo-tvOS.a in Frameworks */,
1A1EABAFBB254C51AA95A884 /* libCodePush.a in Frameworks */,
BDC17299171149F2874B1AB8 /* libz.tbd in Frameworks */,
63F9C160CE05449786E0C256 /* libVydiaRNFileUploader.a in Frameworks */,
3FB191FD84A84EE59701A8DA /* libSplashScreen.a in Frameworks */,
373C7FA9E2A645858860CEE6 /* libRCTCamera.a in Frameworks */,
);
......@@ -483,6 +487,7 @@
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
20C53C1323F44CCBB35F0247 /* RNDeviceInfo.xcodeproj */,
F140EEF54B894D10B664588B /* CodePush.xcodeproj */,
C6C24E880A174F99B0C84663 /* VydiaRNFileUploader.xcodeproj */,
BE6C1D88183E4F098BBEED33 /* SplashScreen.xcodeproj */,
0640C8B84C334158A1518970 /* RCTCamera.xcodeproj */,
);
......
......@@ -44,6 +44,7 @@
"react": "^16.1.1",
"react-native": "^0.49.3",
"react-native-camera": "^0.12.0",
"react-native-background-upload": "^4.1.0",
"react-native-code-push": "^5.1.3-beta",
"react-native-device-info": "^0.12.1",
"react-native-fetch-polyfill": "^1.1.2",
......
import Upload from 'react-native-background-upload';
import { castArray } from 'lodash';
import post from '../utils/post';
import request from '../utils/request';
import { getToken } from '../utils/auth';
import config from '../utils/config';
export class Operations {
constructor() {
this.operations = [];
}
addCmd = (cmd, ...args) => {
this.operations.push({ cmd, args });
return this;
};
setName = (name) => {
return this.addCmd('setName', name);
};
setRight = (right) => {
return this.addCmd('setRight', right);
};
addTags = (...tags) => {
return this.addCmd('addTags', ...tags);
};
removeTags = (...tags) => {
return this.addCmd('removeTags', ...tags);
};
clearTags = () => {
return this.addCmd('clearTags');
};
setTags = (...tags) => {
return this.addCmd('setTags', ...tags);
};
addOwners = (...owners) => {
return this.addCmd('addOwners', ...owners);
};
removeOwners = (...owners) => {
return this.addCmd('removeOwners', ...owners);
};
clearOwners = () => {
return this.addCmd('clearOwners');
};
setOwners = (...owners) => {
return this.addCmd('setOwners', ...owners);
};
addOwnerGroups = (...groups) => {
return this.addCmd('addOwnerGroups', ...groups);
};
removeOwnerGroups = (...groups) => {
return this.addCmd('removeOwnerGroups', ...groups);
};
clearOwnerGroups = () => {
return this.addCmd('clearOwnerGroups');
};
setOwnerGroups = (...groups) => {
return this.addCmd('setOwnerGroups', ...groups);
};
use = (usage) => {
return this.addCmd('use', usage);
};
unuse = (usage) => {
return this.addCmd('unuse', usage);
};
}
export const createOperations = () => {
return new Operations();
};
export async function editResource(uri, operations) {
return post(`${config.apiContextPath}/api/resource/user/${encodeURIComponent(uri)}/meta`, { operations: operations.operations });
}
export async function getResourceInfo(uri) {
return request(`${config.apiContextPath}/api/resource/user/${encodeURIComponent(uri)}/meta`);
}
export async function queryResourceByUsage(usage, pst = -1, psz = -1) {
return request(`${config.apiContextPath}/api/resource/user/query`, { usage, pst, psz });
}
export async function queryResourceByAllTags(tags, pst = -1, psz = -1) {
return request(`${config.apiContextPath}/api/resource/user/query`, { tags: castArray(tags), pst, psz });
}
export async function queryResourceByAnyTags(tags, pst = -1, psz = -1) {
return request(`${config.apiContextPath}/api/resource/user/query`, { tags: castArray(tags), andOr: 'or', pst, psz });
}
export async function queryResourceByUsageAndAllTags(usage, tags, pst = -1, psz = -1) {
return request(`${config.apiContextPath}/api/resource/user/query`, { usage, tags: castArray(tags), pst, psz });
}
export async function queryResourceByUsageAndAnyTags(usage, tags, pst = -1, psz = -1) {
return request(`${config.apiContextPath}/api/resource/user/query`, { usage, tags: castArray(tags), andOr: 'or', pst, psz });
}
/**
* @callback UploadErrorCallback
* @param {string} uploadId 上传id,用于标识上传任务
* @param {Error} error 错误异常
*/
/**
* @callback UploadCompleteCallback
* @param {string} uploadId 上传id,用于标识上传任务
* @param {string} uri 上传完成后,服务端返回的内部uri,这个uri可以用于后续定位上传的资源
*/
/**
* @callback UploadProgressCallback
* @param {string} uploadId 上传id,用于标识上传任务
* @param {number} progress 上传进度,0-100的整数
*/
/**
* 上传文件,支持后台上传
* @param path 文件绝对路径,类似file:///xxx格式
* @param {UploadErrorCallback} [error] 错误回调,上传失败会调用此回调,并传入错误异常
* @param {UploadCompleteCallback} [complete] 成功回调,上传成功会调用此回调,并传入服务端资源内部uri
* @param {UploadProgressCallback} [progress] 上传进度回调,可以获得进度
* @param {string} [uri] 服务端资源内部uri,可用于覆盖已有资源
* @return {Promise<string>} uploadId 上传id,用于引用上传任务
*/
export async function uploadResource(path, error = () => {}, complete = () => {}, progress = () => {}, uri) {
const { exists, mimeType } = await Upload.getFileInfo(path.substring(7));
if (exists) {
const token = await getToken();
let url;
if (uri) {
url = `${config.apiContextPath}/resource/${token}/${encodeURIComponent(uri)}`;
} else {
url = `${config.apiContextPath}/resource/${token}`;
}
const uploadId = await Upload.startUpload({
url,
path,
method: 'POST',
field: 'file',
type: 'multipart',
headers: {
'content-type': mimeType,
},
});
let completeHandle;
const progressHandle = Upload.addListener('progress', uploadId, (data) => {
progress(uploadId, data.progress);
});
const errorHandle = Upload.addListener('error', uploadId, (data) => {
try {
error(uploadId, data.error);
} finally {
progressHandle.remove();
completeHandle.remove();
errorHandle.remove();
}
});
completeHandle = Upload.addListener('completed', uploadId, (event) => {
try {
const { responseCode, responseBody } = event;
if (responseCode >= 200 && responseCode < 300) {
try {
const response = JSON.parse(responseBody);
if (response.errorCode != null && response.errorCode === 0) {
complete(uploadId, response.data[0]);
} else if (response.errorCode != null) {
const err = new Error(response.message);
err.data = response;
error(uploadId, err);
} else {
error(uploadId, new Error(`Invalid response: ${responseBody}.`));
}
} catch (err) {
error(uploadId, new Error(`Invalid response: ${responseBody}.`));
}
} else {
try {
const response = JSON.parse(responseBody);
if (response.message) {
const err = new Error(response.message);
err.data = response;
error(uploadId, err);
} else if (response.data) {
const err = new Error(response.data);
err.data = response;
error(uploadId, err);
} else {
error(uploadId, new Error(responseBody));
}
} catch (err) {
error(uploadId, new Error(responseBody));
}
}
} finally {
progressHandle.remove();
completeHandle.remove();
errorHandle.remove();
}
});
return uploadId;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论