Commit cbf8e8d0 authored by ibuler's avatar ibuler

[Update] 修改支持复制

parent 8b51e11f
...@@ -11,15 +11,14 @@ from coco.httpd.ws import ProxyNamespace, ElfinderNamespace ...@@ -11,15 +11,14 @@ from coco.httpd.ws import ProxyNamespace, ElfinderNamespace
logger = get_logger(__file__) logger = get_logger(__file__)
app = Flask(__name__, template_folder='templates', app = Flask(__name__, template_folder='templates',
static_folder='static', static_folder='static')
static_url_path='/coco/static')
app.config.update(config) app.config.update(config)
socket_io = SocketIO() socket_io = SocketIO()
socket_io.on_namespace(ProxyNamespace('/ssh')) socket_io.on_namespace(ProxyNamespace('/ssh'))
socket_io.on_namespace(ElfinderNamespace('/elfinder')) socket_io.on_namespace(ElfinderNamespace('/elfinder'))
# init_kwargs = {'async_mode': 'threading'} # init_kwargs = {'async_mode': 'threading'}
init_kwargs = {'async_mode': 'eventlet',} init_kwargs = {'async_mode': 'eventlet'}
socket_io.init_app(app, **init_kwargs), socket_io.init_app(app, **init_kwargs),
socket_io.on_error_default(lambda x: logger.exception(x)) socket_io.on_error_default(lambda x: logger.exception(x))
......
...@@ -23,8 +23,7 @@ class ElFinderConnector: ...@@ -23,8 +23,7 @@ class ElFinderConnector:
'mkfile': ('__mkfile', {'target': True, 'name': True}), 'mkfile': ('__mkfile', {'target': True, 'name': True}),
'rename': ('__rename', {'target': True, 'name': True}), 'rename': ('__rename', {'target': True, 'name': True}),
'ls': ('__list', {'target': True}), 'ls': ('__list', {'target': True}),
'paste': ('__paste', {'targets[]': True, 'src': True, 'paste': ('__paste', {'targets[]': True, 'dst': True, 'cut': True}),
'dst': True, 'cut': True}),
'rm': ('__remove', {'targets[]': True}), 'rm': ('__remove', {'targets[]': True}),
'upload': ('__upload', {'target': True}), 'upload': ('__upload', {'target': True}),
'size': ('__size', {'targets[0]': True}), 'size': ('__size', {'targets[0]': True}),
...@@ -256,14 +255,10 @@ class ElFinderConnector: ...@@ -256,14 +255,10 @@ class ElFinderConnector:
def __paste(self): def __paste(self):
targets = self.data['targets[]'] targets = self.data['targets[]']
source = self.data['src']
dest = self.data['dst'] dest = self.data['dst']
cut = (self.data['cut'] == '1') cut = self.data['cut'] == '1'
source_volume = self.get_volume(source)
dest_volume = self.get_volume(dest) dest_volume = self.get_volume(dest)
if source_volume != dest_volume: self.response.update(dest_volume.paste(targets, dest, cut))
raise Exception('Moving between volumes is not supported.')
self.response.update(dest_volume.paste(targets, source, dest, cut))
def __remove(self): def __remove(self):
targets = self.data['targets[]'] targets = self.data['targets[]']
......
...@@ -186,7 +186,7 @@ class BaseVolume: ...@@ -186,7 +186,7 @@ class BaseVolume:
""" """
raise NotImplementedError raise NotImplementedError
def paste(self, targets, source, dest, cut): def paste(self, targets, dest, cut):
""" Moves/copies target files/directories from source to dest. """ Moves/copies target files/directories from source to dest.
If a file with the same name already exists in the dest directory If a file with the same name already exists in the dest directory
...@@ -194,7 +194,6 @@ class BaseVolume: ...@@ -194,7 +194,6 @@ class BaseVolume:
before sending the request). before sending the request).
:param targets: A list of hashes of files/dirs to move/copy. :param targets: A list of hashes of files/dirs to move/copy.
:param source: The current parent of the targets.
:param dest: The new parent of the targets. :param dest: The new parent of the targets.
:param cut: Boolean. If true, move the targets. If false, copy the :param cut: Boolean. If true, move the targets. If false, copy the
targets. targets.
......
...@@ -146,7 +146,9 @@ class SFTPVolume(BaseVolume): ...@@ -146,7 +146,9 @@ class SFTPVolume(BaseVolume):
def mkfile(self, name, parent): def mkfile(self, name, parent):
""" Creates a new file. """ """ Creates a new file. """
parent_path = self._path(parent) parent_path = self._path(parent)
remote_path = self._remote_path(parent_path) path = self._join(parent_path, name)
remote_path = self._remote_path(path)
with self.sftp.open(remote_path, mode='w'): with self.sftp.open(remote_path, mode='w'):
pass pass
return self._info(parent_path) return self._info(parent_path)
...@@ -163,9 +165,42 @@ class SFTPVolume(BaseVolume): ...@@ -163,9 +165,42 @@ class SFTPVolume(BaseVolume):
'removed': [target] 'removed': [target]
} }
def paste(self, targets, source, dest, cut): def is_exist(self, path):
remote_path = self._remote_path(path)
try:
data = self.sftp.lstat(remote_path)
print(data)
exist = True
except FileNotFoundError:
exist = False
return exist
def paste(self, targets, dest, cut):
""" Moves/copies target files/directories from source to dest. """ """ Moves/copies target files/directories from source to dest. """
return {"error": "Not support paste"} print("Paste {} {} {}".format(targets, dest, cut))
dest_parent_path = self._path(dest)
added = []
removed = []
for target in targets:
src_path = self._path(target)
dest_path = self._join(dest_parent_path, self._base_name(src_path))
print("Paste {} to => {}".format(src_path, dest_parent_path))
if self.is_exist(dest_path):
print("Exist {}".format(dest_path))
continue
src_remote_path = self._remote_path(src_path)
dest_remote_path = self._remote_path(dest_path)
try:
f = self.sftp.open(src_remote_path, mode='r')
attr = self.sftp.putfo(f, dest_remote_path)
if cut:
removed.append(self.remove(target))
added.append(self._info(dest_path, attr))
finally:
f.close()
return {"added": added, "removed": removed}
def remove(self, target): def remove(self, target):
""" Delete a File or Directory object. """ """ Delete a File or Directory object. """
...@@ -201,7 +236,6 @@ class SFTPVolume(BaseVolume): ...@@ -201,7 +236,6 @@ class SFTPVolume(BaseVolume):
def upload_as_chunk(self, files, chunk_name, parent): def upload_as_chunk(self, files, chunk_name, parent):
added = [] added = []
print("Upload chunk: {}".format(chunk_name))
parent_path = self._path(parent) parent_path = self._path(parent)
item = files.get('upload[]') item = files.get('upload[]')
__tmp = chunk_name.split('.') __tmp = chunk_name.split('.')
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
<body style="margin: 0"> <body style="margin: 0">
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery-2.1.1.js') }}"></script> <script type="text/javascript" src="{{ url_for('static', filename='js/jquery-2.1.1.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery-ui-1.10.4.min.js') }}"></script> <script type="text/javascript" src="{{ url_for('static', filename='js/jquery-ui-1.10.4.min.js') }}"></script>
<link rel="stylesheet" type="text/css" media="screen" href="{{ url_for('static', filename='elfinder/css/elfinder.min.css') }}">
<link rel="stylesheet" type="text/css" media="screen" href="{{ url_for('static', filename='elfinder/css/theme-gray.css') }}">
<script type="text/javascript" src="{{ url_for('static', filename='elfinder/elfinder.full.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='elfinder/i18n/elfinder.pl.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/socket.io.js') }}"></script> <script type="text/javascript" src="{{ url_for('static', filename='js/socket.io.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='plugins/elfinder/elfinder.full.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='plugins/elfinder/i18n/elfinder.pl.js') }}"></script>
<link rel="stylesheet" type="text/css" media="screen" href="{{ url_for('static', filename='plugins/elfinder/css/elfinder.min.css') }}">
<link rel="stylesheet" type="text/css" media="screen" href="{{ url_for('static', filename='plugins/elfinder/css/theme-gray.css') }}">
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
var socket = io.connect('/elfinder'); var socket = io.connect('/elfinder');
socket.on('connect', function () { socket.on('connect', function () {
...@@ -42,10 +42,10 @@ ...@@ -42,10 +42,10 @@
], ],
cwd: [ cwd: [
'reload', 'back', '|', 'mkdir', 'mkfile', '|', 'reload', 'back', '|', 'mkdir', 'mkfile', '|',
'upload' 'upload', 'paste'
], ],
files: [ files: [
'rm', 'rename', 'download' 'rm', 'rename', 'download', 'copy', 'cut', 'paste'
] ]
}, },
rememberLastDir: false, rememberLastDir: false,
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
} }
if (lng !== 'en') { if (lng !== 'en') {
$.ajax({ $.ajax({
url : "{{ url_for('static', filename='elfinder/i18n/') }}"+'/elfinder.'+lng+'.js', url : "{{ url_for('static', filename='plugins/elfinder/i18n/') }}"+'/elfinder.'+lng+'.js',
cache : true, cache : true,
dataType : 'script' dataType : 'script'
}) })
...@@ -101,8 +101,6 @@ ...@@ -101,8 +101,6 @@
if (!$('#elfinder').hasClass('elfinder-fullscreen')) { if (!$('#elfinder').hasClass('elfinder-fullscreen')) {
resizeTimer = setTimeout(function () { resizeTimer = setTimeout(function () {
var h, w; var h, w;
var isTrue = window == parent;
console.log("Window == parent" + isTrue);
if (window != parent) { if (window != parent) {
h = parseInt(parent.$('.window.active').height()); h = parseInt(parent.$('.window.active').height());
w = parseInt(parent.$('.window.active').width()); w = parseInt(parent.$('.window.active').width());
...@@ -112,7 +110,6 @@ ...@@ -112,7 +110,6 @@
} }
var ori_h = parseInt($('#elfinder').height()); var ori_h = parseInt($('#elfinder').height());
var ori_w = parseInt($('#elfinder').width()); var ori_w = parseInt($('#elfinder').width());
console.log("Height: " + h + " Wid: " + w);
if (h !== ori_h || w != ori_w){ if (h !== ori_h || w != ori_w){
elf.resize(w, h); elf.resize(w, h);
} }
......
This diff is collapsed.
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