-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache preview images of docs locally & Fix showing doc preview issues #6
base: custom-oembed-provider
Are you sure you want to change the base?
Changes from all commits
537c983
540fcc0
18aa75a
165a371
5d1d5d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,18 @@ | |
// prevent direct access to this file. | ||
exit; | ||
} | ||
?> | ||
<div style="border: 1px solid #000; text-align: center;"> | ||
<a href="<?php echo esc_url( $drive_file_url ); ?>" title="<?php esc_attr_e( 'Open the Shared Document', 'rt-google-embeds' ); ?>" target="_blank" rel="noopener noreferrer" style="color: #cd2653;"> | ||
<?php esc_html_e( 'Open Shared Document.', 'rt-google-embeds' ); ?> | ||
</a> | ||
<img src="<?php echo esc_url( $thumbnail_url ); ?>" alt="<?php esc_attr_e( 'Shared Document Preview', 'rt-google-embeds' ); ?>" style="border: 1px solid #eee; margin: 15px auto; display: block;" /> | ||
</div> | ||
if ( file_exists( $cached_file ) ) : ?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There won't be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding https://github.com/rtCamp/wp-google-drive/pull/6/files#diff-59c6e676df5dade9eec1de91f5c5b44fR252-R253 lines, you'll only use the URL retrieved from Whenever network request is successful, you update the cached image. And when network request fails, you return the cached image URL. |
||
<div style="border: 1px solid #000; text-align: center;"> | ||
<a href="<?php echo esc_url( $drive_file_url ); ?>" title="<?php esc_attr_e( 'Open the Shared Document', 'rt-google-embeds' ); ?>" target="_blank" rel="noopener noreferrer" style="color: #cd2653;"> | ||
<?php esc_html_e( 'Open Shared Document.', 'rt-google-embeds' ); ?> | ||
</a> | ||
<img src="<?php echo esc_url( $cached_url ); ?>" alt="<?php esc_attr_e( 'Shared Document Preview from Cache', 'rt-google-embeds' ); ?>" style="border: 1px solid #eee; margin: 15px auto; display: block;" /> | ||
</div> | ||
<?php else : ?> | ||
<div style="border: 1px solid #000; text-align: center;"> | ||
<a href="<?php echo esc_url( $drive_file_url ); ?>" title="<?php esc_attr_e( 'Open the Shared Document', 'rt-google-embeds' ); ?>" target="_blank" rel="noopener noreferrer" style="color: #cd2653;"> | ||
<?php esc_html_e( 'Open Shared Document.', 'rt-google-embeds' ); ?> | ||
</a> | ||
<img src="<?php echo esc_url( $thumbnail_url ); ?>" alt="<?php esc_attr_e( 'Shared Document Preview', 'rt-google-embeds' ); ?>" style="border: 1px solid #eee; margin: 15px auto; display: block;" /> | ||
</div> | ||
<?php endif; ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to cache image which is being fetched on line 322 of this file too. And test once if it's working fine even after token is expired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try implementing this? Current
save_thumbnail
call will only work for public files, not for private files. In order for this to work with private files, you'll need to do what I've suggested above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also
get_thumbnail_url
function should return cached URL if network request fails. If all the network requests fails, then at the end you can check whether the file of this ID is already cached, if it is then send that URL.