mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
feature(package) spead up directory upload: philip: bower -> npm
This commit is contained in:
parent
b3aba1f5e3
commit
b940d95a01
19 changed files with 38 additions and 885 deletions
|
|
@ -29,12 +29,10 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"domtokenlist-shim": "~1.1.0",
|
||||
"findit": "1.1.7",
|
||||
"menu": "~1.0.2",
|
||||
"olark": "^1.0.0",
|
||||
"jquery": "3.2.1",
|
||||
"fancybox": "^2.1.6",
|
||||
"philip": "^1.3.7",
|
||||
"smalltalk": "2.4.1"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const philip = require('philip');
|
||||
|
||||
const Images = require('./images');
|
||||
const {FS} = require('../../common/cloudfunc');
|
||||
|
||||
module.exports = (items) => {
|
||||
const Info = DOM.CurrentInfo;
|
||||
const load = DOM.load;
|
||||
const Dialog = DOM.Dialog;
|
||||
|
||||
if (items.length)
|
||||
|
|
@ -18,56 +19,43 @@ module.exports = (items) => {
|
|||
return item.webkitGetAsEntry();
|
||||
});
|
||||
|
||||
const addDir = (name) => {
|
||||
return `/modules/${name}/lib/${name}.js`;
|
||||
};
|
||||
const path = Info.dirPath
|
||||
.replace(/\/$/, '');
|
||||
|
||||
const array = [
|
||||
'findit',
|
||||
'philip'
|
||||
];
|
||||
|
||||
const url = CloudCmd.join(array.map(addDir));
|
||||
|
||||
load.js(url, () => {
|
||||
const path = Info.dirPath
|
||||
.replace(/\/$/, '');
|
||||
const uploader = philip(entries, (type, name, data, i, n, callback) => {
|
||||
const prefixURL = CloudCmd.PREFIX_URL;
|
||||
const full = prefixURL + FS + path + name;
|
||||
|
||||
const uploader = window.philip(entries, (type, name, data, i, n, callback) => {
|
||||
const prefixURL = CloudCmd.PREFIX_URL;
|
||||
const full = prefixURL + FS + path + name;
|
||||
let upload;
|
||||
switch(type) {
|
||||
case 'file':
|
||||
upload = uploadFile(full, data);
|
||||
break;
|
||||
|
||||
case 'directory':
|
||||
upload = uploadDir(full);
|
||||
break;
|
||||
}
|
||||
|
||||
upload.on('end', callback);
|
||||
|
||||
upload.on('progress', (count) => {
|
||||
const current = percent(i, n);
|
||||
const next = percent(i + 1, n);
|
||||
const max = next - current;
|
||||
const value = current + percent(count, 100, max);
|
||||
|
||||
let upload;
|
||||
switch(type) {
|
||||
case 'file':
|
||||
upload = uploadFile(full, data);
|
||||
break;
|
||||
|
||||
case 'directory':
|
||||
upload = uploadDir(full);
|
||||
break;
|
||||
}
|
||||
|
||||
upload.on('end', callback);
|
||||
|
||||
upload.on('progress', (count) => {
|
||||
const current = percent(i, n);
|
||||
const next = percent(i + 1, n);
|
||||
const max = next - current;
|
||||
const value = current + percent(count, 100, max);
|
||||
|
||||
setProgress(value);
|
||||
});
|
||||
setProgress(value);
|
||||
});
|
||||
|
||||
uploader.on('error', (error) => {
|
||||
Dialog.alert(error);
|
||||
uploader.abort();
|
||||
});
|
||||
|
||||
uploader.on('progress', setProgress);
|
||||
uploader.on('end', CloudCmd.refresh);
|
||||
});
|
||||
|
||||
uploader.on('error', (error) => {
|
||||
Dialog.alert(error);
|
||||
uploader.abort();
|
||||
});
|
||||
|
||||
uploader.on('progress', setProgress);
|
||||
uploader.on('end', CloudCmd.refresh);
|
||||
};
|
||||
|
||||
function percent(i, n, per = 100) {
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
{
|
||||
"name": "findit",
|
||||
"homepage": "https://github.com/coderaiser/domfs-findit",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "Walk a directory tree in DOM File System",
|
||||
"main": "lib/findit.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"findit",
|
||||
"DOM",
|
||||
"File System"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"modules"
|
||||
],
|
||||
"dependencies": {
|
||||
"emitify": "^3.0.1"
|
||||
},
|
||||
"version": "1.1.7",
|
||||
"_release": "1.1.7",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v1.1.7",
|
||||
"commit": "f30860d8ab233f2dfea1ffe45710d5cfa9d7b797"
|
||||
},
|
||||
"_source": "https://github.com/coderaiser/domfs-findit.git",
|
||||
"_target": "1.1.7",
|
||||
"_originalSource": "findit"
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
2017.04.28, v1.1.7
|
||||
|
||||
feature:
|
||||
- (bower) emitify v3.0.1
|
||||
|
||||
|
||||
2016.07.14, v1.1.6
|
||||
|
||||
feature:
|
||||
- (emitify) v2.1.1
|
||||
|
||||
|
||||
2016.06.03, v1.1.5
|
||||
|
||||
feature:
|
||||
- (bower) emitify v2.1.0
|
||||
|
||||
|
||||
2015.12.29, v1.1.4
|
||||
|
||||
feature:
|
||||
- (bower) emitify v2.0.0
|
||||
|
||||
|
||||
2015.09.30, v1.1.3
|
||||
|
||||
feature:
|
||||
- (bower) emitify v1.3.0
|
||||
|
||||
|
||||
2015.07.16, v1.1.2
|
||||
|
||||
fix:
|
||||
- (findit) find -> self._find
|
||||
|
||||
|
||||
2015.07.15, v1.1.1
|
||||
|
||||
fix:
|
||||
- (dindit) enry -> entry
|
||||
|
||||
feature:
|
||||
- (package) main: domfs-findit -> findit
|
||||
|
||||
|
||||
2015.07.14, v1.1.0
|
||||
|
||||
fix:
|
||||
- (findit) dirs, first could be overwriting
|
||||
|
||||
|
||||
2015.07.14, v1.0.3
|
||||
|
||||
fix:
|
||||
- (findit) no end when entry file
|
||||
|
||||
|
||||
2015.07.14, v1.0.2
|
||||
|
||||
fix:
|
||||
- (findit) dirs could be more then 0
|
||||
|
||||
|
||||
2015.07.13, v1.0.1
|
||||
|
||||
fix:
|
||||
- (findit) return
|
||||
- (example) add ()
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 coderaiser
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
# DOM File System Findit
|
||||
|
||||
Similar to [node-findit](https://github.com/substack/node-findit "Node Findit") but for [Dom File System](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem "Dom File System").
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
bower i findit --save
|
||||
```
|
||||
|
||||
## How to use?
|
||||
|
||||
Add `findit.js` and [emitify](https://github.com/coderaiser/emitify "Emitify").
|
||||
Or any other node-compitable [EventEmitter](https://iojs.org/api/events.html "Events") (set `window.Emitify = your_emitter` before using `findit`).
|
||||
|
||||
```html
|
||||
<script src="modules/emitify/lib/emitify.js"></script>
|
||||
<script src="lib/findit.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
var node = window;
|
||||
|
||||
node.addEventListener('drop', function (e) {
|
||||
var entry,
|
||||
finder,
|
||||
item = e.dataTransfer.items[0];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
entry = item.webkitGetAsEntry();
|
||||
|
||||
finder = findit(entry);
|
||||
|
||||
finder.on('file', function(file, entry) {
|
||||
console.log('file: ', file, entry);
|
||||
});
|
||||
|
||||
finder.on('directory', function(file, entry) {
|
||||
console.log('directory: ', file, entry);
|
||||
})
|
||||
|
||||
finder.on('end', function() {
|
||||
console.log('done');
|
||||
})
|
||||
});
|
||||
|
||||
node.addEventListener('dragover', function (e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"name": "findit",
|
||||
"homepage": "https://github.com/coderaiser/domfs-findit",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "Walk a directory tree in DOM File System",
|
||||
"main": "lib/findit.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"findit",
|
||||
"DOM",
|
||||
"File System"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"modules"
|
||||
],
|
||||
"dependencies": {
|
||||
"emitify": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<body>
|
||||
<script src="../modules/emitify/lib/emitify.js"></script>
|
||||
<script src="../lib/findit.js"></script>
|
||||
<script>
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var node = window;
|
||||
|
||||
node.addEventListener('drop', function (e) {
|
||||
var entry,
|
||||
finder,
|
||||
item = e.dataTransfer.items[0];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
entry = item.webkitGetAsEntry();
|
||||
|
||||
finder = findit(entry);
|
||||
|
||||
finder.on('file', function(file, entry) {
|
||||
console.log('file: ', file, entry);
|
||||
});
|
||||
|
||||
finder.on('directory', function(file, entry) {
|
||||
console.log('directory: ', file, entry);
|
||||
})
|
||||
|
||||
finder.on('end', function() {
|
||||
console.log('done');
|
||||
})
|
||||
});
|
||||
|
||||
node.addEventListener('dragover', function (e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/* global Emitify */
|
||||
|
||||
(function(global) {
|
||||
'use strict';
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports)
|
||||
module.exports = findit;
|
||||
else
|
||||
global.findit = findit;
|
||||
|
||||
function findit(entry) {
|
||||
var emitter = Emitify();
|
||||
|
||||
setTimeout(function() {
|
||||
FindIt(emitter, entry);
|
||||
}, 0);
|
||||
|
||||
return emitter;
|
||||
}
|
||||
|
||||
function FindIt(emitter, entry) {
|
||||
if (!(this instanceof FindIt))
|
||||
return new FindIt(emitter, entry);
|
||||
|
||||
this._dirs = 0;
|
||||
this._first = true;
|
||||
|
||||
this._find(emitter, entry);
|
||||
}
|
||||
|
||||
FindIt.prototype._find = function(emitter, entry) {
|
||||
var self = this;
|
||||
|
||||
if (entry.isFile) {
|
||||
emitter.emit('file', entry.fullPath, entry);
|
||||
|
||||
if (self._first)
|
||||
emitter.emit('end');
|
||||
} else {
|
||||
if (self._first)
|
||||
self._first = false;
|
||||
|
||||
emitter.emit('directory', entry.fullPath, entry);
|
||||
|
||||
++self._dirs;
|
||||
|
||||
entry.createReader()
|
||||
.readEntries(function(entries) {
|
||||
[].forEach.call(entries, function(entry) {
|
||||
self._find(emitter, entry);
|
||||
});
|
||||
|
||||
--self._dirs;
|
||||
|
||||
if (!self._dirs)
|
||||
emitter.emit('end');
|
||||
});
|
||||
}
|
||||
};
|
||||
})(this);
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"name": "findit",
|
||||
"private": true,
|
||||
"version": "1.1.7",
|
||||
"description": "Walk a directory tree in DOM File System",
|
||||
"main": "lib/findit.js",
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/coderaiser/domfs-findit.git"
|
||||
},
|
||||
"keywords": [
|
||||
"findit",
|
||||
"DOM",
|
||||
"File System"
|
||||
],
|
||||
"author": "coderaiser <mnemonic.enemy@gmail.com> (http://coderaiser.github.io/)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/coderaiser/domfs-findit/issues"
|
||||
},
|
||||
"homepage": "https://github.com/coderaiser/domfs-findit"
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
{
|
||||
"name": "philip",
|
||||
"homepage": "https://github.com/coderaiser/domfs-philip",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "Walk a directory tree in DOM File System",
|
||||
"main": "lib/philip.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"DOM",
|
||||
"File System"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"modules"
|
||||
],
|
||||
"dependencies": {
|
||||
"execon": "~1.2.2",
|
||||
"emitify": "^3.1.0",
|
||||
"findit": "1.1.7"
|
||||
},
|
||||
"version": "1.3.7",
|
||||
"_release": "1.3.7",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v1.3.7",
|
||||
"commit": "5179476e600b28575eb2c8a549990e1f039f2dbf"
|
||||
},
|
||||
"_source": "https://github.com/coderaiser/domfs-philip.git",
|
||||
"_target": "^1.3.7",
|
||||
"_originalSource": "philip",
|
||||
"_direct": true
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
2017.05.22, v1.3.7
|
||||
|
||||
feature:
|
||||
- (bower) emitify v3.1.0
|
||||
|
||||
|
||||
2017.05.10, v1.3.6
|
||||
|
||||
feature:
|
||||
- (bower) emitify v3.0.2
|
||||
|
||||
|
||||
2017.04.28, v1.3.5
|
||||
|
||||
feature:
|
||||
- (bower) emitify v3.0.1
|
||||
|
||||
|
||||
2016.07.14, v1.3.4
|
||||
|
||||
feature:
|
||||
- (bower) findit v1.1.6
|
||||
- (bower) v2.1.1
|
||||
|
||||
|
||||
2016.06.03, v1.3.3
|
||||
|
||||
feature:
|
||||
- (bower) emitify v2.1.0
|
||||
|
||||
|
||||
2015.12.29, v1.3.2
|
||||
|
||||
feature:
|
||||
- (bower) findit v1.1.4
|
||||
- (bower) emitify v2.0.0
|
||||
|
||||
|
||||
2015.09.30, v1.3.1
|
||||
|
||||
feature:
|
||||
- (bower) findit v1.1.3
|
||||
- (philip) emitify v1.3.0
|
||||
|
||||
|
||||
2015.07.20, v1.3.0
|
||||
|
||||
feature:
|
||||
- (philip) add optional parameters to processingFn: i, n
|
||||
|
||||
|
||||
2015.07.19, v1.2.1
|
||||
|
||||
fix:
|
||||
- (philip) _getFiles: to fast callback call
|
||||
|
||||
|
||||
2015.07.18, v1.2.0
|
||||
|
||||
fix:
|
||||
- (philip) not all files was processed
|
||||
|
||||
|
||||
2015.07.17, v1.1.2
|
||||
|
||||
feature:
|
||||
- (philip) emit progress only when value changed
|
||||
|
||||
|
||||
2015.07.16, v1.1.1
|
||||
|
||||
feature:
|
||||
- (philip) inherit from Emitify
|
||||
|
||||
|
||||
2015.07.16, v1.1.0
|
||||
|
||||
feature:
|
||||
- (philip) add abort, pause, continue
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 coderaiser
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
# Philip
|
||||
|
||||
[Dom File System](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem "Dom File System") processing library
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
bower i philip --save
|
||||
```
|
||||
|
||||
## How to use?
|
||||
|
||||
Add `philip.js` [findit](https://github.com/coderaiser/domfs-findit "Find It"), [execon](https://github.com/coderaiser/execon "Patterns of function calls")(or [async](https://github.com/caolan/async "Async utilities for node and the browser" with `window.exec = window.async`) and [emitify](https://github.com/coderaiser/emitify "Emitify").
|
||||
|
||||
Or any other node-compitable [EventEmitter](https://iojs.org/api/events.html "Events") (set `window.Emitify = your_emitter` before using `findit`).
|
||||
|
||||
```html
|
||||
<script src="modules/emitify/lib/emitify.js"></script>
|
||||
<script src="modules/findit/lib/findit.js"></script>
|
||||
<script src="lib/philip.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var node = window;
|
||||
|
||||
node.addEventListener('drop', function (e) {
|
||||
var upload,
|
||||
entry,
|
||||
finder,
|
||||
item = e.dataTransfer.items[0];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
entry = item.webkitGetAsEntry();
|
||||
|
||||
upload = philip(entry, function(type, name, data/*, i, n,*/, callback) {
|
||||
var error = null;
|
||||
|
||||
switch(type) {
|
||||
case 'file':
|
||||
console.log('file', name, data);
|
||||
break;
|
||||
|
||||
case 'directory':
|
||||
console.log('directory', name);
|
||||
break;
|
||||
}
|
||||
|
||||
callback(error);
|
||||
});
|
||||
|
||||
upload.on('error', function(error) {
|
||||
upload.abort();
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
upload.on('progress', function(count) {
|
||||
console.log(count);
|
||||
});
|
||||
|
||||
upload.on('end', function() {
|
||||
console.log('done');
|
||||
});
|
||||
});
|
||||
|
||||
node.addEventListener('dragover', function (e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
})();
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
{
|
||||
"name": "philip",
|
||||
"homepage": "https://github.com/coderaiser/domfs-philip",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "Walk a directory tree in DOM File System",
|
||||
"main": "lib/philip.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"DOM",
|
||||
"File System"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"modules"
|
||||
],
|
||||
"dependencies": {
|
||||
"execon": "~1.2.2",
|
||||
"emitify": "^3.1.0",
|
||||
"findit": "1.1.7"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
<body>
|
||||
<script src="../modules/emitify/lib/emitify.js"></script>
|
||||
<script src="../modules/findit/lib/findit.js"></script>
|
||||
<script src="../lib/philip.js"></script>
|
||||
<script>
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var node = window;
|
||||
|
||||
node.addEventListener('drop', function (e) {
|
||||
var upload,
|
||||
entry,
|
||||
finder,
|
||||
item = e.dataTransfer.items[0];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
entry = item.webkitGetAsEntry();
|
||||
|
||||
upload = philip(entry, function(type, name, data, callback) {
|
||||
var error = null;
|
||||
|
||||
switch(type) {
|
||||
case 'file':
|
||||
console.log('file', name, data);
|
||||
break;
|
||||
|
||||
case 'directory':
|
||||
console.log('directory', name);
|
||||
break;
|
||||
}
|
||||
|
||||
callback(error);
|
||||
});
|
||||
|
||||
upload.on('error', function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
upload.on('progress', function(count) {
|
||||
console.log(count);
|
||||
});
|
||||
|
||||
upload.on('end', function() {
|
||||
console.log('done');
|
||||
});
|
||||
});
|
||||
|
||||
node.addEventListener('dragover', function (e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
/* global Emitify */
|
||||
/* global findit */
|
||||
/* global exec */
|
||||
|
||||
(function(global) {
|
||||
'use strict';
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports)
|
||||
module.exports = Philip;
|
||||
else
|
||||
global.philip = Philip;
|
||||
|
||||
Philip.prototype = Object.create(Emitify.prototype);
|
||||
|
||||
function Philip(entries, processingFn) {
|
||||
var array,
|
||||
self;
|
||||
|
||||
if (!(this instanceof Philip))
|
||||
return new Philip(entries, processingFn);
|
||||
|
||||
if (typeof processingFn !== 'function')
|
||||
throw Error('processingFn should be function!');
|
||||
|
||||
Emitify.call(this);
|
||||
|
||||
if (Array.isArray(entries))
|
||||
array = entries;
|
||||
else
|
||||
array = [entries];
|
||||
|
||||
self = this;
|
||||
|
||||
this._i = 0;
|
||||
this._n = 0;
|
||||
this._processingFn = processingFn;
|
||||
this._pause = false;
|
||||
this._prev = 0;
|
||||
|
||||
this._find(array, function(files, dirs) {
|
||||
self._files = files;
|
||||
self._dirs = dirs;
|
||||
self._n = files.length + dirs.length;
|
||||
self._data = {};
|
||||
|
||||
self._getFiles(files, self._data, function() {
|
||||
self._process();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Philip.prototype._process = function() {
|
||||
var args,
|
||||
argsLength = this._processingFn.length,
|
||||
el,
|
||||
data,
|
||||
self = this,
|
||||
name = self._dirs.shift(),
|
||||
type = 'directory',
|
||||
fn = function(error) {
|
||||
++self._i;
|
||||
|
||||
if (error) {
|
||||
self.emit('error', error);
|
||||
self.pause();
|
||||
}
|
||||
|
||||
self._process();
|
||||
self._progress();
|
||||
};
|
||||
|
||||
if (!name) {
|
||||
type = 'file';
|
||||
el = self._files.shift();
|
||||
|
||||
if (el) {
|
||||
name = el.fullPath;
|
||||
data = self._data[name];
|
||||
}
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
self.emit('end');
|
||||
} else if (!this._pause) {
|
||||
switch(argsLength) {
|
||||
default:
|
||||
args = [type, name, data];
|
||||
break;
|
||||
|
||||
case 6:
|
||||
args = [type, name, data, this._i, this._n];
|
||||
break;
|
||||
}
|
||||
|
||||
args.push(fn);
|
||||
|
||||
self._processingFn.apply(null, args);
|
||||
}
|
||||
};
|
||||
|
||||
Philip.prototype.pause = function() {
|
||||
this._pause = true;
|
||||
};
|
||||
|
||||
Philip.prototype.continue = function() {
|
||||
if (this._pause) {
|
||||
this._pause = false;
|
||||
this._process();
|
||||
}
|
||||
};
|
||||
|
||||
Philip.prototype.abort = function() {
|
||||
this._files = [];
|
||||
this._dirs = [];
|
||||
|
||||
this._process();
|
||||
};
|
||||
|
||||
Philip.prototype._progress = function() {
|
||||
var value = Math.round(this._i * 100 / this._n);
|
||||
|
||||
if (value !== this._prev) {
|
||||
this._prev = value;
|
||||
this.emit('progress', value);
|
||||
}
|
||||
};
|
||||
|
||||
Philip.prototype._getFiles = function(files, obj, callback) {
|
||||
var current,
|
||||
self = this;
|
||||
|
||||
files = files.slice();
|
||||
current = files.shift();
|
||||
|
||||
if (!obj)
|
||||
obj = {};
|
||||
|
||||
if (!current)
|
||||
callback(null, obj);
|
||||
else
|
||||
current.file(function(file) {
|
||||
var name = current.fullPath;
|
||||
|
||||
obj[name] = file;
|
||||
|
||||
self._getFiles(files, obj, callback);
|
||||
});
|
||||
};
|
||||
|
||||
Philip.prototype._find = function(entries, fn) {
|
||||
var files = [],
|
||||
dirs = [];
|
||||
|
||||
exec.each(entries, function(entry, callback) {
|
||||
var finder = findit(entry);
|
||||
|
||||
finder.on('directory', function(name) {
|
||||
dirs.push(name);
|
||||
});
|
||||
|
||||
finder.on('file', function(name, current) {
|
||||
files.push(current);
|
||||
});
|
||||
|
||||
finder.on('end', function() {
|
||||
callback();
|
||||
});
|
||||
}, function() {
|
||||
fn(files, dirs);
|
||||
});
|
||||
};
|
||||
})(this);
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"name": "philip",
|
||||
"private": true,
|
||||
"version": "1.3.7",
|
||||
"description": "Process files and directories in DOM File System",
|
||||
"main": "lib/philip.js",
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/coderaiser/domfs-philip.git"
|
||||
},
|
||||
"keywords": [
|
||||
"philip",
|
||||
"DOM",
|
||||
"File System"
|
||||
],
|
||||
"author": "coderaiser <mnemonic.enemy@gmail.com> (http://coderaiser.github.io/)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/coderaiser/domfs-philip/issues"
|
||||
},
|
||||
"homepage": "https://github.com/coderaiser/domfs-philip"
|
||||
}
|
||||
|
|
@ -159,6 +159,7 @@
|
|||
"babel-cli": "^6.18.0",
|
||||
"babel-loader": "^7.0.0",
|
||||
"babel-plugin-transform-object-assign": "^6.22.0",
|
||||
"babel-preset-env": "^1.6.0",
|
||||
"clean-css-loader": "^0.1.2",
|
||||
"coveralls": "^2.11.6",
|
||||
"css-loader": "^0.28.4",
|
||||
|
|
@ -176,6 +177,7 @@
|
|||
"html-webpack-plugin": "^2.29.0",
|
||||
"jscs": "^3.0.1",
|
||||
"jshint": "^2.8.0",
|
||||
"limier": "^1.0.1",
|
||||
"minor": "^1.2.2",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mock-require": "^2.0.2",
|
||||
|
|
@ -183,6 +185,7 @@
|
|||
"nodemon": "^1.9.1",
|
||||
"nsp": "^2.2.1",
|
||||
"nyc": "^11.0.2",
|
||||
"philip": "^2.0.0",
|
||||
"place": "^1.1.4",
|
||||
"readjson": "^1.1.3",
|
||||
"redrun": "^5.0.0",
|
||||
|
|
@ -201,9 +204,7 @@
|
|||
"version-io": "^2.0.1",
|
||||
"webpack": "^3.0.0",
|
||||
"wraptile": "^1.0.0",
|
||||
"yaspeller": "^4.0.0",
|
||||
"limier": "^1.0.1",
|
||||
"babel-preset-env": "^1.6.0"
|
||||
"yaspeller": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue