Save attributes in attachments

pull/6301/head
Marcelo Schmidt 8 years ago
parent 1c903b2aa4
commit 3c3be3bc1f
No known key found for this signature in database
GPG Key ID: CA48C21A7B66097E
  1. 268
      packages/rocketchat-google-vision/.npm/package/npm-shrinkwrap.json
  2. 30
      packages/rocketchat-google-vision/client/googlevision.js
  3. 28
      packages/rocketchat-google-vision/server/googlevision.js
  4. 10
      packages/rocketchat-google-vision/server/models/Messages.js
  5. 7
      server/methods/messageSearch.js

@ -1,8 +1,8 @@
{
"dependencies": {
"ajv": {
"version": "4.11.4",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-4.11.4.tgz",
"version": "4.11.5",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-4.11.5.tgz",
"from": "ajv@>=4.9.1 <5.0.0"
},
"ansi-regex": {
@ -71,26 +71,9 @@
"from": "balanced-match@>=0.4.1 <0.5.0"
},
"base64url": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/base64url/-/base64url-1.0.6.tgz",
"from": "base64url@>=1.0.4 <1.1.0",
"dependencies": {
"concat-stream": {
"version": "1.4.10",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.4.10.tgz",
"from": "concat-stream@>=1.4.7 <1.5.0"
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"from": "isarray@0.0.1"
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"from": "readable-stream@>=1.1.9 <1.2.0"
}
}
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz",
"from": "base64url@>=2.0.0 <3.0.0"
},
"bcrypt-pbkdf": {
"version": "1.0.1",
@ -127,7 +110,7 @@
"buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
"from": "buffer-equal-constant-time@>=1.0.1 <2.0.0"
"from": "buffer-equal-constant-time@1.0.1"
},
"buffer-shims": {
"version": "1.0.0",
@ -276,14 +259,7 @@
"ecdsa-sig-formatter": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz",
"from": "ecdsa-sig-formatter@>=1.0.0 <2.0.0",
"dependencies": {
"base64url": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz",
"from": "base64url@>=2.0.0 <3.0.0"
}
}
"from": "ecdsa-sig-formatter@1.0.9"
},
"end-of-stream": {
"version": "1.0.0",
@ -336,61 +312,27 @@
"version": "0.7.4",
"resolved": "https://registry.npmjs.org/gcs-resumable-upload/-/gcs-resumable-upload-0.7.4.tgz",
"from": "gcs-resumable-upload@>=0.7.1 <0.8.0",
"dependencies": {
"google-auto-auth": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/google-auto-auth/-/google-auto-auth-0.2.4.tgz",
"from": "google-auto-auth@>=0.2.1 <0.3.0"
}
}
},
"generate-function": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz",
"from": "generate-function@>=2.0.0 <3.0.0"
},
"generate-object-property": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz",
"from": "generate-object-property@>=1.1.0 <2.0.0"
},
"get-stdin": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz",
"from": "get-stdin@>=4.0.1 <5.0.0"
},
"getpass": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.6.tgz",
"from": "getpass@>=0.1.1 <0.2.0",
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
"from": "assert-plus@>=1.0.0 <2.0.0"
}
}
},
"glob": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
"from": "glob@>=7.0.5 <8.0.0"
},
"google-auth-library": {
"version": "0.9.10",
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-0.9.10.tgz",
"from": "google-auth-library@>=0.9.10 <0.10.0",
"dependencies": {
"async": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/async/-/async-1.4.2.tgz",
"from": "async@>=1.4.2 <1.5.0"
},
"base64url": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/base64url/-/base64url-1.0.6.tgz",
"from": "base64url@>=1.0.4 <1.1.0"
},
"caseless": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.11.0.tgz",
"from": "caseless@>=0.11.0 <0.12.0"
},
"concat-stream": {
"version": "1.4.10",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.4.10.tgz",
"from": "concat-stream@>=1.4.7 <1.5.0"
},
"form-data": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-1.0.1.tgz",
@ -403,25 +345,64 @@
}
}
},
"google-auth-library": {
"version": "0.9.10",
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-0.9.10.tgz",
"from": "google-auth-library@>=0.9.6 <0.10.0",
"dependencies": {
"request": {
"version": "2.74.0",
"resolved": "https://registry.npmjs.org/request/-/request-2.74.0.tgz",
"from": "request@>=2.74.0 <2.75.0"
}
}
},
"google-auto-auth": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/google-auto-auth/-/google-auto-auth-0.2.4.tgz",
"from": "google-auto-auth@>=0.2.1 <0.3.0"
},
"har-validator": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/har-validator/-/har-validator-2.0.6.tgz",
"from": "har-validator@>=2.0.6 <2.1.0"
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"from": "isarray@0.0.1"
},
"jwa": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.0.2.tgz",
"from": "jwa@>=1.0.0 <1.1.0",
"dependencies": {
"base64url": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/base64url/-/base64url-0.0.6.tgz",
"from": "base64url@>=0.0.4 <0.1.0"
}
}
},
"jws": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/jws/-/jws-3.0.0.tgz",
"from": "jws@>=3.0.0 <3.1.0"
},
"node-uuid": {
"version": "1.4.7",
"resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.7.tgz",
"from": "node-uuid@>=1.4.7 <1.5.0"
"from": "node-uuid@~1.4.7"
},
"qs": {
"version": "6.2.3",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.2.3.tgz",
"from": "qs@>=6.2.0 <6.3.0"
},
"request": {
"version": "2.74.0",
"resolved": "https://registry.npmjs.org/request/-/request-2.74.0.tgz",
"from": "request@>=2.74.0 <2.75.0"
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"from": "readable-stream@>=1.1.9 <1.2.0"
},
"tunnel-agent": {
"version": "0.4.3",
@ -430,9 +411,46 @@
}
}
},
"generate-function": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz",
"from": "generate-function@>=2.0.0 <3.0.0"
},
"generate-object-property": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz",
"from": "generate-object-property@>=1.1.0 <2.0.0"
},
"get-stdin": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz",
"from": "get-stdin@>=4.0.1 <5.0.0"
},
"getpass": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.6.tgz",
"from": "getpass@>=0.1.1 <0.2.0",
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
"from": "assert-plus@>=1.0.0 <2.0.0"
}
}
},
"glob": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
"from": "glob@>=7.0.5 <8.0.0"
},
"google-auth-library": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-0.10.0.tgz",
"from": "google-auth-library@>=0.10.0 <0.11.0"
},
"google-auto-auth": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/google-auto-auth/-/google-auto-auth-0.5.2.tgz",
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/google-auto-auth/-/google-auto-auth-0.5.4.tgz",
"from": "google-auto-auth@>=0.5.2 <0.6.0"
},
"google-gax": {
@ -1258,9 +1276,9 @@
}
},
"gtoken": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-1.2.1.tgz",
"from": "gtoken@>=1.1.0 <2.0.0"
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-1.2.2.tgz",
"from": "gtoken@>=1.2.1 <2.0.0"
},
"har-schema": {
"version": "1.0.5",
@ -1305,7 +1323,14 @@
"indent-string": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/indent-string/-/indent-string-1.2.2.tgz",
"from": "indent-string@>=1.1.0 <2.0.0"
"from": "indent-string@>=1.1.0 <2.0.0",
"dependencies": {
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"from": "minimist@>=1.1.0 <2.0.0"
}
}
},
"inflight": {
"version": "1.0.6",
@ -1408,26 +1433,26 @@
"from": "jsonpointer@>=4.0.0 <5.0.0"
},
"jsprim": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.3.1.tgz",
"from": "jsprim@>=1.2.2 <2.0.0"
},
"jwa": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.0.2.tgz",
"from": "jwa@>=1.0.0 <1.1.0",
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.0.tgz",
"from": "jsprim@>=1.2.2 <2.0.0",
"dependencies": {
"base64url": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/base64url/-/base64url-0.0.6.tgz",
"from": "base64url@>=0.0.4 <0.1.0"
"assert-plus": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
"from": "assert-plus@1.0.0"
}
}
},
"jwa": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz",
"from": "jwa@>=1.1.4 <2.0.0"
},
"jws": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/jws/-/jws-3.0.0.tgz",
"from": "jws@>=3.0.0 <3.1.0"
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/jws/-/jws-3.1.4.tgz",
"from": "jws@>=3.1.4 <4.0.0"
},
"lcid": {
"version": "1.0.0",
@ -1442,7 +1467,7 @@
"lodash.noop": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/lodash.noop/-/lodash.noop-3.0.1.tgz",
"from": "lodash.noop@>=3.0.0 <3.1.0"
"from": "lodash.noop@>=3.0.1 <4.0.0"
},
"log-driver": {
"version": "1.2.5",
@ -1464,6 +1489,11 @@
"resolved": "https://registry.npmjs.org/meow/-/meow-2.0.0.tgz",
"from": "meow@>=2.0.0 <2.1.0",
"dependencies": {
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"from": "minimist@>=1.1.0 <2.0.0"
},
"object-assign": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-1.0.0.tgz",
@ -1497,21 +1527,14 @@
"from": "minimatch@>=3.0.2 <4.0.0"
},
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"from": "minimist@>=1.1.0 <2.0.0"
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"from": "minimist@0.0.8"
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"from": "mkdirp@>=0.5.0 <0.6.0",
"dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"from": "minimist@0.0.8"
}
}
"from": "mkdirp@>=0.5.0 <0.6.0"
},
"modelo": {
"version": "4.2.0",
@ -1619,16 +1642,9 @@
"from": "pump@>=1.0.0 <2.0.0",
"dependencies": {
"end-of-stream": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.2.0.tgz",
"from": "end-of-stream@>=1.1.0 <2.0.0",
"dependencies": {
"once": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/once/-/once-1.3.3.tgz",
"from": "once@>=1.3.0 <1.4.0"
}
}
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.0.tgz",
"from": "end-of-stream@>=1.1.0 <2.0.0"
}
}
},
@ -1648,8 +1664,8 @@
"from": "qs@>=6.4.0 <6.5.0"
},
"readable-stream": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.3.tgz",
"version": "2.2.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.6.tgz",
"from": "readable-stream@>=2.2.2 <3.0.0"
},
"repeating": {
@ -1680,7 +1696,7 @@
"node-uuid": {
"version": "1.4.7",
"resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.7.tgz",
"from": "node-uuid@~1.4.7"
"from": "node-uuid@>=1.4.7 <1.5.0"
},
"qs": {
"version": "6.3.2",

@ -1,27 +1,27 @@
RocketChat.GoogleVision = {
getVisionAttributes(googleVision) {
getVisionAttributes(attachment) {
const attributes = {};
const labels = [];
if (googleVision.labels && googleVision.labels.length > 0) {
googleVision.labels.forEach(label => {
if (attachment.labels && attachment.labels.length > 0) {
attachment.labels.forEach(label => {
labels.push({ label });
});
}
if (googleVision.safeSearch && googleVision.safeSearch.adult === true) {
if (attachment.safeSearch && attachment.safeSearch[0] && attachment.safeSearch[0].adult === true) {
labels.push({ label: 'NSFW', bgColor: 'red', fontColor: 'white' });
}
if (googleVision.safeSearch && googleVision.safeSearch.violence === true) {
if (attachment.safeSearch && attachment.safeSearch.violence === true) {
labels.push({ label: 'Violence', bgColor: 'red', fontColor: 'white' });
}
if (googleVision.properties && googleVision.properties.colors && googleVision.properties.colors.length > 0) {
attributes.color = '#' + googleVision.properties.colors[0];
if (attachment.colors && attachment.colors.length > 0) {
attributes.color = '#' + attachment.colors[0];
}
if (googleVision.logos && googleVision.logos.length > 0) {
labels.push({ label: `Logo: ${googleVision.logos[0]}` });
if (attachment.logos && attachment.logos.length > 0) {
labels.push({ label: `Logo: ${attachment.logos[0]}` });
}
if (googleVision.faces && googleVision.faces.length > 0) {
if (attachment.faces && attachment.faces.length > 0) {
let faceCount = 0;
googleVision.faces.forEach(face => {
attachment.faces.forEach(face => {
const faceAttributes = [];
if (face.joy) {
faceAttributes.push('Joy');
@ -54,9 +54,7 @@ RocketChat.GoogleVision = {
for (const index in message.attachments) {
if (message.attachments.hasOwnProperty(index)) {
const attachment = message.attachments[index];
if (attachment.googleVision) {
message.attachments[index] = Object.assign(message.attachments[index], this.getVisionAttributes(attachment.googleVision));
}
message.attachments[index] = Object.assign(message.attachments[index], this.getVisionAttributes(attachment));
}
}
}
@ -68,9 +66,7 @@ RocketChat.GoogleVision = {
for (const index in message.attachments) {
if (message.attachments.hasOwnProperty(index)) {
const attachment = message.attachments[index];
if (attachment.googleVision) {
message.attachments[index] = Object.assign(message.attachments[index], this.getVisionAttributes(attachment.googleVision));
}
message.attachments[index] = Object.assign(message.attachments[index], this.getVisionAttributes(attachment));
}
}
}

@ -108,7 +108,7 @@ class GoogleVision {
const bucketFile = bucket.file(`${file.googleCloudStorage.path}${file._id}`);
this.visionClient.detect(bucketFile, visionTypes, Meteor.bindEnvironment((error, results) => {
if (!error) {
console.log(RocketChat.models.Messages.setGoogleVision(message._id, results, visionTypes.length === 1 ? visionTypes[0] : undefined));
console.log(RocketChat.models.Messages.setGoogleVisionData(message._id, this.getAnnotations(visionTypes, results)));
} else {
console.trace('GoogleVision error: ', error.stack);
}
@ -119,6 +119,32 @@ class GoogleVision {
}
}
}
getAnnotations(visionTypes, visionData) {
if (visionTypes.length === 1) {
visionData = {};
visionData[`${visionTypes[0]}`] = visionData;
}
const results = {};
for (const index in visionData) {
if (visionData.hasOwnProperty(index)) {
switch (index) {
case 'faces':
case 'landmarks':
case 'labels':
case 'safeSearch':
case 'similar':
case 'logos':
results[index] = (results[index] || []).concat(visionData[index] || []);
break;
case 'properties':
results['colors'] = visionData[index]['colors'];
break;
}
}
}
return results;
}
}
RocketChat.GoogleVision = new GoogleVision;

@ -1,9 +1,9 @@
RocketChat.models.Messages.setGoogleVision = function(messageId, googleVision, visionType) {
RocketChat.models.Messages.setGoogleVisionData = function(messageId, visionData) {
const updateObj = {};
if (visionType) {
updateObj[`attachments.0.googleVision.${visionType}`] = googleVision;
} else {
updateObj['attachments.0.googleVision'] = googleVision;
for (const index in visionData) {
if (visionData.hasOwnProperty(index)) {
updateObj[`attachments.0.${index}`] = visionData[index];
}
}
return this.update({ _id: messageId }, { $set: updateObj });

@ -80,6 +80,11 @@ Meteor.methods({
return '';
}
function filterLabel(_, tag) {
query['attachments.0.labels'] = new RegExp(s.escapeRegExp(tag), 'i');
return '';
}
function sortByTimestamp(_, direction) {
if (direction.startsWith('asc')) {
options.sort.ts = 1;
@ -140,6 +145,8 @@ Meteor.methods({
text = text.replace(/is:pinned|has:pin/g, filterPinned);
// Filter on messages which have a location attached.
text = text.replace(/has:location|has:map/g, filterLocation);
// Filter image tags
text = text.replace(/label:(\w+)/g, filterLabel);
// Filtering before/after/on a date
// matches dd-MM-yyyy, dd/MM/yyyy, dd-MM-yyyy, prefixed by before:, after: and on: respectively.
// Example: before:15/09/2016 after: 10-08-2016

Loading…
Cancel
Save