Skip to content

Commit 25d8aed

Browse files
committed
App: gdrive previews use correct thumbnail cache path
[skip ci]
1 parent 9910eb1 commit 25d8aed

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

‎scripts/gdrive_app.py‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,27 @@ def _process_item(self, item):
5353
try:
5454
from gdrive import gcache
5555
cache_path = gcache.get_cache_path_for_file(item)
56-
57-
if self.is_cancelled(): return
58-
59-
if cache_path and cache_path.exists():
56+
if not cache_path:
57+
return
58+
thumb_path = thumbnail_path_for_file(cache_path, shared=True, size='normal')
59+
if thumb_path.exists():
60+
img = QImage(str(thumb_path))
61+
elif cache_path.exists():
62+
if self.is_cancelled(): return
6063
if mime == 'application/pdf':
61-
thumbnail_bytes = pdfutils.get_cached_pdf_thumbnail(cache_path, size='large')
64+
thumbnail_bytes = pdfutils.get_cached_pdf_thumbnail(cache_path, size='normal')
6265
img = QImage()
6366
img.loadFromData(thumbnail_bytes)
6467
else:
65-
thumb_path = thumbnail_path_for_file(f"gdrive_{file_id}", size='large')
66-
if thumb_path.exists():
67-
img = QImage(str(thumb_path))
68-
else:
69-
if mime == 'application/pdf':
70-
if self.is_cancelled(): return
71-
thumbnail_bytes = gdrive_base.fetch_preview_image(file_id, size=256)
72-
if thumbnail_bytes:
73-
if self.is_cancelled(): return
74-
img = QImage()
75-
img.loadFromData(thumbnail_bytes)
76-
thumb_path.parent.mkdir(parents=True, exist_ok=True)
77-
thumb_path.write_bytes(thumbnail_bytes)
68+
if mime == 'application/pdf':
69+
if self.is_cancelled(): return
70+
thumbnail_bytes = gdrive_base.fetch_preview_image(file_id, size=128)
71+
if thumbnail_bytes:
72+
img = QImage()
73+
img.loadFromData(thumbnail_bytes)
74+
thumb_path.parent.mkdir(parents=True, exist_ok=True)
75+
# Yes, the thumb_path and the gdrive preview_image are both PNG
76+
thumb_path.write_bytes(thumbnail_bytes)
7877
except Exception as e:
7978
if not self.is_cancelled():
8079
print(f"Error fetching thumbnail for {file_id}: {e}")

‎scripts/local_gdrive.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,12 @@ def download_file_to_cache(self, file: dict, verbose: bool=False) -> Path | None
759759
pass
760760
else:
761761
raise e
762+
except gerrors.HttpError as e:
763+
if e.status_code == 403:
764+
print(f"You do not have permission to download {gdrive_base.GENERIC_LINK_PREFIX}{file['id']}")
765+
return None
766+
else:
767+
raise e
762768
else:
763769
try:
764770
if file['mimeType'] == 'application/vnd.google-apps.document':

0 commit comments

Comments
 (0)