-
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
Google Drive files preview in WordPress #4
Comments
The preview is only shown if the GDrive app isn't muted by the user in slack, else only the link will be pasted. The generated preview is visible to anyone, restriction is only applicable to the access of the document that is shared. Following is screenshot shared in DM over slack, the preview was visible to a user who didn't have access. I checked for existing plugins that provide this feature. Here is a plugin that provides similar to what is described in this issue's description. The plugin uses shortcode/block to embed a file url, please refer this video for more info, created 2 files one with limited access and other with full access. Test post link: https://thrijith.dev1.rt.gw/2020/01/15/test-g-drive-embed/ @rahul286 is this what you expected to be achieved in WordPress? |
@thrijith thanks for recording video. :-) The key difference is UX.
I think the first point may be doable by using oEmbed hack. For the second one, we may need to find out what Slack does? I am not sure if Google Drive API has an endpoint for that. Let's try workflow for oEmbed + Slack-like-preview workflow for public Google Doc first. We can get into permission later. |
Ok, for now we want to generate a preview similar to what is done in slack for a public doc.
Will look into this in detail. @DevikVekariya @maitreyie-chavan I assuming above requirement to take 6-8 hours, which would include support for docs link in oEmbed along with search for an API from Google for image preview of the doc. |
Found https://developers.google.com/drive/api/v2/reference/files/get which is useful in getting info public docs, I tested out its API, it returns a response which contains thumbnail url. We need OAuth access to get information. Doc shared from my personal account.
The URL is accessible directly and can be used for generating preview. Doc shared from my rtCamp account.
This requires for the user to be signed in, for the image to be visible. |
Found a usable "endpoint" which is working in both cases, I'll use this in ombed to get our desired result. rtCamp A/c Doc :- https://drive.google.com/thumbnail?id=17UD5-q-chsslclOAf96muOozC0VNRAEzHm4OHlrm9yY Personal A/c Doc :- https://drive.google.com/thumbnail?id=0B2J7FcMmVjBBWk5OMWRBMlFUWmo1OFNGd0NaNUZ3UXRDLWlj |
Created a sample plugin to handle the embeds right now it works for Google Docs, will add support for others as well. The CSS isn't working in the backend, so need to check that as well. https://drive.google.com/file/d/1CdcybBapUQ9recncb90PFXeetYqmfHPF/view?usp=sharing |
I am mainly testing the feature on Classic Editor, Block Editor has some issue with embeds more details here WordPress/gutenberg#12421 Once support for public Google Sheets, Google Slides preview is added, will work on preview in editor. Current status with support for Docs can be seen in previous comment's link. |
Added support for Open docs in Classic Editor. Here is the current status : https://drive.google.com/drive/folders/1xvcK_bo3OGH3FiaZZVB116vDhedWPewM Have pushed code to a new repo for now, can change later if required. Repo: https://github.com/rtCamp/wp-google-drive/ cc: @rahul286 |
Doesn't support embedding in Block Editor at the moment, I have tested with patch in https://core.trac.wordpress.org/ticket/45447 which fixes the issue, once it lands in code the plugin should be able to embed URLs in Block Editor as well. Alpha release for internal testing : Link. Please test using this zip : Link. Demo for Classic Editor : Link Demo for Classic Editor Block : Link cc: @rahul286 |
I have tested the preview in both classic editor and classic editor block it works as expected for the public links. For a preview of private links to work the user should be logged in and as primary account if there are multiple google accounts logged in. |
I have added comment on the Trac ticket to get an idea on the status of merging it into core. The Calls to methods used in the said method which is part other classes have filters, and public methods which could be overridden ( need to check in detail for implementation ), even if that is possible, doing so for supporting embeds is not clean code. As of now, any one hoping to use this in Block Editor would have to take help of the |
@thrijith I will need to get on a call to understand this better. The user experience is very important |
@rahul286 Sure, I'll ping you as soon as I am free from other tasks. |
Adding the support as a oEmbed Provider didn't work either, as we are not using any embed provider to achieve this, since we have custom requirement which adds just the preview of the document in an image tag. Drive doesn't seem to have an oEmbed endpoint for thumbnail preview, we used
☝️ from the function description, this is our use case, so we could add a Google Drive Embed block to support embeds in Block Editor. Please let me know if I should proceed with custom Block to support URL embeds in Block Editor. |
Adding a custom block is fine but from a UX perspective. If you notice with YouTube URLs, just pasting URL as well as adding YouTube block and then pasting URL in it works. The same seamless behavior we need for Google Drive. For now, let's create a custom block for Google Drive "embed" (preview). We will explore how we can trigger preview simply by pasting the URL later. |
Since Youtube is a whitelisted provider it works out of the box ( ref ) and embeds when a user pastes the URL. If we were to add support for a service using oEmbed, whitelisting and adding provider would have worked as well. The thumbnail preview is added using custom code but not an oEmbed URL, we use Since it does work on Classic Editor, but not on Block Editor due the issue mentioned earlier, I'll add Custom Block to handle this. |
@thrijith can we create a middleware like oEmbed-proxy. We will put a domain such as I am not sure but dont code above for now. We need to do more research and dicussion for now. We will jump to code once we have a blueprint. |
Yes, I think this could be done. Should I add the custom block or check on the above possibility? |
Working on block for now, we can add middleware after research. |
Added block for preview of drive file in block editor. cc: @rahul286 @deepaklalwani97 please test the block and let me know in case of any concerns. Zip of the plugin with latest changes. |
@thrijith I have tested the latest zip with block. The preview for shared documents with the Gutenberg block works as expected. |
Current status of the plugin. What happens if you paste a Google Drive file link which is shared publicly? In Classic Editor - ✅ In Block Editor directly - Doesn't work due to core issue. - ❎ In Block Editor's In Block Editor, we have a new block to add file preview, which works when you paste the shared file URL. ✅ What is remaining? The ability to directly paste the link and embed the URL in Block Editor directly without depending on any block. To fix this we need to create an oEmbed handler which gives proper response, and have to whitelist our provider so that it works in Block Editor as well. |
@rahul286 @thrijith I've also removed no preview image in case of an invalid URL or private file. I've returned 404 instead, by doing this the default Embed block gives an option to convert the URL into a link. In classic editor, it'll do nothing if the file is private or when URL is invalid, else it'll generate the preview. Video - https://drive.google.com/file/d/1fzJHR6o7j9cpifYjBu1qqkopluacxYie/view?usp=sharing |
@SID177 |
@DevikVekariya |
@maitreyie-chavan I have started testing it but having an issue. When I copy the URL by copying the link, it generates such a URL https://docs.google.com/document/d/1MVE8ufd_52kR95AW4lV_j_5EubCQtWe9ECtRQCCVn6k/edit?usp=sharing and it doesn't work. It gives the error of invalid embed @SID177 is looking into this. |
@juhi123 Thank you for the update. Any PR reviews required for this task can be assigned to Thrijith. |
@juhi123 I've fixed the issue. Now it'll extract ID from https://docs.google.com/document/d/1MVE8ufd_52kR95AW4lV_j_5EubCQtWe9ECtRQCCVn6k/edit type of URLs and show the preview. The PR #3 is approved by Thrijith. |
@SID177 |
BTW do we have any control over preview fonts and appearance, it's not quite visible |
@itowhid06 Can you please check this issue #4 (comment) and work on it? |
Okay noted 📝 . |
Thanks @thrijith 🙏 I hope you are doing well and staying safe! 💪 |
Hi @pdclark, I didn't get a chance to test / verify this, but I believe sheets should work based on don't see drawings support in the code, so that should be added. |
The regexes look correct. Any ideas for a fix? Or do presentations work for others?
|
Whenever we share Google doc, sheet or slide in Slack, it automatically displays the file preview.
Maybe we need to create a Google console app and use some APIs that are not private.
Please note we will require to handle access control e.g. somebody who is currently viewing may not supposed to even look at the preview.
Overall, the first step is to understand how Slack displays Google Docs preview. I hope the Google API for this is public.
The text was updated successfully, but these errors were encountered: