Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.