'use strict'

var path = require('path'),
  request = require('request'),
  qs = require('querystring'),
  Dropbox = require(path.resolve(__dirname, '../plugins/dropbox/dropbox.js')).Dropbox,
  Bitbucket = require(path.resolve(__dirname, '../plugins/bitbucket/bitbucket.js')).Bitbucket,
  Github = require(path.resolve(__dirname, '../plugins/github/github.js')).Github,
  Medium = require(path.resolve(__dirname, '../plugins/medium/medium.js')).Medium,
  GoogleDrive = require('../plugins/googledrive/googledrive.js').GoogleDrive,
  OneDrive = require('../plugins/onedrive/onedrive.js').OneDrive,
  Sponsored = require('../plugins/sponsored/sponsored.js'),
  GoogleAnalytics = require('../plugins/googleanalytics/googleanalytics.js');

// Show the home page
exports.index = function (req, res) {

  // Some flags to be set for client-side logic.
  var indexConfig = {
    isDropboxAuth: !!req.session.isDropboxSynced,
    isBitbucketAuth: !!req.session.isBitbucketSynced,
    isGithubAuth: !!req.session.isGithubSynced,
    isMediumAuth: !!req.session.isMediumSynced,
    isEvernoteAuth: !!req.session.isEvernoteSynced,
    isGoogleDriveAuth: !!req.session.isGoogleDriveSynced,
    isOneDriveAuth: !!req.session.isOneDriveSynced,
    isDropboxConfigured: Dropbox.isConfigured,
    isBitbucketConfigured: Bitbucket.isConfigured,
    isGithubConfigured: Github.isConfigured,
    isMediumConfigured: Medium.isConfigured,
    isGoogleDriveConfigured: GoogleDrive.isConfigured,
    isOneDriveConfigured: OneDrive.isConfigured,
    isSponsoredConfigured: Sponsored.isConfigEnabled,
    isGoogleAnalyticsConfigured: GoogleAnalytics.isConfigEnabled
  }

  // Capture Bitbucket username for the future...
  if (req.session.bitbucket && req.session.bitbucket.username) indexConfig.bitbucket_username = req.session.bitbucket.username
  else indexConfig.isBitbucketAuth = false

  // Capture github username for the future...
  if (req.session.github && req.session.github.username) indexConfig.github_username = req.session.github.username

  // If GA is enabled, let's create the HTML and tracking
  if (GoogleAnalytics.isConfigEnabled) {
    indexConfig.GATrackSponsoredLinksHTML = GoogleAnalytics.generateTrackSponsoredLinkClicks()
    indexConfig.GATrackingHTML = GoogleAnalytics.generateGATrackingJS()
  }

  // Check for Medium bits...
  if (req.session.medium && req.session.medium.oauth &&
    req.session.medium.oauth.token && req.session.medium.oauth.token.access_token) {
    // Set the access token on the medium client
    Medium.setAccessTokenFromSession(req.session.medium.oauth.token.access_token)
  } else {
    req.session.isMediumSynced = false
  }


  return res.render('index', indexConfig)

}

exports.privacy = function (req, res) {
  res.sendFile(path.resolve(__dirname, '..', 'public/privacy.html'))
}

// Show the not implemented yet page
exports.not_implemented = function (req, res) {
  res.render('not-implemented')
}

@@ -7,19 +7,21 @@
 trict'%0A%0A
-var
+const
  path = 
@@ -35,19 +35,22 @@
 ('path')
-,%0A 
+%0Aconst
  request
@@ -70,19 +70,22 @@
 equest')
-,%0A 
+%0Aconst
  qs = re
@@ -104,19 +104,22 @@
 string')
-,%0A 
+%0Aconst
  Dropbox
@@ -194,19 +194,22 @@
 .Dropbox
-,%0A 
+%0Aconst
  Bitbuck
@@ -292,19 +292,22 @@
 itbucket
-,%0A 
+%0Aconst
  Github 
@@ -378,19 +378,22 @@
 ).Github
-,%0A 
+%0Aconst
  Medium 
@@ -464,19 +464,22 @@
 ).Medium
-,%0A 
+%0Aconst
  GoogleD
@@ -545,19 +545,22 @@
 gleDrive
-,%0A 
+%0Aconst
  OneDriv
@@ -614,19 +614,22 @@
 OneDrive
-,%0A 
+%0Aconst
  Sponsor
@@ -677,19 +677,22 @@
 red.js')
-,%0A 
+%0Aconst
  GoogleA
@@ -762,9 +762,8 @@
 js')
-;
 %0A%0A//
@@ -820,17 +820,16 @@
  res) %7B%0A
-%0A
   // Som
@@ -875,11 +875,13 @@
 .%0A  
-var
+const
  ind
@@ -1775,32 +1775,38 @@
 bucket.username)
+ %7B%0A   
  indexConfig.bit
@@ -1855,16 +1855,18 @@
 ername%0A 
+ %7D
  else in
@@ -1913,20 +1913,20 @@
 Capture 
-gith
+GitH
 ub usern
@@ -2003,16 +2003,22 @@
 sername)
+ %7B%0A   
  indexCo
@@ -2067,16 +2067,20 @@
 username
+%0A  %7D
 %0A%0A  // I
@@ -2223,32 +2223,39 @@
  GoogleAnalytics
+%0A      
 .generateTrackSp
@@ -2474,16 +2474,20 @@
 token &&
+%0A   
  req.ses
@@ -2712,17 +2712,16 @@
 se%0A  %7D%0A%0A
-%0A
   return
@@ -2754,17 +2754,16 @@
 Config)%0A
-%0A
 %7D%0A%0Aexpor

make modern JS