-
Notifications
You must be signed in to change notification settings - Fork 3
/
findDuplicatesSrv.js
55 lines (44 loc) · 1.41 KB
/
findDuplicatesSrv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const uniqueImages = require('./uniqueImages.js');
const app = require('./uniqueImagesUi/bin/www.js');
const path = require('path');
const sizeOf = require('image-size');
const readChunk = require('read-chunk');
const imageType = require('image-type');
const R = require('ramda');
const getMetaData = (file) => {
try {
var metaData;
const buffer = readChunk.sync(file, 0, 12);
const type = imageType(buffer);
if (type && type.mime === 'image/jpeg') {
const dimensions = sizeOf(file);
return {
width: dimensions.width,
height: dimensions.height
};
} else {
metaData = {};
}
return metaData;
} catch (e) {
console.log(e);
return {};
}
};
const augmentImage = R.map(file => ({
file: file,
metaData: getMetaData(file),
fileName: path.basename(file)
}));
const handleDuplicates = (results) => {
const augmentedDuplicates = results.duplicates.map(augmentImage);
const augmentedPotentialDuplicates = results.potentialDuplicates.map(augmentImage);
const augmentedResults = {
duplicates: augmentedDuplicates,
potentialDuplicates: augmentedPotentialDuplicates,
brokenFiles: results.brokenFiles
};
app.startServer(augmentedResults);
};
uniqueImages.findDuplicates(process.argv[2]).then(handleDuplicates);