Commit 278a4200 authored by ibuler's avatar ibuler

[Update] 不支持复制文件夹

parent f5879bce
......@@ -269,6 +269,7 @@ class ElFinderConnector:
def __upload(self):
parent = self.data['target']
volume = self.get_volume(parent)
upload = self.data.get('upload[]')
if self.data.get('chunk') and self.data.get('cid'):
self.response.update(
volume.upload_as_chunk(
......@@ -279,6 +280,8 @@ class ElFinderConnector:
self.response.update(
volume.upload_chunk_merge(parent, self.data.get('chunk'))
)
elif isinstance(upload, str):
self.response.update(volume.upload_as_url(upload, parent))
else:
self.response.update(volume.upload(self.request.files, parent))
......
import stat
import threading
import tempfile
from flask import send_file
import requests
from coco.utils import get_logger
from .base import BaseVolume
......@@ -87,7 +89,7 @@ class SFTPVolume(BaseVolume):
def list(self, target, name_only=False):
""" Returns a list of files/directories in the target directory. """
path = self._path(target)
# print("List {}-{}".format(target, path))
print("List {} {}".format(target, path))
with self.lock:
return self._list(path)
......@@ -106,6 +108,7 @@ class SFTPVolume(BaseVolume):
获取目录的父目录, 如果deep为0,则直到根
"""
path = self._path(target).rstrip(self.path_sep)
print("Parents {} {}".format(target, path))
with self.lock:
return self._parents(path, depth=depth)
......@@ -177,6 +180,13 @@ class SFTPVolume(BaseVolume):
exist = False
return exist
def is_dir(self, path):
info = self._info(path)
if info['mime'] == 'directory':
return True
else:
return False
def paste(self, targets, dest, cut):
""" Moves/copies target files/directories from source to dest. """
print("Paste {} {} {}".format(targets, dest, cut))
......@@ -187,6 +197,8 @@ class SFTPVolume(BaseVolume):
for target in targets:
src_path = self._path(target)
dest_path = self._join(dest_parent_path, self._base_name(src_path))
if self.is_dir(src_path):
raise OSError("Copy folder unsupported now")
print("Paste {} to => {}".format(src_path, dest_parent_path))
if self.is_exist(dest_path):
print("Exist {}".format(dest_path))
......@@ -218,6 +230,19 @@ class SFTPVolume(BaseVolume):
raise OSError("Delete {} failed".format(self._base_name(path)))
return target
def upload_as_url(self, url, parent):
added = []
parent_path = self._path(parent)
path = self._join(parent_path, self._base_name(url))
remote_path = self._remote_path(path)
r = requests.get(url, stream=True)
with self.sftp.open(remote_path, 'w') as rf:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
rf.write(chunk)
added.append(self._info(path))
return {'added': added}
def upload(self, files, parent):
""" For now, this uses a very naive way of storing files - the entire
file is read in to the File model's content field in one go.
......
......@@ -390,7 +390,7 @@ class InternalSFTPClient(SFTPServer):
super().__init__(fake_server)
def listdir_attr(self, path):
return self.list_folder(path)
return self.list_folder.__wrapped__(self, path)
def open(self, path, mode, **kwargs):
client, rpath = self.get_sftp_client_rpath(path)
......
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