Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
feat: make vision helpers work with JSON proto (#441)
Browse files Browse the repository at this point in the history
* feat: make vision helpers work with JSON proto

* lint
  • Loading branch information
alexander-fenster authored Sep 14, 2019
1 parent 4b8f23b commit 5b7a249
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
},
"dependencies": {
"@google-cloud/promisify": "^1.0.0",
"google-gax": "^1.0.0",
"is": "^3.2.1",
"protobufjs": "^6.8.6"
"google-gax": "^1.5.2",
"is": "^3.2.1"
},
"devDependencies": {
"@google-cloud/storage": "^3.0.0",
Expand Down
19 changes: 6 additions & 13 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

const fs = require('fs');
const is = require('is');
const path = require('path');
const {promisify} = require('@google-cloud/promisify');
const protobuf = require('protobufjs');

const gax = require('google-gax');

// We only need to have a Feature enum from the protos, and we want
// this enum to work for both gRPC and fallback scenarios.
// It's enough to have the contents of JSON proto for this purpose.
const jsonProto = require('../protos/protos.json');

/*!
* Convert non-object request forms into a correctly-formatted object.
*
Expand Down Expand Up @@ -244,16 +246,7 @@ module.exports = apiVersion => {
});
});

let protoFilesRoot = new gax.GoogleProtoFilesRoot();
protoFilesRoot = protobuf.loadSync(
path.join(
__dirname,
'..',
'protos',
`google/cloud/vision/${apiVersion}/image_annotator.proto`
),
protoFilesRoot
);
const protoFilesRoot = gax.protobuf.Root.fromJSON(jsonProto);
const features = protoFilesRoot.lookup(
`google.cloud.vision.${apiVersion}.Feature.Type`
).values;
Expand Down

0 comments on commit 5b7a249

Please sign in to comment.