Skip to content

Commit

Permalink
Merge pull request #161 from boostcamp-2020/dev
Browse files Browse the repository at this point in the history
v0.0.4 배포
  • Loading branch information
rockpell committed Dec 14, 2020
2 parents 9f507b4 + 7b23c90 commit 2aa3fce
Show file tree
Hide file tree
Showing 40 changed files with 1,192 additions and 145 deletions.
53 changes: 45 additions & 8 deletions backend/chatServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,73 @@ import express from 'express'
import { createServer } from 'http'
import createChatServer from 'socket.io'
import { createChatMessage } from './service/chat'
import { addReaction, removeReaction } from './service/reaction'
dotenv()

const server = createServer(express())
const io = createChatServer(server, {
cors: { origin: process.env.FRONTEND_HOST, credentials: true },
})

const namespace = io.of('chat')
const namespace = io.of(/^\/chat\/\w+$/)
namespace.use((socket, next) => {
// TODO jwt 검증 로직 필요
next()
})

namespace.on('connection', socket => {
const { workspaceUserInfoId } = socket.handshake.query
socket.join(workspaceUserInfoId)
socket.on('invite channel', ({ channelId, origin, newMember }) => {
origin
.concat(newMember)
.forEach(member =>
namespace.in(member).emit('invited channel', { channelId, newMember }),
)
})
socket.on('new message', async data => {
// TODO 특정 채널로 전송하도록 변경, db에 저장 필요 (현재는 자신 제외 전체 전송)
const { channelId, creator } = socket.handshake.query
const { contents } = data
const { contents, channelId } = data
const { data: result } = await createChatMessage({
creator,
creator: workspaceUserInfoId,
channelId,
contents,
})
namespace.in(channelId).emit('new message', {
message: { ...data, _id: result._id, createdAt: result.createdAt },
})
})
socket.on('join-room', roomId => {
socket.join(roomId)
console.log('joined', roomId)
socket.on('update reaction', async data => {
const { emoji, chatId, userInfo, channelId, type } = data
//1 = add, 0 = remove
const result =
type === 1
? await addReaction({
workspaceUserInfoId,
chatId,
emoticon: emoji,
})
: await removeReaction({
workspaceUserInfoId,
chatId,
emoticon: emoji,
})

namespace.in(channelId).emit('update reaction', {
reaction: {
chatId: chatId,
emoji: emoji,
workspaceUserInfoId: userInfo._id,
displayName: userInfo.displayName,
type: result ? type : false,
},
})
})

socket.on('join-room', (channelList = []) => {
socket.join(channelList)
})
socket.on('leave-room', roomId => {
socket.leave(roomId)
})
})

Expand Down
4 changes: 3 additions & 1 deletion backend/config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ async function gitStrategyLogin(profiles) {
const data = await User.create({
OAuthId: profiles.id,
fullName: profiles.username,
profileUrl: profiles.photos[0].value,
profileUrl:
profiles?.photos[0]?.value ||
'https://user-images.githubusercontent.com/56837413/102013276-583f6000-3d92-11eb-8184-186bc09f2a98.jpg',
isDeleted: false,
})
return {
Expand Down
15 changes: 15 additions & 0 deletions backend/config/s3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import AWS from 'aws-sdk'
require('dotenv').config()

const S3 = new AWS.S3({
endpoint: process.env.S3_ENDPOINT,
region: process.env.S3_REGION,
credentials: {
accessKeyId: process.env.S3_ACCESSKEY,
secretAccessKey: process.env.S3_SECRETKEY,
},
})

const BUCKETNAME = process.env.S3_BUCKETNAME

module.exports = { S3, BUCKETNAME }
24 changes: 24 additions & 0 deletions backend/controller/file/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { asyncWrapper } from '../../util'
import service from '../../service/file'

exports.getFileURL = asyncWrapper(async (req, res) => {
const { code, success, data } = await service.getFileURL({
...req.query,
})
return res.status(code).json({ success, data })
})

exports.uploadFile = asyncWrapper(async (req, res) => {
const { code, success, data } = await service.uploadFile({
file: req.file,
userId: req.user.id,
})
return res.status(code).json({ success, data })
})

exports.deleteFile = asyncWrapper(async (req, res) => {
const { code, success } = await service.deleteFile({
...req.query,
})
return res.status(code).json({ success })
})
14 changes: 14 additions & 0 deletions backend/controller/file/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import express from 'express'
const { Auth } = require('../../middleware/auth')
const router = express.Router()
const controller = require('./file')

const multer = require('multer')
const storage = multer.memoryStorage()
const uploader = multer({ storage: storage })

router.get('/', Auth, controller.getFileURL)
router.post('/', Auth, uploader.single('file'), controller.uploadFile)
router.delete('/', Auth, controller.deleteFile)

module.exports = router
3 changes: 2 additions & 1 deletion backend/controller/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import express from 'express'

import channelCotroller from './channel'
import searchCotroller from './search'
import userController from './user'
import workspaceController from './workspace'
import chatController from './chat'
import fileController from './file'
const router = express.Router()

router.use('/channel', channelCotroller)
router.use('/search', searchCotroller)
router.use('/user', userController)
router.use('/workspace', workspaceController)
router.use('/chat', chatController)
router.use('/file', fileController)

module.exports = router
155 changes: 155 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,161 @@ paths:
default:
description: Default error sample response

'/api/file/{fileId}':
summary: get chat messages
description: get chat messages
get:
tags:
- file
operationId: ''
parameters:
- name: fileId
in: path
description: fileId
required: true
explode: true
schema:
type: string
responses:
'200':
content:
application/json:
schema:
type: object
properties:
success:
type: string
data:
type: object
properties:
url:
type: string
originalName:
type: string

description: success response
'400':
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
description: not modified
'401':
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
description: unauthorized
default:
description: Default error sample response
delete:
tags:
- file
operationId: ''
parameters:
- name: fileId
in: path
description: fileId
required: true
explode: true
schema:
type: string
responses:
'200':
content:
application/json:
schema:
type: object
properties:
success:
type: boolean

description: success response
'400':
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
description: not modified
'401':
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
description: unauthorized
default:
description: Default error sample response
'/api/file':
summary: file upload
description: file upload
post:
tags:
- file
operationId: ''
parameters:
- name: file
in: query
description: file
required: true
explode: true
schema:
type: string
responses:
'200':
content:
application/json:
schema:
type: object
properties:
success:
type: string
data:
type: object
properties:
fileId:
type: string
fileName:
type: string
fileType:
type: string
creator:
type: string
etag:
type: string
description: success response
'400':
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
description: not modified
'401':
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
description: unauthorized
default:
description: Default error sample response

components:
schemas:
workspaceUserInfo:
Expand Down
3 changes: 3 additions & 0 deletions backend/model/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const fileSchema = mongoose.Schema(
name: {
type: String,
},
originalName: {
type: String,
},
creator: {
type: Schema.Types.ObjectId,
ref: 'User',
Expand Down
Loading

0 comments on commit 2aa3fce

Please sign in to comment.