Commit f5879bce authored by ibuler's avatar ibuler

[Update] 修改文件显示

parent faeae592
...@@ -25,7 +25,7 @@ class ElFinderConnector: ...@@ -25,7 +25,7 @@ class ElFinderConnector:
'paste': ('__paste', {'targets[]': True, 'dst': True, 'cut': True}), 'paste': ('__paste', {'targets[]': 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[]': True}),
} }
_allowed_args = [ _allowed_args = [
...@@ -213,9 +213,7 @@ class ElFinderConnector: ...@@ -213,9 +213,7 @@ class ElFinderConnector:
volume = list(self.volumes.values())[0] volume = list(self.volumes.values())[0]
else: else:
volume = self.get_volume(target) volume = self.get_volume(target)
self.response['cwd'] = volume.info(target) self.response['cwd'] = volume.info(target)
files = volume.list(target) files = volume.list(target)
if 'tree' in self.data or 'reload' in self.data: if 'tree' in self.data or 'reload' in self.data:
parents = volume.parents(target, depth=0) parents = volume.parents(target, depth=0)
...@@ -285,6 +283,6 @@ class ElFinderConnector: ...@@ -285,6 +283,6 @@ class ElFinderConnector:
self.response.update(volume.upload(self.request.files, parent)) self.response.update(volume.upload(self.request.files, parent))
def __size(self): def __size(self):
target = self.data['target'] target = self.data['targets[]']
volume = self.get_volume(target) volume = self.get_volume(target)
self.response['size'] = volume.size(target) self.response['size'] = volume.size(target)
...@@ -53,7 +53,7 @@ class SFTPVolume(BaseVolume): ...@@ -53,7 +53,7 @@ class SFTPVolume(BaseVolume):
"phash": self._hash(parent_path), "phash": self._hash(parent_path),
"ts": attr.st_mtime, "ts": attr.st_mtime,
"size": attr.st_size, "size": attr.st_size,
"mime": "directory" if stat.S_ISDIR(attr.st_mode) else "", "mime": "directory" if stat.S_ISDIR(attr.st_mode) else "file",
"locked": 0, "locked": 0,
"hidden": 0, "hidden": 0,
"read": 1, "read": 1,
...@@ -67,7 +67,6 @@ class SFTPVolume(BaseVolume): ...@@ -67,7 +67,6 @@ class SFTPVolume(BaseVolume):
data['name'] = self.root_name data['name'] = self.root_name
data['locked'] = 1 data['locked'] = 1
data['volume_id'] = self.get_volume_id() data['volume_id'] = self.get_volume_id()
# print("_Get stat info end")
return data return data
def _list(self, path, name_only=False): def _list(self, path, name_only=False):
...@@ -89,23 +88,26 @@ class SFTPVolume(BaseVolume): ...@@ -89,23 +88,26 @@ class SFTPVolume(BaseVolume):
""" Returns a list of files/directories in the target directory. """ """ Returns a list of files/directories in the target directory. """
path = self._path(target) path = self._path(target)
# print("List {}-{}".format(target, path)) # print("List {}-{}".format(target, path))
return self._list(path) with self.lock:
return self._list(path)
def tree(self, target): def tree(self, target):
""" Get the sub directory of directory """ Get the sub directory of directory
""" """
path = self._path(target) path = self._path(target)
print("Tree {} {}".format(target, path)) print("Tree {} {}".format(target, path))
infos = self.list(target) with self.lock:
tree = list(filter(lambda x: x['mime'] == 'directory', infos)) infos = self._list(path)
return tree tree = list(filter(lambda x: x['mime'] == 'directory', infos))
return tree
def parents(self, target, depth=0): def parents(self, target, depth=0):
""" """
获取目录的父目录, 如果deep为0,则直到根 获取目录的父目录, 如果deep为0,则直到根
""" """
path = self._path(target).rstrip(self.path_sep) path = self._path(target).rstrip(self.path_sep)
return self._parents(path, depth=depth) with self.lock:
return self._parents(path, depth=depth)
def _parents(self, path, depth=0): def _parents(self, path, depth=0):
path = self.path_sep + path.lstrip(self.path_sep) path = self.path_sep + path.lstrip(self.path_sep)
...@@ -207,7 +209,11 @@ class SFTPVolume(BaseVolume): ...@@ -207,7 +209,11 @@ class SFTPVolume(BaseVolume):
path = self._path(target) path = self._path(target)
remote_path = self._remote_path(path) remote_path = self._remote_path(path)
try: try:
self.sftp.unlink(remote_path) info = self.info(target)
if info['mime'] == 'directory':
self.sftp.rmdir(remote_path)
else:
self.sftp.unlink(remote_path)
except OSError: except OSError:
raise OSError("Delete {} failed".format(self._base_name(path))) raise OSError("Delete {} failed".format(self._base_name(path)))
return target return target
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
cwd : {oldSchool: true} cwd : {oldSchool: true}
}, },
customData: {'sid': sid}, customData: {'sid': sid},
height: '100%',
width: '100%', width: '100%',
url: '{{ url_for("sftp_host_connector_view", host=host) }}', url: '{{ url_for("sftp_host_connector_view", host=host) }}',
resizable: false, resizable: false,
...@@ -102,7 +101,7 @@ ...@@ -102,7 +101,7 @@
if (!$('#elfinder').hasClass('elfinder-fullscreen')) { if (!$('#elfinder').hasClass('elfinder-fullscreen')) {
resizeTimer = setTimeout(function () { resizeTimer = setTimeout(function () {
var h, w; var h, w;
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());
} else { } else {
...@@ -111,7 +110,7 @@ ...@@ -111,7 +110,7 @@
} }
var ori_h = parseInt($('#elfinder').height()); var ori_h = parseInt($('#elfinder').height());
var ori_w = parseInt($('#elfinder').width()); var ori_w = parseInt($('#elfinder').width());
if (h !== ori_h || w != ori_w){ if (h !== ori_h || w !== ori_w){
elf.resize(w, h); elf.resize(w, h);
} }
}, 200); }, 200);
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
__sftp_cached = {} __volumes_cached = {}
def get_cached_sftp(sid): def get_cached_volume(sid):
return __sftp_cached.get(sid) return __volumes_cached.get(sid)
def set_cache_sftp(sid, volume): def set_cache_volume(sid, volume):
__sftp_cached[sid] = volume __volumes_cached[sid] = volume
...@@ -9,7 +9,7 @@ from .elfinder import connector, volumes ...@@ -9,7 +9,7 @@ from .elfinder import connector, volumes
from ..models import Connection from ..models import Connection
from ..sftp import InternalSFTPClient from ..sftp import InternalSFTPClient
from .auth import login_required from .auth import login_required
from .utils import get_cached_sftp, set_cache_sftp from .utils import get_cached_volume, set_cache_volume
from ..service import app_service from ..service import app_service
logger = get_logger(__file__) logger = get_logger(__file__)
...@@ -19,15 +19,16 @@ logger = get_logger(__file__) ...@@ -19,15 +19,16 @@ logger = get_logger(__file__)
@login_required @login_required
def sftp_host_connector_view(host): def sftp_host_connector_view(host):
sid = request.args.get("sid") or request.values.get('sid') sid = request.args.get("sid") or request.values.get('sid')
sftp = get_cached_sftp(sid) if sid else None volume = get_cached_volume(sid) if sid else None
if not sftp: if not volume:
logger.debug("New sftp, sid: {} host: {}".format(sid, host)) logger.debug("New sftp, sid: {} host: {}".format(sid, host))
user = request.current_user user = request.current_user
connection = Connection(addr=(request.real_ip, 0)) connection = Connection(addr=(request.real_ip, 0))
connection.user = user connection.user = user
sftp = InternalSFTPClient(connection) sftp = InternalSFTPClient(connection)
set_cache_sftp(sid, sftp) volume = volumes.SFTPVolume(sftp)
volume = volumes.SFTPVolume(sftp) set_cache_volume(sid, volume)
if host != '_': if host != '_':
asset = app_service.get_asset(host) asset = app_service.get_asset(host)
if not asset: if not asset:
......
...@@ -11,7 +11,7 @@ from ..proxy import ProxyServer ...@@ -11,7 +11,7 @@ from ..proxy import ProxyServer
from ..utils import get_logger from ..utils import get_logger
from ..ctx import app_service from ..ctx import app_service
from .base import BaseNamespace from .base import BaseNamespace
from .utils import get_cached_sftp from .utils import get_cached_volume
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
logger = get_logger(__file__) logger = get_logger(__file__)
...@@ -201,6 +201,6 @@ class ElfinderNamespace(BaseNamespace): ...@@ -201,6 +201,6 @@ class ElfinderNamespace(BaseNamespace):
self.emit('data', {"sid": str(request.sid)}) self.emit('data', {"sid": str(request.sid)})
def on_disconnect(self): def on_disconnect(self):
sftp = get_cached_sftp(request.sid) sftp = get_cached_volume(request.sid)
if sftp: if sftp:
sftp.close() sftp.close()
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