Skip to content

Instantly share code, notes, and snippets.

@robertknight
Created August 22, 2019 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertknight/c831ba788cf850be97ac50006ee3540d to your computer and use it in GitHub Desktop.
Save robertknight/c831ba788cf850be97ac50006ee3540d to your computer and use it in GitHub Desktop.
Cross-site file fetching test in the Hypothesis LMS app
diff --git a/lms/static/scripts/frontend_apps/components/FilePickerApp.js b/lms/static/scripts/frontend_apps/components/FilePickerApp.js
index 1e32c81..a040a75 100644
--- a/lms/static/scripts/frontend_apps/components/FilePickerApp.js
+++ b/lms/static/scripts/frontend_apps/components/FilePickerApp.js
@@ -91,9 +91,11 @@ export default function FilePickerApp({
try {
setLoadingIndicatorVisible(true);
const { id, url } = await googlePicker.showPicker();
+ await googlePicker.fetchFile(id);
await googlePicker.enablePublicViewing(id);
setUrl(url);
- submit(true);
+ // TESTING
+ // submit(true);
} catch (error) {
setLoadingIndicatorVisible(false);
if (!(error instanceof PickerCanceledError)) {
diff --git a/lms/static/scripts/frontend_apps/utils/google-picker-client.js b/lms/static/scripts/frontend_apps/utils/google-picker-client.js
index 44877c0..c3db8d0 100644
--- a/lms/static/scripts/frontend_apps/utils/google-picker-client.js
+++ b/lms/static/scripts/frontend_apps/utils/google-picker-client.js
@@ -124,6 +124,30 @@ export class GooglePickerClient {
});
}
+ async fetchFile(docId) {
+ const gapiClient = await this._gapiClient;
+
+ await gapiClient.init({
+ apiKey: this._developerKey,
+ clientId: this._clientId,
+ discoveryDocs: [
+ 'https://www.googleapis.com/discovery/v1/apis/drive/v3/rest',
+ ],
+ scope: GOOGLE_DRIVE_SCOPE,
+ });
+
+ const request = gapiClient.drive.files.get({
+ fileId: docId,
+ alt: 'media',
+ });
+
+ return request.then(result => {
+ console.log('Google Drive fetch request result', result);
+ }).catch(err => {
+ console.log('Google Drive fetch request failure', err);
+ });
+ }
+
/**
* Change the sharing settings on a document in Google Drive to make it
* publicly viewable to anyone with the link.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment