Skip to content

Commit 567e1f3

Browse files
kjinstephenplusplus
authored andcommitted
refactor: use protobufjs library to load proto file (#55)
1 parent fe09381 commit 567e1f3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/google-cloud-vision/src/helpers.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const fs = require('fs');
2020
const is = require('is');
2121
const path = require('path');
2222
const promisify = require('@google-cloud/common').util.promisify;
23+
const protobuf = require('protobufjs');
2324

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

@@ -243,16 +244,19 @@ module.exports = apiVersion => {
243244
});
244245
});
245246

246-
// Get a list of features available on the API. Although we could iterate over
247-
// them and create single-feature methods for each dynamically, for
248-
// documentation purpose, we manually list all the single-feature methods
249-
// below.
250-
const features = gax
251-
.grpc()
252-
.loadProto(
253-
path.join(__dirname, '..', 'protos'),
247+
let protoFilesRoot = new gax.grpc.GoogleProtoFilesRoot();
248+
protoFilesRoot = protobuf.loadSync(
249+
path.join(
250+
__dirname,
251+
'..',
252+
'protos',
254253
`google/cloud/vision/${apiVersion}/image_annotator.proto`
255-
).google.cloud.vision[apiVersion].Feature.Type.values;
254+
),
255+
protoFilesRoot
256+
);
257+
const features = protoFilesRoot.lookup(
258+
`google.cloud.vision.${apiVersion}.Feature.Type`
259+
).values;
256260

257261
/**
258262
* Annotate a single image with face detection.

0 commit comments

Comments
 (0)