Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions gslides_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,11 @@ def _create_folder():

def delete_file(self, file_id):
"""
Deletes a file from Google Drive.
Permanently deletes a file from Google Drive (bypasses trash).

This method can delete any type of file including presentations, folders, images, etc.
The file is moved to the trash and can be restored from there unless permanently deleted.
Note: on Shared Drives, permanent deletion requires the ``canDelete``
capability (Manager role). Content Managers only have ``canTrash``.
Use :meth:`trash_file` when the caller only needs to discard the file.

:param file_id: The ID of the file to delete
:return: Empty response if successful
Expand All @@ -470,6 +471,33 @@ def _delete():

return _delete()

def trash_file(self, file_id):
"""
Moves a file to the trash in Google Drive.

Unlike :meth:`delete_file`, this only requires the ``canTrash``
capability, which Content Managers on Shared Drives have.

:param file_id: The ID of the file to trash
:return: The updated file metadata
:raises: Exception if the file doesn't exist or user doesn't have permission
"""
self.flush_batch_update()

@self._with_exponential_backoff
def _trash():
return (
self.drive_service.files()
.update(
fileId=file_id,
body={"trashed": True},
supportsAllDrives=True,
)
.execute()
)

return _trash()

def upload_image_to_drive(self, image_path, folder_id: str | None = None) -> str:
"""
Uploads an image to Google Drive and returns the public URL.
Expand Down