[vision][ios] add apiKeyOverride property

This commit is contained in:
ehesp
2019-08-07 12:40:53 +01:00
parent d740d6d9d8
commit f802923360
14 changed files with 130 additions and 18 deletions

View File

@@ -84,6 +84,20 @@ describe('mlkit.vision.document.text', () => {
});
});
it('throws if apiKeyOverride is not a string', async () => {
try {
await firebase.vision().cloudDocumentTextRecognizerProcessImage(testImageFile, {
apiKeyOverride: true,
});
return Promise.reject(new Error('Did not throw Error.'));
} catch (e) {
e.message.should.containEql(
"'cloudDocumentTextRecognizerOptions.apiKeyOverride' expected a string value",
);
return Promise.resolve();
}
});
it('throws if languageHints is not an array', async () => {
try {
await firebase.vision().cloudDocumentTextRecognizerProcessImage(testImageFile, {

View File

@@ -210,5 +210,21 @@ describe('mlkit.vision.label', () => {
});
});
});
describe('apiKeyOverride', () => {
it('throws if apiKeyOverride is not a string', async () => {
try {
await firebase.vision().cloudImageLabelerProcessImage(testImageFile, {
apiKeyOverride: true,
});
return Promise.reject(new Error('Did not throw Error.'));
} catch (e) {
e.message.should.containEql(
"'cloudImageLabelerOptions.apiKeyOverride' expected a string value",
);
return Promise.resolve();
}
});
});
});
});

View File

