Switch to using uppy-thin module in Google Drive

This commit is contained in:
Harry Hedger 2016-08-30 22:43:16 -04:00
parent 6cc5469cd2
commit 95bf6c092d
2 changed files with 36 additions and 50 deletions

View file

@ -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"
},

View file

@ -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 {
</svg>
`
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) {