Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Add Dropbox integration
Browse files Browse the repository at this point in the history
  • Loading branch information
curtgrimes committed Oct 29, 2018
1 parent 558eeec commit 59855af
Show file tree
Hide file tree
Showing 21 changed files with 9,963 additions and 9,903 deletions.
1 change: 1 addition & 0 deletions app/api/routes/index.js
Expand Up @@ -2,5 +2,6 @@ const routes = require('express').Router();

routes.use('/rooms', require('./rooms'));
routes.use('/charges', require('./charges'));
routes.use('/storage', require('./storage'));

module.exports = routes;
181 changes: 181 additions & 0 deletions app/api/routes/storage/dropbox/index.js
@@ -0,0 +1,181 @@
const dropboxRoute = require('express').Router();
const Dropbox = require('dropbox').Dropbox;
const axios = require('axios');
const fetch = require('isomorphic-fetch');
const {format: dateFormat} = require('date-fns');

function getDropboxClient() {
return new Dropbox({clientId: 'v7642g8xms9wmlf', fetch});
}

dropboxRoute.get('/auth', async (req, res, next) => {
// Redirect to login page
const dropboxClient = getDropboxClient();
res.redirect(302, dropboxClient.getAuthenticationUrl(process.env.HOSTNAME + '/captioner/settings/dropbox'));
});

dropboxRoute.post('/auth-revoke', async (req, res, next) => {
const {accessToken} = req.body;

if (!accessToken) {
// Missing required params
res.sendStatus(400);
return;
}

const dropboxClient = getDropboxClient();
dropboxClient.setAccessToken(accessToken);
dropboxClient.authTokenRevoke()
.then(response => {
res.sendStatus(200);
})
.catch(error => {
console.log('error revoking token');
console.log(error);
res.sendStatus(400);
});
});

// Get the current user profile
dropboxRoute.get('/profile', async (req, res, next) => {
const {accessToken, accountId} = req.query;

if (!accessToken || !accountId) {
// Missing required params
res.sendStatus(400);
return;
}

const dropboxClient = getDropboxClient();
dropboxClient.setAccessToken(accessToken);

dropboxClient.usersGetAccount({account_id: accountId})
.then(response => {
res.json(response);
})
.catch(error => {
res.send(400);
});

});

dropboxRoute.post('/push', async (req, res) => {
const {contents, accessToken, sessionStartDate} = req.body;

if (!contents || !accessToken || !sessionStartDate) {
// Missing required params
res.sendStatus(400);
return;
}

const dropboxClient = getDropboxClient();
dropboxClient.setAccessToken(accessToken);

dropboxClient.filesUpload({
path: '/Transcripts/' + dateFormat(sessionStartDate, 'YYYY-MM-DD HH.mm.ss') + '.txt',
contents,
mode: 'overwrite',
})
.then(function(response) {
res.sendStatus(200);
})
.catch(function(error) {
res.sendStatus(400);
});
});

dropboxRoute.get('/transcripts', async (req, res, next) => {
const {accessToken, cursor} = req.query;

if (!accessToken) {
// Missing required param
res.sendStatus(400);
return;
}

const dropboxClient = getDropboxClient();
dropboxClient.setAccessToken(accessToken);

if (!cursor) {
// First check
dropboxClient.filesListFolder({
path: '/Transcripts',
recursive: false,
include_media_info: false,
include_deleted: false,
})
.then(result => {
res.json({
has_more: result.has_more,
cursor: result.cursor,
files: (result.entries || []).map(entry => {
return {
name: entry.name,
size: entry.size,
};
}),
});
})
.catch(error => {
console.log(error);
res.sendStatus(400);
});
}
else {
// Additional check with given cursor
dropboxClient.filesListFolderContinue({
cursor,
})
.then(result => {
res.json({
has_more: result.has_more,
cursor: result.cursor,
files: (result.entries || []).map(entry => {
return {
name: entry.name,
size: entry.size,
};
}),
});
})
.catch(error => {
console.log(error);
res.sendStatus(400);
});
}

});

dropboxRoute.get('/transcripts/:fileName', async (req, res, next) => {
const {accessToken} = req.query;
const {fileName} = req.params;

if (!accessToken || !fileName) {
// Missing required param
res.sendStatus(400);
return;
}

const dropboxClient = getDropboxClient();
dropboxClient.setAccessToken(accessToken);

dropboxClient.filesGetTemporaryLink({
path: '/Transcripts/' + fileName + '.txt'
})
.then(result => {
if (result.link) {
console.log(result);
res.redirect(result.link);
}
else {
res.sendStatus(400);
}
})
.catch(error => {
console.log(error);
res.sendStatus(400);
});

});

module.exports = dropboxRoute;
5 changes: 5 additions & 0 deletions app/api/routes/storage/index.js
@@ -0,0 +1,5 @@
const routes = require('express').Router();

routes.use('/dropbox', require('./dropbox'));

module.exports = routes;
2 changes: 1 addition & 1 deletion app/assets/scss/app.scss
Expand Up @@ -3,7 +3,7 @@

@font-face {
font-family: "Redacted";
src: url("~/static/static/redacted-regular.ttf");
src: url("~/static/redacted-regular.ttf");
}

$font-family-sans-serif: 'Roboto', sans-serif;
Expand Down
11 changes: 5 additions & 6 deletions app/nuxt.config.js
Expand Up @@ -87,15 +87,14 @@ module.exports = {
},
{
set: '@fortawesome/free-brands-svg-icons',
icons: ['faApple', 'faWindows', 'faAndroid', 'faChrome', 'faTwitter', 'faFacebook',],
icons: ['faApple', 'faWindows', 'faAndroid', 'faChrome', 'faTwitter', 'faFacebook', 'faDropbox'],
},
]
}],
],
plugins: [
{ src: '~/plugins/websocket', ssr: false },
'~/plugins/vue-timeago',
'~/node_modules/vue-contenteditable-directive',
'~/plugins/performance.js',
],
css: [
Expand Down Expand Up @@ -125,8 +124,8 @@ module.exports = {
/*
** Run ESLint on save
*/
extend (config, { isDev, isClient, isServer }) {
if (isDev && isClient) {
extend (config, { isDev }) {
if (isDev && process.client) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
Expand All @@ -135,11 +134,11 @@ module.exports = {
})
}

if (isClient) {
if (process.client) {
config.devtool = '#source-map';
}

if (isServer) {
if (process.server) {

}
}
Expand Down

0 comments on commit 59855af

Please sign in to comment.