Commit 8fb026f5 authored by Kim, MinGyu's avatar Kim, MinGyu
Browse files

Avatar -> fileInfo

parent 0be923a8
......@@ -2,15 +2,7 @@ import React from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import "tailwindcss/tailwind.css";
import { IntoPost } from "./post/intopost";
import {
Login,
Profile,
RequireAuth,
Signup,
Admin,
ImgRewrite,
Search,
} from "./auth";
import { Login, Profile, RequireAuth, Signup, Admin, ImgRewrite } from "./auth";
import { Header, Body } from "./home";
import { Board } from "./board";
import Posting from "./post/posting";
......@@ -37,7 +29,6 @@ export const App = () => {
<Route path="board" element={<Board />} />
<Route path="post/:postId" element={<IntoPost />} />
<Route path="edit" element={<EditPost />} />
{/* </Route> */}
<Route
path="profile"
element={
......@@ -48,7 +39,6 @@ export const App = () => {
/>
<Route path="admin" element={<Admin />} />
<Route path="rewrite" element={<ImgRewrite />} />
<Route path="search" element={<Search />} />
</Route>
</Route>
</Routes>
......
......@@ -7,9 +7,7 @@ export const RequireAuth: FC<{ children: JSX.Element }> = ({ children }) => {
const location = useLocation();
if (!user.isLoggedIn) {
return (
<Navigate to={"/login"} state={{ from: location.pathname }} replace />
);
return <Navigate to={"/"} state={{ from: location.pathname }} replace />;
}
return children;
};
import React, { FormEvent, useEffect, useState, MouseEvent } from "react";
import { Link } from "react-router-dom";
import { mainimgApi } from "../apis";
import { picture } from "../apis/profile.api";
import { profileUpload } from "../apis/profile.api";
import { catchErrors } from "../helpers";
import { MainimgType } from "../types";
import { MySlide } from "./adminslide";
......
......@@ -4,4 +4,3 @@ export { default as Profile } from "./profile";
export { RequireAuth } from "./RequireAuth";
export { default as Admin } from "./admin";
export { default as ImgRewrite } from "./imgrewrite";
export { default as Search } from "./search";
import React from "react";
import { useLocation } from "react-router-dom";
export default function Search() {
const a = useLocation().state;
return (
<div>
<div></div>
</div>
);
}
......@@ -31,7 +31,7 @@ export interface SignupUser {
export interface Profile {
_id: string;
email: string;
avatar: {
fileInfo: {
originalfilename: string;
newfilename: string;
picturepath: string;
......
......@@ -12,7 +12,6 @@ app.use(cookieParser());
app.use("/api", router);
app.use("/images", express.static(path.join(__dirname, "..", "/uploads")));
app.use("/images", express.static(path.join(__dirname, "..", "/adminpics")));
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
console.log("익스프레스 에러: ", err);
......
import formidable from "formidable";
import { asyncWrap } from "../helpers/asyncWrap";
import { TypedRequest } from "../types";
export const uploadFile = asyncWrap(async (reqExp, res, next) => {
const req = reqExp as TypedRequest;
const form = formidable({ multiples: false, uploadDir: "uploads" });
await new Promise((resolve, reject) => {
form.parse(req, (err, fields, files) => {
if (err) {
reject(err);
return;
}
console.log("fields", fields);
console.log("files", files);
req.body = fields;
req.files = files;
resolve(files);
});
});
next();
return;
});
export const uploadFiles = asyncWrap(async (reqExp, res, next) => {
const req = reqExp as TypedRequest;
const form = formidable({ multiples: true, uploadDir: "uploads" });
await new Promise((resolve, reject) => {
form.parse(req, (err, fields, files) => {
if (err) {
reject(err);
return;
}
console.log("fields", fields);
console.log("files", files);
req.body = fields;
req.files = files;
resolve(files);
});
});
next();
return;
});
......@@ -3,3 +3,4 @@ export * as postCtrl from "./post.controller";
export * as roleCtrl from "./role.controller";
export * as userCtrl from "./user.controller";
export * as mainimgCtrl from "./mainimg.controller";
export * as fileInfoCtrl from "./fileinfo.controller";
......@@ -12,7 +12,7 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
const { userId } = req.auth;
const form = formidable({
uploadDir: "adminpics",
uploadDir: "uploads",
keepExtensions: true,
multiples: false,
});
......
import { ObjectId } from "mongoose";
import { Avatar, IAvatar, Mainimg, MainimgType } from "../models";
import { FileInfo, IFileInfo, Mainimg, MainimgType } from "../models";
export const createMainimg = async (mainimg: MainimgType, pic: IAvatar) => {
const newPic = await Avatar.create({
export const createMainimg = async (mainimg: MainimgType, pic: IFileInfo) => {
const newPic = await FileInfo.create({
originalfilename: pic.originalfilename,
newfilename: pic.newfilename,
pictureauth: pic.picturepath,
......
import { model, Schema } from "mongoose";
export interface IAvatar {
export interface IFileInfo {
originalfilename?: string;
newfilename?: string;
picturepath?: string;
nickname?: string;
}
const Avatarschema = new Schema<IAvatar>({
const schema = new Schema<IFileInfo>({
originalfilename: { type: String, unique: true },
newfilename: { type: String },
nickname: { type: String },
picturepath: { type: String },
});
export default model<IAvatar>("Avatar", Avatarschema);
export default model<IFileInfo>("FileInfo", schema);
export { default as User, IUser } from "./user.model";
export { default as Post, PostType } from "./post.model";
export { default as Role } from "./role.model";
export { default as Avatar, IAvatar } from "./fileinfo.model";
export { default as FileInfo, IFileInfo } from "./fileinfo.model";
export { default as Mainimg, MainimgType } from "./mainimg.model";
......@@ -4,7 +4,7 @@ export interface MainimgType {
theme: string;
city: string;
title: string;
pic?: Types.ObjectId;
fileInfo?: Types.ObjectId;
}
const MainimgSchema = new Schema<MainimgType>({
......@@ -18,7 +18,7 @@ const MainimgSchema = new Schema<MainimgType>({
type: String,
required: true,
},
pic: { type: Schema.Types.ObjectId, ref: "Avatar" },
fileInfo: { type: Schema.Types.ObjectId, ref: "Fileinfo" },
});
export default model<MainimgType>("Mainimg", MainimgSchema);
......@@ -5,7 +5,7 @@ export interface IUser {
name?: string;
password: string;
role?: Types.ObjectId;
avatar?: Types.ObjectId;
fileInfo?: Types.ObjectId;
}
const validateEmail = (email: string) => {
......@@ -22,7 +22,7 @@ const schema = new Schema<IUser>(
validate: [validateEmail, "이메일을 입력해주세요"],
},
name: { type: String },
avatar: { type: Schema.Types.ObjectId, ref: "Avatar" },
fileInfo: { type: Schema.Types.ObjectId, ref: "FileInfo" },
password: { type: String, required: true, select: false },
role: { type: Schema.Types.ObjectId, ref: "Role" },
},
......
import express from "express";
import { userCtrl, authCtrl } from "../controllers";
import { userCtrl, authCtrl, fileInfoCtrl } from "../controllers";
const router = express.Router();
router
.route("/")
.get(authCtrl.requireLogin, userCtrl.getUsers)
.post(authCtrl.requireLogin, authCtrl.hasRole("admin"), userCtrl.createUser);
.post(
authCtrl.requireLogin,
authCtrl.hasRole("admin"),
fileInfoCtrl.uploadFile,
userCtrl.createUser
);
export default router;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment