Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021_dev-profile
/
dev-profile
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Lee SeJin
2021-06-08 02:37:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7f9c1b322a5281f28cf08b7e2deab05881ca68ae
7f9c1b32
1 parent
29bf5981
Deploy version 1.0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
4 deletions
src/controllers/userController.js
src/middlewares.js
src/views/editProfile.pug
src/views/userDetail.pug
src/controllers/userController.js
View file @
7f9c1b3
...
...
@@ -63,11 +63,12 @@ export const postEditProfile = async (req, res) => {
body
:
{
name
,
email
,
school
,
blogUrl
,
tech
,
career
,
introduction
},
file
,
}
=
req
;
const
isHeroku
=
process
.
env
.
NODE_ENV
===
"production"
;
try
{
const
updatedUser
=
await
User
.
findByIdAndUpdate
(
id
,
{
avatarUrl
:
file
?
file
.
location
:
req
.
session
.
passport
.
user
.
avatarUrl
,
avatarUrl
:
file
?
(
isHeroku
?
file
.
location
:
file
.
path
)
:
req
.
session
.
passport
.
user
.
avatarUrl
,
name
,
email
,
school
,
...
...
src/middlewares.js
View file @
7f9c1b3
...
...
@@ -9,6 +9,8 @@ const s3 = new aws.S3({
}
});
const
isHeroku
=
process
.
env
.
NODE_ENV
===
"production"
;
const
multerUploader
=
multerS3
({
s3
:
s3
,
bucket
:
"developer-profile-oss"
,
...
...
@@ -18,7 +20,7 @@ const multerUploader = multerS3({
export
const
localsMiddleware
=
(
req
,
res
,
next
)
=>
{
res
.
locals
.
siteName
=
"Dev Profile"
;
res
.
locals
.
loggedUser
=
req
.
user
||
null
;
res
.
locals
.
isHeroku
=
isHeroku
;
next
();
};
...
...
@@ -43,5 +45,5 @@ export const uploadFiles = multer({
limits
:
{
fileSize
:
3000000
},
storage
:
multerUploader
storage
:
isHeroku
?
multerUploader
:
undefined
,
});
\ No newline at end of file
...
...
src/views/editProfile.pug
View file @
7f9c1b3
...
...
@@ -3,7 +3,10 @@ extends layouts/main
block content
.form-container
form(action="/users/edit-profile", method="POST", enctype="multipart/form-data")
img(src=`${loggedUser.avatarUrl}`)
if isHeroku
img(src=`${user.avatarUrl}`)
else
img(src=`/${user.avatarUrl}`)
.fileUpload
input(type="file", id="photo", name="photo", accept="image/*")
label(for="photo") Photo
...
...
src/views/userDetail.pug
View file @
7f9c1b3
...
...
@@ -9,7 +9,10 @@ block content
.pageLayout
.user-profile
.user-profile__column
if isHeroku
img(src=`${user.avatarUrl}`)
else
img(src=`/${user.avatarUrl}`)
.user-profile__link
a(href=user.githubUrl target="_blank") GitHub
i.fab.fa-github
...
...
Please
register
or
login
to post a comment