Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
Oauth2_ssd
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dumindu Sanjana Hettiarachchi
Oauth2_ssd
Commits
79546138
Commit
79546138
authored
Oct 06, 2020
by
Dumindu Sanjana Hettiarachchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
255948d9
Pipeline
#1704
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
routes/home.js
routes/home.js
+82
-0
No files found.
routes/home.js
0 → 100644
View file @
79546138
const
{
Router
}
=
require
(
'
express
'
)
const
passport
=
require
(
'
passport
'
)
const
{
google
}
=
require
(
'
googleapis
'
)
const
KEYS
=
require
(
'
../configs/keys
'
)
const
router
=
Router
()
router
.
get
(
'
/
'
,
function
(
req
,
res
)
{
res
.
render
(
'
home.html
'
,
{
'
title
'
:
'
Application Home
'
})
})
router
.
get
(
'
/dashboard
'
,
function
(
req
,
res
)
{
// if not user
if
(
typeof
req
.
user
==
"
undefined
"
)
res
.
redirect
(
'
/auth/login/google
'
)
else
{
let
parseData
=
{
title
:
'
File Uploader
'
,
googleid
:
req
.
user
.
_id
,
name
:
req
.
user
.
name
,
avatar
:
req
.
user
.
pic_url
,
email
:
req
.
user
.
email
}
// redirect with google drive response will be
if
(
req
.
query
.
file
!==
undefined
)
{
// successfully upload the file
if
(
req
.
query
.
file
==
"
upload
"
)
parseData
.
file
=
"
uploaded
"
else
if
(
req
.
query
.
file
==
"
notupload
"
)
parseData
.
file
=
"
notuploaded
"
}
res
.
render
(
'
dashboard.html
'
,
parseData
)
}
})
router
.
post
(
'
/uploadtheFile
'
,
function
(
req
,
res
)
{
// not auth
if
(
!
req
.
user
)
res
.
redirect
(
'
/auth/login/google
'
)
else
{
// auth user
// config google drive with client token
const
oauth2Client
=
new
google
.
auth
.
OAuth2
()
oauth2Client
.
setCredentials
({
'
access_token
'
:
req
.
user
.
accessToken
});
const
drive
=
google
.
drive
({
version
:
'
v3
'
,
auth
:
oauth2Client
});
//move file to google drive
let
{
name
:
filename
,
mimetype
,
data
}
=
req
.
files
.
file_upload
const
driveResponse
=
drive
.
files
.
create
({
requestBody
:
{
name
:
filename
,
mimeType
:
mimetype
},
media
:
{
mimeType
:
mimetype
,
body
:
Buffer
.
from
(
data
).
toString
()
}
});
driveResponse
.
then
(
data
=>
{
if
(
data
.
status
==
200
)
res
.
redirect
(
'
/dashboard?file=upload
'
)
// success
else
res
.
redirect
(
'
/dashboard?file=notupload
'
)
// unsuccess
}).
catch
(
err
=>
{
throw
new
Error
(
err
)
})
}
})
module
.
exports
=
router
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment