Fix uploading bigfile to non-user directory
This commit is contained in:
parent
231df44c94
commit
c40f0c6919
2 changed files with 14 additions and 6 deletions
|
@ -126,7 +126,7 @@ class UiWebsocketPlugin(object):
|
||||||
nonce = CryptHash.random()
|
nonce = CryptHash.random()
|
||||||
piece_size = 1024 * 1024
|
piece_size = 1024 * 1024
|
||||||
inner_path = self.site.content_manager.sanitizePath(inner_path)
|
inner_path = self.site.content_manager.sanitizePath(inner_path)
|
||||||
file_info = self.site.content_manager.getFileInfo(inner_path)
|
file_info = self.site.content_manager.getFileInfo(inner_path, new_file=True)
|
||||||
|
|
||||||
content_inner_path_dir = helper.getDirname(file_info["content_inner_path"])
|
content_inner_path_dir = helper.getDirname(file_info["content_inner_path"])
|
||||||
file_relative_path = inner_path[len(content_inner_path_dir):]
|
file_relative_path = inner_path[len(content_inner_path_dir):]
|
||||||
|
@ -150,13 +150,13 @@ class UiWebsocketPlugin(object):
|
||||||
|
|
||||||
@PluginManager.registerTo("ContentManager")
|
@PluginManager.registerTo("ContentManager")
|
||||||
class ContentManagerPlugin(object):
|
class ContentManagerPlugin(object):
|
||||||
def getFileInfo(self, inner_path):
|
def getFileInfo(self, inner_path, *args, **kwargs):
|
||||||
if "|" not in inner_path:
|
if "|" not in inner_path:
|
||||||
return super(ContentManagerPlugin, self).getFileInfo(inner_path)
|
return super(ContentManagerPlugin, self).getFileInfo(inner_path, *args, **kwargs)
|
||||||
|
|
||||||
inner_path, file_range = inner_path.split("|")
|
inner_path, file_range = inner_path.split("|")
|
||||||
pos_from, pos_to = map(int, file_range.split("-"))
|
pos_from, pos_to = map(int, file_range.split("-"))
|
||||||
file_info = super(ContentManagerPlugin, self).getFileInfo(inner_path)
|
file_info = super(ContentManagerPlugin, self).getFileInfo(inner_path, *args, **kwargs)
|
||||||
return file_info
|
return file_info
|
||||||
|
|
||||||
def readFile(self, file_in, size, buff_size=1024 * 64):
|
def readFile(self, file_in, size, buff_size=1024 * 64):
|
||||||
|
|
|
@ -302,7 +302,7 @@ class ContentManager(object):
|
||||||
|
|
||||||
# Find the file info line from self.contents
|
# Find the file info line from self.contents
|
||||||
# Return: { "sha512": "c29d73d...21f518", "size": 41 , "content_inner_path": "content.json"}
|
# Return: { "sha512": "c29d73d...21f518", "size": 41 , "content_inner_path": "content.json"}
|
||||||
def getFileInfo(self, inner_path):
|
def getFileInfo(self, inner_path, new_file=False):
|
||||||
dirs = inner_path.split("/") # Parent dirs of content.json
|
dirs = inner_path.split("/") # Parent dirs of content.json
|
||||||
inner_path_parts = [dirs.pop()] # Filename relative to content.json
|
inner_path_parts = [dirs.pop()] # Filename relative to content.json
|
||||||
while True:
|
while True:
|
||||||
|
@ -338,6 +338,14 @@ class ContentManager(object):
|
||||||
else:
|
else:
|
||||||
back["content_inner_path"] = content_inner_path_dir + "content.json"
|
back["content_inner_path"] = content_inner_path_dir + "content.json"
|
||||||
back["optional"] = None
|
back["optional"] = None
|
||||||
|
back["relative_path"] = "/".join(inner_path_parts)
|
||||||
|
return back
|
||||||
|
|
||||||
|
if new_file and content:
|
||||||
|
back = {}
|
||||||
|
back["content_inner_path"] = content_inner_path
|
||||||
|
back["relative_path"] = "/".join(inner_path_parts)
|
||||||
|
back["optional"] = None
|
||||||
return back
|
return back
|
||||||
|
|
||||||
# No inner path in this dir, lets try the parent dir
|
# No inner path in this dir, lets try the parent dir
|
||||||
|
@ -874,7 +882,7 @@ class ContentManager(object):
|
||||||
else: # Check using sha512 hash
|
else: # Check using sha512 hash
|
||||||
file_info = self.getFileInfo(inner_path)
|
file_info = self.getFileInfo(inner_path)
|
||||||
if file_info:
|
if file_info:
|
||||||
if CryptHash.sha512sum(file) != file_info["sha512"]:
|
if CryptHash.sha512sum(file) != file_info.get("sha512", ""):
|
||||||
raise VerifyError("Invalid hash")
|
raise VerifyError("Invalid hash")
|
||||||
|
|
||||||
if file_info.get("size", 0) != file.tell():
|
if file_info.get("size", 0) != file.tell():
|
||||||
|
|
Loading…
Reference in a new issue