From 95bf6c092d553bec8d60da35a98cdfea1b459555 Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Tue, 30 Aug 2016 22:43:16 -0400 Subject: [PATCH] Switch to using uppy-thin module in Google Drive --- package.json | 1 + src/plugins/GoogleDrive/index.js | 85 +++++++++++++------------------- 2 files changed, 36 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index d3326cb24..4a2e93e3e 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "namespace-emitter": "1.0.0", "pretty-bytes": "3.0.1", "tus-js-client": "1.2.1", + "uppy-thin": "git+https://github.com/hedgerh/uppy-thin.git", "whatwg-fetch": "1.0.0", "yo-yo": "1.2.2" }, diff --git a/src/plugins/GoogleDrive/index.js b/src/plugins/GoogleDrive/index.js index b057b4147..b2b18392c 100644 --- a/src/plugins/GoogleDrive/index.js +++ b/src/plugins/GoogleDrive/index.js @@ -3,6 +3,8 @@ import Plugin from '../Plugin' import 'whatwg-fetch' import html from '../../core/html' +import {Provider} from 'uppy-thin' + import AuthView from './AuthView' import Browser from './Browser' import ErrorView from './Error' @@ -19,6 +21,11 @@ export default class Google extends Plugin { ` + this.GoogleDrive = new Provider({ + host: this.opts.host, + provider: 'google' + }) + this.files = [] // this.core.socket.on('') @@ -138,45 +145,35 @@ export default class Google extends Plugin { * @return {Promise} Folders/files in folder */ getFolder (id = 'root') { - return fetch(`${this.opts.host}/google/list?dir=${id}`, { - method: 'get', - credentials: 'include', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: { - demo: this.opts.demo - } - }) - .then((res) => { - if (res.status >= 200 && res.status <= 300) { - return res.json().then((data) => { - // let result = Utils.groupBy(data.items, (item) => item.mimeType) - let folders = [] - let files = [] - data.items.forEach((item) => { - if (item.mimeType === 'application/vnd.google-apps.folder') { - folders.push(item) - } else { - files.push(item) + return this.GoogleDrive.list(id) + .then((res) => { + if (res.status >= 200 && res.status <= 300) { + return res.json().then((data) => { + // let result = Utils.groupBy(data.items, (item) => item.mimeType) + let folders = [] + let files = [] + data.items.forEach((item) => { + if (item.mimeType === 'application/vnd.google-apps.folder') { + folders.push(item) + } else { + files.push(item) + } + }) + return { + folders, + files } }) - return { - folders, - files - } - }) - } else { - this.handleError(res) - let error = new Error(res.statusText) - error.response = res - throw error - } - }) - .catch((err) => { - return err - }) + } else { + this.handleError(res) + let error = new Error(res.statusText) + error.response = res + throw error + } + }) + .catch((err) => { + return err + }) } /** @@ -185,8 +182,6 @@ export default class Google extends Plugin { * @param {String} title Folder title */ getNextFolder (id, title) { - console.log(id) - console.log(title) this.getFolder(id) .then((data) => { const state = this.core.getState().googleDrive @@ -240,17 +235,7 @@ export default class Google extends Plugin { * Removes session token on client side. */ logout () { - fetch(`${this.opts.host}/google/logout?redirect=${location.href}`, { - method: 'get', - credentials: 'include', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: { - demo: this.opts.demo - } - }) + this.GoogleDrive.logout(location.href) .then((res) => res.json()) .then((res) => { if (res.ok) {