Skip to content
This repository has been archived by the owner on Aug 6, 2018. It is now read-only.

Commit

Permalink
Encoding and some code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgerh committed May 5, 2016
1 parent 732221a commit 751fdde
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 66 deletions.
14 changes: 2 additions & 12 deletions server/controllers/google/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ module.exports = function * (next) {
var exportMimeType = fileTypes[file.mimeType.replace('application/vnd.google-apps.', '')]

// Pass mimeType of desired file type to export
// TODO: Google Docs, Sheets, etc, need to be passed different mimeTypes.
// 'application/...wordprocessingml.document' is for Google Docs files
//
google.get(`files/${self.query.fileId}/export`, {
auth: {
bearer: self.session.google.token
Expand All @@ -49,22 +46,17 @@ module.exports = function * (next) {
return cb()
}

fs.writeFile('./output/doc.docx', body, function (err, res) {
fs.writeFile(`./output/${self.query.fileId}`, body, {encoding: 'binary'}, function (err, res) {
if (err) {
console.log(err)
self.body = err
}
console.log('we did it')
self.body = 'ok'
self.status = 200
cb()
})
})
// self.status = 401
// self.body = 'Uppy Server does not currently support fetching Google documents'
// cb()
} else {
console.log('else')
// Fetch non-Google files
google.get(`files/${self.query.fileId}`, {
auth: {
Expand All @@ -75,13 +67,11 @@ module.exports = function * (next) {
}
}, function (err, res, body) {
if (err) {
console.log('fetcher')
console.log(err)
self.body = 'Error: ' + err
return cb()
}
// TODO: Figure out how to write with correct encoding (binary?)
fs.writeFile(`./output/${file.title}`, body, function (err, res) {
fs.writeFile(`./output/${file.title}`, body, {encoding: 'binary'}, function (err, res) {
if (err) {
console.log(err)
self.body = err
Expand Down
55 changes: 1 addition & 54 deletions server/controllers/google/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module.exports = function * (next) {
bearer: this.session.google.token
},
qs: {
q: query,
fields: 'items(createdDate,id,labels,mimeType,modifiedByMeDate,ownedByMe,parents,title,userPermission)'
q: query
}
}, function (err, res, body) {
if (err) {
Expand All @@ -30,55 +29,3 @@ module.exports = function * (next) {
})
}
}

// var google = require('googleapis')
// var GoogleAuth = require('google-auth-library')
// var config = require('../../../config/auth')

// var clientKey = config.drive.key
// var clientSecret = config.drive.secret
// var redirectUrl = config.server.url + config.drive.callback

// module.exports = function () {
// return function *(next) {
// console.log('getFolder')
// var service = google.drive('v2')
// var auth = new GoogleAuth()

// var oauth2Client = new auth.OAuth2(clientKey, clientSecret, redirectUrl)
// oauth2Client.credentials = this.session.drive.token
// var query = "'" + (this.query.dir || 'root') + "' in parents"

// yield function listFiles (cb) {
// var files = []

// var getList = (nextPageToken, callCount) => {
// service.files.list({
// auth : oauth2Client,
// query : query,
// fields : 'items(id,kind,mimeType,title),kind,nextPageToken',
// maxResults: 1000,
// pageToken : nextPageToken
// }, (err, res) => {
// if (err) {
// console.log(err)
// this.body = err
// return cb()
// }
// console.log(res)
// files.concat(res.items)

// if (res.nextPageToken) {
// getList(res.nextPageToken, callCount + 1)
// } else {
// this.body = {
// items: res.items
// }
// cb()
// }
// })
// }
// getList('', 1)
// }
// }
// }

0 comments on commit 751fdde

Please sign in to comment.