Skip to content

Commit

Permalink
Resolve #101 | Fix -d flag for team drives
Browse files Browse the repository at this point in the history
  • Loading branch information
Akianonymus committed Aug 12, 2020
1 parent 88f77b8 commit 8bdbb90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions bash/drive-utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ _drive_info() {
"${EXTRA_LOG}" "justify" "Fetching info.." "-" 1>&2
search_response="$(curl --compressed "${CURL_PROGRESS_EXTRA}" \
-H "Authorization: Bearer ${token}" \
"${API_URL}/drive/${API_VERSION}/files/${folder_id}?fields=${fetch}&supportsAllDrives=true" || :)" && _clear_line 1 1>&2
"${API_URL}/drive/${API_VERSION}/files/${folder_id}?fields=${fetch}&supportsAllDrives=true&includeItemsFromAllDrives=true" || :)" && _clear_line 1 1>&2
_clear_line 1 1>&2

printf "%b" "${search_response:+${search_response}\n}"
Expand All @@ -82,11 +82,11 @@ _check_existing_file() {
declare query search_response id

"${EXTRA_LOG}" "justify" "Checking if file" " exists on gdrive.." "-" 1>&2
query="$(_url_encode "name='${name}' and '${rootdir}' in parents and trashed=false and 'me' in writers")"
query="$(_url_encode "name='${name}' and '${rootdir}' in parents and trashed=false")"

search_response="$(curl --compressed "${CURL_PROGRESS_EXTRA}" \
-H "Authorization: Bearer ${token}" \
"${API_URL}/drive/${API_VERSION}/files?q=${query}&fields=files(id,name,mimeType)&supportsAllDrives=true" || :)" && _clear_line 1 1>&2
"${API_URL}/drive/${API_VERSION}/files?q=${query}&fields=files(id,name,mimeType)&supportsAllDrives=true&includeItemsFromAllDrives=true" || :)" && _clear_line 1 1>&2
_clear_line 1 1>&2

{ _json_value id 1 1 <<< "${search_response}" 2>| /dev/null 1>&2 && printf "%s\n" "${search_response}"; } || return 1
Expand Down Expand Up @@ -116,7 +116,7 @@ _create_directory() {

search_response="$(curl --compressed "${CURL_PROGRESS_EXTRA}" \
-H "Authorization: Bearer ${token}" \
"${API_URL}/drive/${API_VERSION}/files?q=${query}&fields=files(id)&supportsAllDrives=true" || :)" && _clear_line 1 1>&2
"${API_URL}/drive/${API_VERSION}/files?q=${query}&fields=files(id)&supportsAllDrives=true&includeItemsFromAllDrives=true" || :)" && _clear_line 1 1>&2

if ! folder_id="$(printf "%s\n" "${search_response}" | _json_value id 1 1)"; then
declare create_folder_post_data create_folder_response
Expand All @@ -126,7 +126,7 @@ _create_directory() {
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/json; charset=UTF-8" \
-d "${create_folder_post_data}" \
"${API_URL}/drive/${API_VERSION}/files?fields=id&supportsAllDrives=true" || :)" && _clear_line 1 1>&2
"${API_URL}/drive/${API_VERSION}/files?fields=id&supportsAllDrives=true&includeItemsFromAllDrives=true" || :)" && _clear_line 1 1>&2
fi
_clear_line 1 1>&2

