Skip to content

Commit

Permalink
Merge pull request #147 from sparcs-kaist/develop
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
withSang authored May 10, 2024
2 parents d6f31cf + 61ed131 commit a50fc06
Show file tree
Hide file tree
Showing 39 changed files with 2,338 additions and 1,581 deletions.
2 changes: 1 addition & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine
FROM node:18.18.2-alpine


RUN apk add --no-cache git
Expand Down
4 changes: 2 additions & 2 deletions .docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.19.1
FROM node:18.18.2

RUN apt update

Expand All @@ -10,4 +10,4 @@ EXPOSE 6001

VOLUME [ "/app" ]

CMD ["yarn", "dev"]
CMD ["yarn", "dev"]
16 changes: 16 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ services:
- DB_STR=zabo
volumes:
- zabo-scheduler-log:/backup_log:rw

# zabo-worker:
# container_name: zabo-worker
# restart: always
# build:
# context: ..
# dockerfile: .worker/Dockerfile
# environment:
# - NODE_ENV=${NODE_ENV:-production}
# - MINIMUM_LOG_LEVEL=info
# - MONGODB_URL=mongodb://zabo-mongo:27017/zabo
# - DB_STR=zabo
# volumes:
# - zabo-worker-log:/backup_log:rw

volumes:
zabo-server-log:
Expand All @@ -61,3 +75,5 @@ volumes:
external: true
zabo-scheduler-log:
external: true
# zabo-worker-log:
# external: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

.uuid
# dependencies
/node_modules

Expand All @@ -11,6 +12,7 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
zabo-server-deployment/base/**/secret.yaml

*.log

Expand Down
14 changes: 14 additions & 0 deletions .worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:16-alpine


RUN apk add --no-cache git

WORKDIR '/app'

COPY ./package.json ./
COPY ./yarn.lock ./
RUN yarn

COPY . .

CMD ["node", "worker.js"]
25 changes: 25 additions & 0 deletions migrations/1714912017538-add_showBoard_field.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require ('@babel/register');
require ('../config/env');

const {Zabo} = require('../src/db');

/**
* Make any changes you need to make to the database here
*/
async function up () {
// Write migration here
// eslint-disable-next-line no-restricted-syntax
for await (const zabo of Zabo.find()) {
zabo.showBoard = false;
await zabo.save ();
}
}

/**
* Make any changes that UNDO the up function side effects here (if possible)
*/
async function down () {
// Write migration here
}

module.exports = { up, down };
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/register": "^7.21.0",
"@tiptap/pm": "^2.3.1",
"adminjs": "^6.8.7",
"aws-sdk": "^2.485.0",
"axios": ">=0.18.1",
"bcrypt": "^5.1.1",
"chalk": "^2.4.2",
"connect-redis": "^3.4.1",
"cors": "^2.8.5",
Expand All @@ -56,7 +58,7 @@
"http-errors": "~1.6.2",
"ioredis": "^4.14.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.19",
"lodash": "^4.17.21",
"migrate-mongoose": "^4.0.0",
"moment": "^2.24.0",
"mongoose": "^5.7.5",
Expand Down Expand Up @@ -84,7 +86,7 @@
"figlet": "^1.2.4",
"husky": "^4.0.6",
"inquirer": "^7.0.3",
"lint-staged": "^9.5.0",
"lint-staged": "^15.1.0",
"nodemon": "^1.18.11",
"prettier": "^1.17.0"
},
Expand Down
42 changes: 42 additions & 0 deletions routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
* [`POST`](routes.md) /zabo/:zaboId/share
* [`DELETE`](routes.md) /zabo/:zaboId/

### Board
* [`POST`](routes.md) /board/device
* [`DELETE`](routes.md) /board/device
* [`POST`](routes.md) /board/login
* [`POST`](routes.md) /board/logout
* [`GET`](routes.md) /board/list


## Authentication

Following **Authorization** field must be set in HTTP request header
Expand Down Expand Up @@ -361,6 +369,40 @@ TODO: 그룹의 정보 \(사진\)을 업데이트할 수 있습니다. 이름도

400 : null id 500

### Board
#### `POST` /board/device { name, description, password } => deviceInfo
자보 보드를 게시할 디바이스를 생성합니다. Admin 패널에서 생성할 수 있습니다.
Admin 권한이 필요합니다. 기존의 디바이스들과 이름이 겹치면 생성되지 않습니다.

유효성 확인
* 관리자이여야 합니다.
* 기존의 디바이스와 겹치지 않는 디바이스 이름이여야 합니다.

#### `DELETE` /board/device { name } => { message }
자보 보드를 게시하는 디바이스를 삭제합니다. Admin 패널에서 삭제할 수 있습니다.

유효성 확인
* 관리자이여야 합니다.
* 유효한 디바이스 이름이여야 합니다.

#### `POST` /board/login { name, password } => { success, message }
자보 보드 디바이스에 로그인합니다. 세션 쿠키를 사용하여 인증합니다.

유효성 확인
* 올바른 디바이스 이름 및 비밀번호인지 확인합니다.

#### `POST` /board/logout => { message }
자보 보드 디바이스에서 로그아웃합니다.

유효성 확인
* 디바이스로 로그인되어있어야 합니다.

#### `GET` /board/list => zaboList
디바이스에서 자보 보드용 자보를 받아옵니다. 디바이스 로깅을 위해 /zabo/list와 분리해서 사용해야 합니다.

유효성 확인
* 디바이스로 로그인되어있어야 합니다.

## English

#### `GET` /auth \(\)`user`
Expand Down
6 changes: 6 additions & 0 deletions src/admin/actions/addDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Components } from "../components";

