We've had so many projects lately, that it's quite some work to prepare them all for release! Today, we're excited to share a Google Drive Media Source for MODX3 that we built for Catch Media.
The goal was pretty simple: get part of a clients' Google Drive storage to show up in the media browser, and be available as if it were any other media source across MODX.
The actual development ended up being a lot more complex than initially assumed, and it took some time to work out all the quirks, get performance to where we wanted it, and sort out compatibility issues in both the MODX core and third party extras. Luckily I like to be challenged and the people at Catch were very helpful, so eventually we did get it done.
Here's a selection of what it can do:
- Authenticate a Google account with OAuth, using your own client credentials.
- Various ways to define the root of the media source. Once authenticated, the media source will let you choose:
- any folder in the root of the authenticated users' account
- any shortcut, located in the root of the authenticated users' account, pointing to a folder anywhere in the users' account
- any Shared Drive (formerly Team Drive) the authenticated user has access to
- any folder that was shared with the authenticated user
- Browse nested folders
- Names of files and folders in the tree/browser are their friendly names, while internally the IDs of them in Google Drive are used
- Create / update / delete (archive) / download most file types
- Create / rename / delete folders
- Standard programmatic interactions through the Media Source API
- Google Drive native file types, like Google Docs, Sheets, or Slides, are exportable from within MODX as typical formats (e.g. PDF, Word, or Excel)
- Confirmed compatibility with core TVs, Image+, MoreGallery, and ContentBlocks
Files or images are served up through a local proxy. This means the
media source generates URLs based on the internal Google Drive ID, for
https://assets.mysite.com/a1b2c3d4e5, and the Media Source will dynamically fetch the file by its ID and serve it up with proper headers and file type.
To boost performance, both file metadata and the file content are
cached. And for security, only files that are within your configured
media source root can be returned.
All in all, this was very interesting to build!