mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-08-31 23:19:36 +00:00
Allow to upload folder
This commit is contained in:
@@ -909,6 +909,41 @@ error:
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
create_relative_path (RecvFSM *fsm, char *parent_dir, char **abs_path)
|
||||
{
|
||||
int rc = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
char *relative_path = g_hash_table_lookup (fsm->form_kvs, "relative_path");
|
||||
if (relative_path != NULL && strcmp(relative_path, "") != 0) {
|
||||
rc = seaf_repo_manager_mkdir_with_parents (seaf->repo_mgr,
|
||||
fsm->repo_id,
|
||||
parent_dir,
|
||||
relative_path,
|
||||
fsm->user,
|
||||
&error);
|
||||
if (rc < 0) {
|
||||
if (error) {
|
||||
seaf_warning ("[upload folder] %s.", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
*abs_path = g_new0 (char, SEAF_PATH_MAX);
|
||||
if (!*abs_path) {
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
strcat (*abs_path, parent_dir);
|
||||
strcat (*abs_path, relative_path);
|
||||
}
|
||||
|
||||
out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
Handle AJAX file upload.
|
||||
@return an array of json data, e.g. [{"name": "foo.txt"}]
|
||||
@@ -921,6 +956,7 @@ upload_ajax_cb(evhtp_request_t *req, void *arg)
|
||||
GError *error = NULL;
|
||||
int error_code = ERROR_INTERNAL;
|
||||
char *filenames_json, *tmp_files_json;
|
||||
int rc;
|
||||
|
||||
evhtp_headers_add_header (req->headers_out,
|
||||
evhtp_header_new("Access-Control-Allow-Headers",
|
||||
@@ -980,16 +1016,24 @@ upload_ajax_cb(evhtp_request_t *req, void *arg)
|
||||
filenames_json = file_list_to_json (fsm->filenames);
|
||||
tmp_files_json = file_list_to_json (fsm->files);
|
||||
|
||||
char *abs_path = NULL;
|
||||
rc = create_relative_path (fsm, parent_dir, &abs_path);
|
||||
if (rc < 0) {
|
||||
goto error;
|
||||
} else if (abs_path) {
|
||||
parent_dir = abs_path;
|
||||
}
|
||||
|
||||
char *ret_json = NULL;
|
||||
int rc = seaf_repo_manager_post_multi_files (seaf->repo_mgr,
|
||||
fsm->repo_id,
|
||||
parent_dir,
|
||||
filenames_json,
|
||||
tmp_files_json,
|
||||
fsm->user,
|
||||
0,
|
||||
&ret_json,
|
||||
&error);
|
||||
rc = seaf_repo_manager_post_multi_files (seaf->repo_mgr,
|
||||
fsm->repo_id,
|
||||
parent_dir,
|
||||
filenames_json,
|
||||
tmp_files_json,
|
||||
fsm->user,
|
||||
0,
|
||||
&ret_json,
|
||||
&error);
|
||||
g_free (filenames_json);
|
||||
g_free (tmp_files_json);
|
||||
if (rc < 0) {
|
||||
|
Reference in New Issue
Block a user