export const addDeviceAction = {
actionType: "resource",
component: Components.addDeviceComponent,
};
20 changes: 20 additions & 0 deletions src/admin/actions/deleteDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import axios from "axios";
export const deleteDeviceAction = {
actionType: "record",
component: false,
guard: "Do you really want to delete this device?",
handler: async (req, res, context) => {
const { record } = context;
const deviceName = record.params.name;
const response = await axios.delete("/api/board/device", {
name: deviceName,
});

response.data.message;

return {
record: {},
msg: "Deleting Device: Success",
};
},
};
51 changes: 51 additions & 0 deletions src/admin/components/addDevice.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, {useState} from 'react'
import { H3, Input, Button } from '@adminjs/design-system';
import axios from 'axios';

const addDevice = async (name, description, password) => {
const response = await axios.post('/api/board/device',
{
name,
description,
password
}
);
}

const addDeviceComponent = (props) => {
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [password, setPassword] = useState("");

const handleNameChange = (e) => {
setName(e.target.value);
}

const handleDescriptionChange = (e) => {
setDescription(e.target.value);
}

const handlePasswordChange = (e) => {
setPassword(e.target.value);
}

const handleDeviceSubmit = async() => {
await addDevice(name, description, password);
}

return (
<div>
<H3> Create your zabo boards device</H3>
<br/>
<Input type="text" onChange={handleNameChange} placeholder="name" />
<br/>
<Input type="text" onChange={handleDescriptionChange} placeholder="description" />
<br/>
<Input type="password" onChange={handlePasswordChange} placeholder="password" />
<br/>
<Button size="icon" rounded="True" onClick={handleDeviceSubmit}>Submit</Button>
</div>
)
}

export default addDeviceComponent
1 change: 1 addition & 0 deletions src/admin/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Components = {
"uploadZaboComponent",
"./uploadZabo",
),
addDeviceComponent: componentLoader.add("addDeviceComponent", "./addDevice"),
};

export { componentLoader, Components };
5 changes: 3 additions & 2 deletions src/admin/components/uploadZabo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const uploadZaboComponent = (props) => {
const [description, setDescription] = useState("");
const [category, setCategory] = useState("");
const [schedule, setSchedule] = useState({});
const [showBoard, setShowBoard] = useState(false);

const handleZaboChange = (e) => {
const files = Array.from(e.target.files);
Expand Down Expand Up @@ -119,6 +120,7 @@ const uploadZaboComponent = (props) => {
zaboJSON.append("title", title);
zaboJSON.append("description", description);
zaboJSON.append("category", category);
zaboJSON.append("showBoard", showBoard);
//TODO: handle if schedule exists
// formData.append("schedule", schedule);

Expand All @@ -128,7 +130,7 @@ const uploadZaboComponent = (props) => {
await sortedImageFiles.sort(gridLayoutCompareFunction);

const {width, height} = await imageFileGetWidthHeight(sortedImageFiles[0]);
const ratio = width / height;
let ratio = width / height;
if (ratio > 2) ratio = 2;
else if (ratio < 0.5) ratio = 0.5;
const sources = await Promise.all(sortedImageFiles.map((file) => cropImage(file, ratio)));
Expand All @@ -144,7 +146,6 @@ const uploadZaboComponent = (props) => {
},
});

return
}

return (
Expand Down
4 changes: 4 additions & 0 deletions src/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
Statistic,
PreRegister,
Meta,
DeviceLog,
} from "../db";

import { GroupResource } from "./resources/Group";
import { ZaboResource } from "./resources/Zabo";
import { AdminUserResource } from "./resources/AdminUser";
import { DeviceResource } from "./resources/Device";

AdminJS.registerAdapter({
Resource: AdminJSMongoose.Resource,
Expand All @@ -34,7 +36,9 @@ const adminOptions = {
Statistic,
PreRegister,
Meta,
DeviceResource,
ZaboResource,
DeviceLog,
],
componentLoader,
};
Expand Down
11 changes: 11 additions & 0 deletions src/admin/resources/Device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Device } from "../../db/index";
import { addDeviceAction } from "../actions/addDevice";

export const DeviceResource = {
resource: Device,
options: {
actions: {
addDevice: addDeviceAction,
},
},
};
3 changes: 2 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ app.use(
app.use(
cors({
origin: [/sparcs\.org$/, /kaist\.ac\.kr$/],
credentials: true,
}),
);

Expand Down Expand Up @@ -67,7 +68,7 @@ app.use((err, req, res, next) => {
logger.api.error(err?.message || err); // TODO: Log params and body?
res.status(err.status || 500);
res.json({
error: err,
error: err, // 이거 뭐임? 왜 넣었지 ㅋㅋ 이거 없애도 되는거 아님? ㅋㅋ 이거 없애면 에러 안나는데 ㅋㅋ 이거 왜 넣었지 ㅋㅋ
});
});

Expand Down
4 changes: 3 additions & 1 deletion src/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const checkAdmin = ash(async (req, res, next) => {
export const postNewZabo = ash(async (req, res) => {
const self = req.adminUser.user;

const { title, description, schedules: jsonSchedules } = req.body;
const { title, description, schedules: jsonSchedules, showBoard } = req.body;
const schedules = parseJSON(jsonSchedules, []);
let { category } = req.body;
logger.zabo.info(
Expand All @@ -111,6 +111,7 @@ export const postNewZabo = ash(async (req, res) => {
description,
category,
schedules,
showBoard,
req.files,
);
category = (category || "")
Expand Down Expand Up @@ -142,6 +143,7 @@ export const postNewZabo = ash(async (req, res) => {
description,
category,
schedules,
showBoard,
});

const calSizes = [];
Expand Down
Loading

0 comments on commit a50fc06

Please sign in to comment.