@@ -92,6 +92,20 @@ describe('mlkit.vision.landmark', () => {
enforceCertFingerprintMatch: false,
});
});
it('throws if apiKeyOverride is not a string', async () => {
try {
await firebase.vision().cloudLandmarkRecognizerProcessImage(testImageFile, {
apiKeyOverride: true,
});
return Promise.reject(new Error('Did not throw Error.'));
} catch (e) {
e.message.should.containEql(
"'cloudLandmarkRecognizerOptions.apiKeyOverride' expected a string value",
);
return Promise.resolve();
}
});
});
describe('maxResults', () => {

View File

@@ -144,6 +144,22 @@ describe('mlkit.vision.text', () => {
});
});
describe('apiKeyOverride', () => {
it('throws if apiKeyOverride is not a string', async () => {
try {
await firebase.vision().cloudTextRecognizerProcessImage(testImageFile, {
apiKeyOverride: true,
});
return Promise.reject(new Error('Did not throw Error.'));
} catch (e) {
e.message.should.containEql(
"'cloudTextRecognizerOptions.apiKeyOverride' expected a string value",
);
return Promise.resolve();
}
});
});
describe('languageHints', () => {
it('throws if not array', async () => {
try {

View File

@@ -55,6 +55,10 @@ RCT_EXPORT_METHOD(cloudDocumentTextRecognizerProcessImage:
options.languageHints = cloudDocumentTextRecognizerOptions[@"hintedLanguages"];
}
if (cloudDocumentTextRecognizerOptions[@"apiKeyOverride"]) {
options.APIKeyOverride = cloudDocumentTextRecognizerOptions[@"apiKeyOverride"];
}
FIRVisionDocumentTextRecognizer *textRecognizer = [vision cloudDocumentTextRecognizerWithOptions:options];
[textRecognizer processImage:visionImage completion:^(FIRVisionDocumentText *_Nullable result, NSError *error) {
if (error != nil) {

View File

@@ -99,6 +99,10 @@ RCT_EXPORT_METHOD(cloudImageLabelerProcessImage:
options.confidenceThreshold = [cloudImageLabelerOptions[@"confidenceThreshold"] floatValue];
}
if (cloudImageLabelerOptions[@"apiKeyOverride"]) {
options.APIKeyOverride = cloudImageLabelerOptions[@"apiKeyOverride"];
}
FIRVisionImageLabeler *labeler = [vision cloudImageLabelerWithOptions:options];
[labeler processImage:visionImage completion:^(NSArray<FIRVisionImageLabel *> *_Nullable labels, NSError *error) {
if (error != nil) {

View File

@@ -51,6 +51,10 @@ RCT_EXPORT_METHOD(cloudLandmarkRecognizerProcessImage:
FIRVisionCloudDetectorOptions *options = [[FIRVisionCloudDetectorOptions alloc] init];
options.maxResults = [cloudLandmarkRecognizerOptions[@"maxResults"] unsignedIntegerValue];
if (cloudLandmarkRecognizerOptions[@"apiKeyOverride"]) {
options.APIKeyOverride = cloudLandmarkRecognizerOptions[@"apiKeyOverride"];
}
NSInteger *model = [cloudLandmarkRecognizerOptions[@"model"] pointerValue];
if (model == (NSInteger *) 1) {

View File

@@ -88,6 +88,10 @@ RCT_EXPORT_METHOD(cloudTextRecognizerProcessImage:
options.languageHints = cloudTextRecognizerOptions[@"hintedLanguages"];
}
if (cloudTextRecognizerOptions[@"apiKeyOverride"]) {
options.APIKeyOverride = cloudTextRecognizerOptions[@"apiKeyOverride"];
}
NSInteger *modelType = [cloudTextRecognizerOptions[@"modelType"] pointerValue];
if (modelType == (NSInteger *) 1) {
options.modelType = FIRVisionCloudTextModelTypeSparse;

View File

@@ -50,6 +50,16 @@ export default function visionCloudDocumentTextRecognizerOptions(
cloudDocumentTextRecognizerOptions.enforceCertFingerprintMatch;
}
if (hasOwnProperty(cloudDocumentTextRecognizerOptions, 'apiKeyOverride')) {
if (!isString(cloudDocumentTextRecognizerOptions.apiKeyOverride)) {
throw new Error(
"'cloudDocumentTextRecognizerOptions.apiKeyOverride' expected a string value.",
);
}
out.apiKeyOverride = cloudDocumentTextRecognizerOptions.apiKeyOverride;
}
if (cloudDocumentTextRecognizerOptions.languageHints) {
if (
!isArray(cloudDocumentTextRecognizerOptions.languageHints) ||

View File

@@ -20,6 +20,7 @@ import {
isBoolean,
isNumber,
isObject,
isString,
isUndefined,
} from '@react-native-firebase/common';
@@ -47,6 +48,14 @@ export default function visionCloudImageLabelerOptions(cloudImageLabelerOptions)
out.enforceCertFingerprintMatch = cloudImageLabelerOptions.enforceCertFingerprintMatch;
}
if (hasOwnProperty(cloudImageLabelerOptions, 'apiKeyOverride')) {
if (!isString(cloudImageLabelerOptions.apiKeyOverride)) {
throw new Error("'cloudImageLabelerOptions.apiKeyOverride' expected a string value.");
}
out.apiKeyOverride = cloudImageLabelerOptions.apiKeyOverride;
}
if (cloudImageLabelerOptions.confidenceThreshold) {
if (!isNumber(cloudImageLabelerOptions.confidenceThreshold)) {
throw new Error(

View File

@@ -20,6 +20,7 @@ import {
isBoolean,
isNumber,
isObject,
isString,
isUndefined,
} from '@react-native-firebase/common';
@@ -50,6 +51,14 @@ export default function visionCloudLandmarkRecognizerOptions(cloudLandmarkRecogn
out.enforceCertFingerprintMatch = cloudLandmarkRecognizerOptions.enforceCertFingerprintMatch;
}
if (hasOwnProperty(cloudLandmarkRecognizerOptions, 'apiKeyOverride')) {
if (!isString(cloudLandmarkRecognizerOptions.apiKeyOverride)) {
throw new Error("'cloudLandmarkRecognizerOptions.apiKeyOverride' expected a string value.");
}
out.apiKeyOverride = cloudLandmarkRecognizerOptions.apiKeyOverride;
}
if (hasOwnProperty(cloudLandmarkRecognizerOptions, 'maxResults')) {
if (!isNumber(cloudLandmarkRecognizerOptions.maxResults)) {
throw new Error("'cloudLandmarkRecognizerOptions.maxResults' expected a number value.");

View File

@@ -50,6 +50,14 @@ export default function visionCloudTextRecognizerOptions(cloudTextRecognizerOpti
out.enforceCertFingerprintMatch = cloudTextRecognizerOptions.enforceCertFingerprintMatch;
}
if (hasOwnProperty(cloudTextRecognizerOptions, 'apiKeyOverride')) {
if (!isString(cloudTextRecognizerOptions.apiKeyOverride)) {
throw new Error("'cloudTextRecognizerOptions.apiKeyOverride' expected a string value.");
}
out.apiKeyOverride = cloudTextRecognizerOptions.apiKeyOverride;
}
if (cloudTextRecognizerOptions.modelType) {
if (
cloudTextRecognizerOptions.modelType !== VisionCloudTextRecognizerModelType.DENSE_MODEL &&

View File

@@ -35,24 +35,24 @@ console.log(`Android AVD: ${config.configurations['android.emu.debug'].name}`);
const PACKAGES = [
'app',
'dynamic-links',
'iid',
'perf',
'fiam',
'functions',
'analytics',
'config',
'crashlytics',
'utils',
'ml-natural-language',
// 'dynamic-links',
// 'iid',
// 'perf',
// 'fiam',
// 'functions',
// 'analytics',
// 'config',
// 'crashlytics',
// 'utils',
// 'ml-natural-language',
'ml-vision',
'fiam',
'auth',
'database',
'storage',
'indexing',
'messaging',
'firestore',
// 'fiam',
// 'auth',
// 'database',
// 'storage',
// 'indexing',
// 'messaging',
// 'firestore',
];
for (let i = 0; i < PACKAGES.length; i++) {

View File

@@ -2,7 +2,7 @@
--timeout 260000
--reporter spec
--slow 2000
--retries 3
--retries 0
--bail
--exit
--require node_modules/jet/platform/node