Expand Down Expand Up @@ -261,7 +261,7 @@ _upload_file() {
else
request_method="PATCH"
_file_id="$(_json_value id 1 1 <<< "${file_check_json}")" || { _error_logging_upload "${slug}" "${file_check_json}" && return 1; }
url="${API_URL}/upload/drive/${API_VERSION}/files/${_file_id}?uploadType=resumable&supportsAllDrives=true"
url="${API_URL}/upload/drive/${API_VERSION}/files/${_file_id}?uploadType=resumable&supportsAllDrives=true&includeItemsFromAllDrives=true"
# JSON post data to specify the file name and folder under while the file to be updated
postdata="{\"mimeType\": \"${mime_type}\",\"name\": \"${slug}\",\"addParents\": [\"${folder_id}\"]}"
STRING="Updated"
Expand All @@ -273,7 +273,7 @@ _upload_file() {

# Set proper variables for creating files
[[ ${job} = create ]] && {
url="${API_URL}/upload/drive/${API_VERSION}/files?uploadType=resumable&supportsAllDrives=true"
url="${API_URL}/upload/drive/${API_VERSION}/files?uploadType=resumable&supportsAllDrives=true&includeItemsFromAllDrives=true"
request_method="POST"
# JSON post data to specify the file name and folder under while the file to be created
postdata="{\"mimeType\": \"${mime_type}\",\"name\": \"${slug}\",\"parents\": [\"${folder_id}\"]}"
Expand Down Expand Up @@ -456,7 +456,7 @@ _clone_file() {
curl --compressed -s \
-X DELETE \
-H "Authorization: Bearer ${token}" \
"${API_URL}/drive/${API_VERSION}/files/${_file_id}?supportsAllDrives=true" 2>| /dev/null 1>&2 || :
"${API_URL}/drive/${API_VERSION}/files/${_file_id}?supportsAllDrives=true&includeItemsFromAllDrives=true" 2>| /dev/null 1>&2 || :
STRING="Updated"
else
_collect_file_info "${file_check_json}" || return 1
Expand All @@ -475,7 +475,7 @@ _clone_file() {
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/json; charset=UTF-8" \
-d "${clone_file_post_data}" \
"${API_URL}/drive/${API_VERSION}/files/${file_id}/copy?supportsAllDrives=true" || :)"
"${API_URL}/drive/${API_VERSION}/files/${file_id}/copy?supportsAllDrives=true&includeItemsFromAllDrives=true" || :)"
for _ in 1 2 3; do _clear_line 1; done
_collect_file_info "${clone_file_response}" || return 1
"${QUIET:-_print_center}" "justify" "${name} " "| ${readable_size} | ${STRING}" "="
Expand Down
16 changes: 8 additions & 8 deletions sh/drive-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ _drive_info() {
"${EXTRA_LOG}" "justify" "Fetching info.." "-" 1>&2
search_response_drive_info="$(curl --compressed "${CURL_PROGRESS_EXTRA}" \
-H "Authorization: Bearer ${token_drive_info}" \
"${API_URL}/drive/${API_VERSION}/files/${folder_id_drive_info}?fields=${fetch_drive_info}&supportsAllDrives=true" || :)" && _clear_line 1 1>&2
"${API_URL}/drive/${API_VERSION}/files/${folder_id_drive_info}?fields=${fetch_drive_info}&supportsAllDrives=true&includeItemsFromAllDrives=true" || :)" && _clear_line 1 1>&2
_clear_line 1 1>&2

printf "%b" "${search_response_drive_info:+${search_response_drive_info}\n}"
Expand Down Expand Up @@ -86,7 +86,7 @@ _check_existing_file() (

response_check_existing_file="$(curl --compressed "${CURL_PROGRESS_EXTRA}" \
-H "Authorization: Bearer ${token_check_existing_file}" \
"${API_URL}/drive/${API_VERSION}/files?q=${query_check_existing_file}&fields=files(id,name,mimeType)&supportsAllDrives=true" || :)" && _clear_line 1 1>&2
"${API_URL}/drive/${API_VERSION}/files?q=${query_check_existing_file}&fields=files(id,name,mimeType)&supportsAllDrives=true&includeItemsFromAllDrives=true" || :)" && _clear_line 1 1>&2
_clear_line 1 1>&2

{ printf "%s\n" "${response_check_existing_file}" | _json_value id 1 1 2>| /dev/null 1>&2 && printf "%s\n" "${response_check_existing_file}"; } || return 1
Expand Down Expand Up @@ -116,7 +116,7 @@ _create_directory() (

search_response_create_directory="$(curl --compressed "${CURL_PROGRESS_EXTRA}" \
-H "Authorization: Bearer ${token_create_directory}" \
"${API_URL}/drive/${API_VERSION}/files?q=${query_create_directory}&fields=files(id)&supportsAllDrives=true" || :)" && _clear_line 1 1>&2
"${API_URL}/drive/${API_VERSION}/files?q=${query_create_directory}&fields=files(id)&supportsAllDrives=true&includeItemsFromAllDrives=true" || :)" && _clear_line 1 1>&2

if ! folder_id_create_directory="$(printf "%s\n" "${search_response_create_directory}" | _json_value id 1 1)"; then
unset create_folder_post_data_create_directory create_folder_response_create_directory
Expand All @@ -126,7 +126,7 @@ _create_directory() (
-H "Authorization: Bearer ${token_create_directory}" \
-H "Content-Type: application/json; charset=UTF-8" \
-d "${create_folder_post_data_create_directory}" \
"${API_URL}/drive/${API_VERSION}/files?fields=id&supportsAllDrives=true" || :)" && _clear_line 1 1>&2
"${API_URL}/drive/${API_VERSION}/files?fields=id&supportsAllDrives=true&includeItemsFromAllDrives=true" || :)" && _clear_line 1 1>&2
fi
_clear_line 1 1>&2

Expand Down Expand Up @@ -263,7 +263,7 @@ _upload_file() {
else
request_method_upload_file="PATCH"
_file_id_upload_file="$(printf "%s\n" "${file_check_json_upload_file}" | _json_value id 1 1)" || { _error_logging_upload "${slug_upload_file}" "${file_check_json_upload_file}" && return 1; }
url_upload_file="${API_URL}/upload/drive/${API_VERSION}/files/${_file_id_upload_file}?uploadType=resumable&supportsAllDrives=true"
url_upload_file="${API_URL}/upload/drive/${API_VERSION}/files/${_file_id_upload_file}?uploadType=resumable&supportsAllDrives=true&includeItemsFromAllDrives=true"
# JSON post data to specify the file name and folder under while the file to be updated
postdata_upload_file="{\"mimeType\": \"${mime_type_upload_file}\",\"name\": \"${slug_upload_file}\",\"addParents\": [\"${folder_id_upload_file}\"]}"
STRING="Updated"
Expand All @@ -275,7 +275,7 @@ _upload_file() {
# Set proper variables for creating files
[ "${job_upload_file}" = create ] && {
url_upload_file="${API_URL}/upload/drive/${API_VERSION}/files?uploadType=resumable&supportsAllDrives=true"
url_upload_file="${API_URL}/upload/drive/${API_VERSION}/files?uploadType=resumable&supportsAllDrives=true&includeItemsFromAllDrives=true"
request_method_upload_file="POST"
# JSON post data to specify the file name and folder under while the file to be created
postdata_upload_file="{\"mimeType\": \"${mime_type_upload_file}\",\"name\": \"${slug_upload_file}\",\"parents\": [\"${folder_id_upload_file}\"]}"
Expand Down Expand Up @@ -461,7 +461,7 @@ _clone_file() {
curl --compressed -s \
-X DELETE \
-H "Authorization: Bearer ${token_clone_file}" \
"${API_URL}/drive/${API_VERSION}/files/${_file_id_clone_file}?supportsAllDrives=true" 2>| /dev/null 1>&2 || :
"${API_URL}/drive/${API_VERSION}/files/${_file_id_clone_file}?supportsAllDrives=true&includeItemsFromAllDrives=true" 2>| /dev/null 1>&2 || :
STRING="Updated"
else
_collect_file_info "${file_check_json_clone_file}" "${name_clone_file}" || return 1
Expand All @@ -480,7 +480,7 @@ _clone_file() {
-H "Authorization: Bearer ${token_clone_file}" \
-H "Content-Type: application/json; charset=UTF-8" \
-d "${post_data_clone_file}" \
"${API_URL}/drive/${API_VERSION}/files/${file_id_clone_file}/copy?supportsAllDrives=true" || :)"
"${API_URL}/drive/${API_VERSION}/files/${file_id_clone_file}/copy?supportsAllDrives=true&includeItemsFromAllDrives=true" || :)"
for _ in 1 2 3; do _clear_line 1; done
_collect_file_info "${response_clone_file}" "${name_clone_file}" || return 1
"${QUIET:-_print_center}" "justify" "${name_clone_file} " "| ${readable_size_clone_file} | ${STRING}" "="
Expand Down

0 comments on commit 8bdbb90

Please sign in to comment.