From 2bad69ace0483f4099706d0b33d372eb82d2d180 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 16 Apr 2018 16:37:00 -0400 Subject: [PATCH] First use of exif tags! --- .eslintrc | 1 + src/App.js | 9 --------- src/electron/websocket-events.js | 25 +++++++++++++++++++++---- src/views/HomeView.js | 1 - 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.eslintrc b/.eslintrc index d4ab65b..93a93fb 100644 --- a/.eslintrc +++ b/.eslintrc @@ -38,6 +38,7 @@ }], "prefer-const": "error", "no-alert": "error", + "no-case-declarations": "off", "no-console": "off", "no-duplicate-imports": "error", "no-eval": "error", diff --git a/src/App.js b/src/App.js index a69b1c1..e78ea4d 100644 --- a/src/App.js +++ b/src/App.js @@ -46,17 +46,8 @@ export class App extends Component { }); window.clientWS.onmessage = message => { - console.info(message); - console.info(message.data); - console.info(JSON.parse(message.data)); - // const fr = new FileReader(); - // fr.readAsArrayBuffer(message.data); - - // console.info(fr.result); }; - - console.info(window.clientWS); } onWebSocketClose () { diff --git a/src/electron/websocket-events.js b/src/electron/websocket-events.js index d8250da..16a4893 100644 --- a/src/electron/websocket-events.js +++ b/src/electron/websocket-events.js @@ -1,18 +1,35 @@ /** * Websocket event handlers */ +const {ExifTool} = require('exiftool-vendored'); const {JSONMessage} = require('../helpers/web-socket'); +const exiftool = new ExifTool(); + module.exports = (wss) => { wss.on('connection', ws => { ws.send(JSONMessage('server-log', 'Connected to client!')); ws.on('message', (...args) => { - console.info(args); - }); + const [type, message] = JSON.parse(args); + switch (type) { + case 'dropped-files': + const filemap = []; + message.forEach(async file => { + const tags = await getExifTags(file); + console.info(tags); + filemap[file] = tags; + }); + ws.send(JSONMessage('parsed-exif-tags', filemap)); + break; - ws.on('dropped-files', e => { - ws.send(JSONMessage('recieved-dropped-files', e)); + default: + return ws.send(JSONMessage('server-log', [type, message])); + } }); }); }; + +function getExifTags (imgPath) { + return exiftool.read(imgPath); +} diff --git a/src/views/HomeView.js b/src/views/HomeView.js index dbaeab7..6f2fe1a 100644 --- a/src/views/HomeView.js +++ b/src/views/HomeView.js @@ -11,7 +11,6 @@ function handleDrop (e) { const draggedFiles = []; for (const f of e.dataTransfer.files) { - console.log('Dragged files', f.path); draggedFiles.push(f.path); }