Skip to content

Commit

Permalink
feat: Recursively respecet folder structure on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
uhrjun committed Feb 15, 2023
1 parent 4937dc9 commit 0569f57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions drive/api/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
from drive.utils.files import get_user_directory, create_user_directory
from drive.locks.distributed_lock import DistributedLock

def if_folder_exists(folder_name, parent):
values = {"title": folder_name,"is_group": 1, "is_active": 1,"owner": frappe.session.user,"parent_drive_entity": parent}
existing_folder = frappe.db.get_value("Drive Entity", values, ['name', 'title', 'is_group', 'is_active'], as_dict=1)
if not existing_folder:
new_folder = create_folder(folder_name, parent)
return new_folder.name
else:
return existing_folder.name

@frappe.whitelist()
def upload_file(fullpath=None, parent=None):
Expand All @@ -41,16 +49,10 @@ def upload_file(fullpath=None, parent=None):
user_directory = create_user_directory()

parent = frappe.form_dict.parent or user_directory.name

if fullpath:
values = {"title": fullpath,"is_group": 1, "is_active": 1,"owner": frappe.session.user,"parent_drive_entity": parent}
existing_folder = frappe.db.get_value("Drive Entity", values, ['name', 'title', 'is_group', 'is_active'], as_dict=1)
if not existing_folder:
new_folder = create_folder(fullpath, parent)
parent = new_folder.name
print(parent)
else:
parent = existing_folder.name
dirname = os.path.dirname(fullpath).split("/")
for i in dirname:
parent = if_folder_exists(i, parent)

# Todo
# Recursively create folders
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ export default {
file.parent ? formData.append("parent", file.parent) : null
file.webkitRelativePath ? formData.append("fullpath", file.webkitRelativePath.slice(0, file.webkitRelativePath.indexOf("/"))) : null
// WARNING: dropzone hidden input element click does not append fullPath to formdata thats why webkitRelativePath was used
file.fullPath ? formData.append("fullpath", file.fullPath.slice(0, file.fullPath.indexOf("/"))) : null
file.webkitRelativePath ? formData.append("fullpath", file.webkitRelativePath) : null
file.fullPath ? formData.append("fullpath", file.fullPath) : null
},
params: function (files, xhr, chunk) {
if (chunk) {
Expand Down

0 comments on commit 0569f57

Please sign in to comment.