Commit 86d1afb0 authored by Mihkel Putrinš's avatar Mihkel Putrinš

d99 use lighter "mime" instead of wonderful "mmmime"

parent c7a87d8f
...@@ -18,7 +18,7 @@ var pjson_path = path.join(__dirname, '..', 'package.json') ...@@ -18,7 +18,7 @@ var pjson_path = path.join(__dirname, '..', 'package.json')
var pjson = require(pjson_path) var pjson = require(pjson_path)
if (IS_DEV) { if (IS_DEV) {
pjson.build++ pjson.build++
fs.writeFileSync(pjson_path, JSON.stringify(pjson, null, 4)) fs.writeFileSync(pjson_path, JSON.stringify(pjson, null, 2))
} }
console.log('----==== ' + pjson.name + ' v.' + pjson.version + ' (build ' + (pjson.build) + ') ====----') console.log('----==== ' + pjson.name + ' v.' + pjson.version + ' (build ' + (pjson.build) + ') ====----')
......
...@@ -3,10 +3,7 @@ var fs = require('fs') ...@@ -3,10 +3,7 @@ var fs = require('fs')
var op = require('object-path') var op = require('object-path')
var path = require('path') var path = require('path')
var async = require('async') var async = require('async')
var mime = require('mime')
var mmm = require('mmmagic')
var Magic = mmm.Magic
var magic = new Magic(mmm.MAGIC_MIME_TYPE | mmm.MAGIC_MIME_ENCODING)
var remote = require('remote') var remote = require('remote')
var app = remote.require('app') var app = remote.require('app')
...@@ -25,13 +22,13 @@ var user_data = {} ...@@ -25,13 +22,13 @@ var user_data = {}
var data = ipc.sendSync('getUser', null) var data = ipc.sendSync('getUser', null)
var initialize = function initialize() { var initialize = function initialize() {
console.log('user_data: ' + data) // console.log('user_data: ' + data)
if (!data) { if (!data) {
data = JSON.parse(clipboard.readText()) data = JSON.parse(clipboard.readText())
clipboard.clear() clipboard.clear()
ipc.send('setUser', data) ipc.send('setUser', data)
} }
console.log('user_data: ' + JSON.stringify(data, null, 4)) // console.log('user_data: ' + JSON.stringify(data, null, 4))
if (op.get(data, 'result.user_id', false)) { if (op.get(data, 'result.user_id', false)) {
user_data['user_id'] = op.get(data, 'result.user_id') user_data['user_id'] = op.get(data, 'result.user_id')
user_data['session_key'] = op.get(data, 'result.session_key') user_data['session_key'] = op.get(data, 'result.session_key')
...@@ -105,6 +102,7 @@ var resourceLoaded = function resourceLoaded() { ...@@ -105,6 +102,7 @@ var resourceLoaded = function resourceLoaded() {
} }
var renderResource = function renderResource() { var renderResource = function renderResource() {
console.log(JSON.stringify(op.get(resource_stats, 'mime'), null, 2))
document.getElementById('resourceStats').removeAttribute('hidden') document.getElementById('resourceStats').removeAttribute('hidden')
document.getElementById('resourceDirectories').innerHTML = '' document.getElementById('resourceDirectories').innerHTML = ''
document.getElementById('resourceFiles').innerHTML = '' document.getElementById('resourceFiles').innerHTML = ''
...@@ -130,21 +128,15 @@ var recurseLocal = function recurseLocal(parent_resource, paths, loadedCB) { ...@@ -130,21 +128,15 @@ var recurseLocal = function recurseLocal(parent_resource, paths, loadedCB) {
return callback() return callback()
} }
if (stats.isFile()) { if (stats.isFile()) {
magic.detectFile(_path, function(err, result) { var mimetype = mime.lookup(_path)
if (err) { // console.log(mimetype)
return callback() resource_stats.files.count++
} resource_stats.files.size += stats.size
resource_stats.files.count++ op.push(parent_resource, 'files', _path)
resource_stats.files.size += stats.size var charset = ''
op.push(parent_resource, 'files', _path) op.set(resource_stats, ['mime', mimetype, 'count'], op.get(resource_stats, ['mime', mimetype, 'count'], 0) + 1)
var mime = result.split(';')[0] op.set(resource_stats, ['mime', mimetype, 'size'], op.get(resource_stats, ['mime', mimetype, 'size'], 0) + stats.size)
var charset = result.split(';')[1].split('=')[1] callback()
op.set(resource_stats, ['mime', mime, 'count'], op.get(resource_stats, ['mime', mime, 'count'], 0) + 1)
op.set(resource_stats, ['mime', mime, 'size'], op.get(resource_stats, ['mime', mime, 'size'], 0) + stats.size)
op.set(resource_stats, ['mime', mime, 'charsets', charset, 'count'], op.get(resource_stats, ['mime', mime, 'charsets', charset, 'count'], 0) + 1)
op.set(resource_stats, ['mime', mime, 'charsets', charset, 'size'], op.get(resource_stats, ['mime', mime, 'charsets', charset, 'size'], 0) + stats.size)
callback()
})
} else if (stats.isDirectory()) { } else if (stats.isDirectory()) {
resource_stats.directories.count++ resource_stats.directories.count++
var directory = {name: _path} var directory = {name: _path}
...@@ -165,6 +157,7 @@ var recurseLocal = function recurseLocal(parent_resource, paths, loadedCB) { ...@@ -165,6 +157,7 @@ var recurseLocal = function recurseLocal(parent_resource, paths, loadedCB) {
if( err ) { if( err ) {
console.log('A file failed to process', err) console.log('A file failed to process', err)
} else { } else {
// console.log(JSON.stringify(op.get(resource_stats, 'mime'), null, 2))
loadedCB() loadedCB()
} }
}) })
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "Panustaja", "name": "Panustaja",
"description": "Ressursikataloogi upitamiseks keeleressurside Entu repositooriumisse.", "description": "Ressursikataloogi upitamiseks keeleressurside Entu repositooriumisse.",
"version": "1.0.1-d", "version": "1.0.1-d",
"build": 96, "build": 99,
"main": "./code/app.js", "main": "./code/app.js",
"license": "CC-SA", "license": "CC-SA",
"private": true, "private": true,
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"dependencies": { "dependencies": {
"async": "^1.5.0", "async": "^1.5.0",
"electron-jade": "^1.3.0", "electron-jade": "^1.3.0",
"mmmagic": "^0.4.1", "mime": "^1.3.4",
"object-path": "^0.9.2", "object-path": "^0.9.2",
"request": "^2.65.0" "request": "^2.65.0"
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment