Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelawyu committed Mar 7, 2018
1 parent 8d932e3 commit cd542e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions functions/imagemagick/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ exports.blurOffensiveImages = (event) => {
}

const file = storage.bucket(object.bucket).file(object.name);
const file_uri = `gs://${object.bucket}/${object.name}`;
const fileUri = `gs://${object.bucket}/${object.name}`;

console.log(`Analyzing ${file.name}.`);

return client.safeSearchDetection(file_uri)
return client.safeSearchDetection(fileUri)
.catch((err) => {
console.error(`Failed to analyze ${file.name}.`, err);
return Promise.reject(err);
})
.then(([result]) => {
if (result.safeSearchAnnotation.adult == 'VERY_LIKELY' ||
result.safeSearchAnnotation.violence == 'VERY_LIKELY') {
if (result.safeSearchAnnotation.adult === 'VERY_LIKELY' ||
result.safeSearchAnnotation.violence === 'VERY_LIKELY') {
console.log(`The image ${file.name} has been detected as inappropriate.`);
return blurImage(file, result);
} else {
Expand Down
26 changes: 13 additions & 13 deletions functions/imagemagick/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ function getSample (filename) {
bucket: sinon.stub().returns(bucket)
};
const StorageMock = sinon.stub().returns(storageMock);
var safeSearchDetectionStub = sinon.stub()
var safeSearchDetectionStub = sinon.stub();
safeSearchDetectionStub.withArgs(`gs://${bucketName}/${safeFilename}`).returns(Promise.resolve([{
safeSearchAnnotation: {
adult: 'VERY_LIKELY',
violence: 'VERY_LIKELY'
}
safeSearchAnnotation: {
adult: 'VERY_LIKELY',
violence: 'VERY_LIKELY'
}
}]));
safeSearchDetectionStub.withArgs(`gs://${bucketName}/${unsafeFilename}`).returns(Promise.resolve([{
safeSearchAnnotation: {
adult: 'VERY_UNLIKELY',
violence: 'VERY_UNLIKELY'
}
safeSearchAnnotation: {
adult: 'VERY_UNLIKELY',
violence: 'VERY_UNLIKELY'
}
}]));
var imageAnnotatorClientStub = sinon.stub(vision, "ImageAnnotatorClient");
var imageAnnotatorClientStub = sinon.stub(vision, 'ImageAnnotatorClient');
imageAnnotatorClientStub.returns({
safeSearchDetection: safeSearchDetectionStub
});
Expand Down Expand Up @@ -84,7 +84,7 @@ function getSample (filename) {

test.beforeEach(tools.stubConsole);
test.afterEach.always(tools.restoreConsole);
test.afterEach.always(function() {
test.afterEach.always(function () {
vision.ImageAnnotatorClient.restore();
});

Expand Down Expand Up @@ -114,9 +114,9 @@ test.serial(`blurOffensiveImages blurs images`, async (t) => {
test.serial(`blurOffensiveImages ignores safe images`, async (t) => {
const sample = getSample(unsafeFilename);
await sample.program.blurOffensiveImages({
data: {
data: {
bucket: bucketName,
name: unsafeFilename
name: unsafeFilename
}
});
t.is(console.log.callCount, 2);
Expand Down

0 comments on commit cd542e7

Please sign in to comment.