Commit 29d3c719 authored by 백승민's avatar 백승민
Browse files

only css left

parent fbaae34c
...@@ -48,7 +48,7 @@ export function MySlide({ slides}: num) { ...@@ -48,7 +48,7 @@ export function MySlide({ slides}: num) {
{slides.slice(page - 1, page + 2).map((slide) => ( {slides.slice(page - 1, page + 2).map((slide) => (
<div key={Math.random()} className="min-w-full" <div key={Math.random()} className="min-w-full"
> >
<div key={slide} className={`inline-grid grid-cols-2 ${style}`}> <div key={slide} className={`inline-grid grid-cols-2 ${style} min-w-full`}>
{slide} {slide}
</div> </div>
</div> </div>
......
...@@ -35,11 +35,9 @@ export default function Login() { ...@@ -35,11 +35,9 @@ export default function Login() {
setLoading(true); setLoading(true);
await login(user.email, user.password, () => { await login(user.email, user.password, () => {
if (user.email == "admin@korea.ac.kr" && user.password == "111111") {
navigate("/admin", { replace: true }); navigate("/", { replace: true });
} else {
navigate("/", { replace: true });
}
}); });
// console.log("서버연결됬나요", res); // console.log("서버연결됬나요", res);
// console.log("로그인"); // console.log("로그인");
......
...@@ -65,16 +65,16 @@ export default function Body() { ...@@ -65,16 +65,16 @@ export default function Body() {
Idpics.slice(i * limit, i * limit + limit).map( Idpics.slice(i * limit, i * limit + limit).map(
(picture, index: number) => ( (picture, index: number) => (
<div <div
className={`m-1 shrink-0 rounded shadow-md h-45 relative overflow-hidden`} className={`m-1 shrink-0 rounded shadow-md h-50 relative overflow-hidden`}
key={index} key={index}
> >
<img <img
src={ src={
"http://localhost:3000/images/" + picture.fileInfo.newfilename "http://localhost:3000/images/" + picture.fileInfo.newfilename
} }
className="w-full h-40 object-cover hover:scale-110 transition duration-0 hover:duration-500" className="w-full h-48 object-cover hover:scale-110 transition duration-0 hover:duration-500"
/> />
<div className="bg-transparent text-neutral-50 text-xs rounded-full absolute bottom-0 ml-1 mb-1 hover:scale-110 transition duration-0 hover:duration-500"> <div className="bg-transparent text-neutral-50 text-xs md:text-lg rounded-full absolute bottom-0 ml-1 mb-1 hover:scale-110 transition duration-0 hover:duration-500">
<span>{picture.title}</span> <span>{picture.title}</span>
</div> </div>
</div> </div>
......
...@@ -24,10 +24,10 @@ export default function Header() { ...@@ -24,10 +24,10 @@ export default function Header() {
</button> </button>
<div className="flex h-12"> <div className="flex h-12">
<input <input
className="ml-10 focus:outline-none focus:border-y-4 focus:border-l-4 focus:border-sky-500 w-20 w-40 md:w-4/5 border-y-4 border-l-4 border-sky-300 pl-9 rounded-l-full focus:border-0" className="ml-10 focus:outline-none focus:border-y-4 focus:border-l-4 focus:border-sky-500 w-3/5 md:w-4/5 border-y-4 border-l-4 border-sky-300 pl-9 rounded-l-full focus:border-0"
onChange={handleChange} onChange={handleChange}
/> />
<button className="shrink-0 bg-white border-y-4 border-r-4 border-sky-500 rounded-r-full pr-4"> <button className="whitespace-nowrap bg-white border-y-4 border-r-4 border-sky-500 rounded-r-full pr-4">
검색 검색
</button> </button>
</div> </div>
......
...@@ -39,7 +39,8 @@ export interface SignupUser { ...@@ -39,7 +39,8 @@ export interface SignupUser {
export interface Profile { export interface Profile {
_id: string; _id: string;
email: string; email: string;
fileInfo: { name: string;
avatar: {
originalfilename: string; originalfilename: string;
newfilename: string; newfilename: string;
picturepath: string; picturepath: string;
......
...@@ -4,7 +4,7 @@ import { TypedRequest } from "../types"; ...@@ -4,7 +4,7 @@ import { TypedRequest } from "../types";
export const uploadFile = asyncWrap(async (reqExp, res, next) => { export const uploadFile = asyncWrap(async (reqExp, res, next) => {
const req = reqExp as TypedRequest; const req = reqExp as TypedRequest;
const form = formidable({ multiples: false, uploadDir: "uploads" }); const form = formidable({ multiples: false, uploadDir: "uploads",keepExtensions : true });
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
form.parse(req, (err, fields, files) => { form.parse(req, (err, fields, files) => {
......
import { NextFunction, Request, Response } from "express"; import { NextFunction, Request, Response } from "express";
import isLength from "validator/lib/isLength"; import isLength from "validator/lib/isLength";
import { TypedRequestAuth } from "./auth.controller";
import { asyncWrap } from "../helpers"; import { asyncWrap } from "../helpers";
import { mainimgDb } from "../db"; import { mainimgDb } from "../db";
import { TypedRequest } from "../types"; import { TypedRequest } from "../types";
import { ObjectId } from "mongoose"; import { ObjectId } from "mongoose";
import formidable from "formidable"; import formidable from "formidable";
import { TypedRequestAuth } from "./auth.controller";
export const createMainimg = asyncWrap(async (reqExp, res) => { export const createMainimg = asyncWrap(async (reqExp, res) => {
const req = reqExp as TypedRequestAuth<{ userId: ObjectId }>; const req = reqExp as TypedRequestAuth<{ userId: ObjectId }>;
...@@ -65,49 +65,58 @@ export const deleteMainimg = asyncWrap(async (req, res) => { ...@@ -65,49 +65,58 @@ export const deleteMainimg = asyncWrap(async (req, res) => {
}); });
export const updateMainimg = asyncWrap(async (reqExp, res) => { export const updateMainimg = asyncWrap(async (reqExp, res) => {
const req = reqExp as TypedRequestAuth<{ userId: ObjectId }>; const req = reqExp as TypedRequest;
const form = formidable({ // const { id } = reqExp.params;
uploadDir: "uploads", const { id, theme, city, title } = req.body;
keepExtensions: true, const { updatemainimg }: { updatemainimg: formidable.File } = req.files;
multiples: false, console.log("전부 제대로", id,theme, city, title, updatemainimg)
}); const img = await mainimgDb.updateOneMainimg(id, theme,city,title, updatemainimg);
form.parse(req, (err, fields, files) => { res.json(img);
if (!Array.isArray(files.updatemainimg)) { })
//파일 좁히기 중 // const form = formidable({
if ( // uploadDir: "uploads",
!( // keepExtensions: true,
Array.isArray(fields.id) || // multiples: false,
Array.isArray(fields.city) || // });
Array.isArray(fields.title) ||
Array.isArray(fields.theme) // form.parse(req, (err, fields, files) => {
) // if (!Array.isArray(files.updatemainimg)) {
) { // //파일 좁히기 중
const id = fields.id; // if (
const city = fields.city; // !(
const title = fields.title; // Array.isArray(fields.id) ||
const theme = fields.theme; // Array.isArray(fields.city) ||
console.log("error"); // Array.isArray(fields.title) ||
if (!(files.updatemainimg === undefined)) { // Array.isArray(fields.theme)
const originalfilename = files.updatemainimg?.originalFilename; // )
const newfilename = files.updatemainimg.newFilename; // ) {
if (!(originalfilename === null || newfilename === undefined)) { // const id = fields.id;
const imgRes = mainimgDb.updateOneMainimg( // const city = fields.city;
id, // const title = fields.title;
theme, // const theme = fields.theme;
city, // console.log("error");
title, // if (!(files.updatemainimg === undefined)) {
originalfilename, // const originalfilename = files.updatemainimg?.originalFilename;
newfilename // const newfilename = files.updatemainimg.newFilename;
); // if (!(originalfilename === null || newfilename === undefined)) {
return res.json(imgRes); // const imgRes = mainimgDb.updateOneMainimg(
} // id,
} else { // theme,
const imgRes = mainimgDb.updateOneMainimg(id, theme, city, title); // city,
return res.json(imgRes); // title,
} // // fileInfo
} // originalfilename,
} // newfilename
}); // );
}); // return res.json(imgRes);
// }
// } else {
// const imgRes = mainimgDb.updateOneMainimg(id, theme, city, title);
// return res.json(imgRes);
// }
// }
// }
// });
// });
import { ObjectId } from "mongoose"; import { HydratedDocument, ObjectId } from "mongoose";
import { FileInfo, IFileInfo, Mainimg, MainimgType } from "../models"; import { FileInfo, IFileInfo, Mainimg, MainimgType } from "../models";
import fs from "fs/promises"; import fs from "fs/promises";
import { fileInfoCtrl } from "../controllers"; import { fileInfoCtrl } from "../controllers";
import formidable from "formidable";
export const createMainimg = async (mainimg: MainimgType, pic: IFileInfo) => { export const createMainimg = async (mainimg: MainimgType, pic: IFileInfo) => {
const newPic = await FileInfo.create({ const newPic = await FileInfo.create({
originalfilename: pic.originalfilename, originalfilename: pic.originalfilename,
newfilename: pic.newfilename, newfilename: pic.newfilename,
pictureauth: pic.picturepath, picturepath: pic.picturepath,
}); });
const newMainimg = await Mainimg.create({ const newMainimg = await Mainimg.create({
...@@ -43,41 +44,76 @@ export const updateOneMainimg = async ( ...@@ -43,41 +44,76 @@ export const updateOneMainimg = async (
theme: string, theme: string,
city: string, city: string,
title: string, title: string,
originalfilename?: string | null, fileInfo: formidable.File
newfilename?: string // originalfilename?: string | null,
// newfilename?: string
) => { ) => {
const newMainimg = await Mainimg.findById(_Id); // const newMainimg = await Mainimg.findById(_Id)
console.log("error2", _Id); const newMainimg = await Mainimg.findById(_Id).populate<{ fileInfo: IFileInfo }>(
if (!(newMainimg?.fileInfo === undefined)) { "fileInfo"
if (originalfilename === undefined) { );
await Mainimg.findByIdAndUpdate(newMainimg._id, {
theme: theme, console.log("error2", newMainimg);
city: city, if (!newMainimg) {
title: title, throw new Error("mainimg가 존재하지 않습니다")
}); }
console.log("errrror4"); if (
} else if ( fileInfo.originalFilename &&
!(originalfilename === undefined) && newMainimg?.fileInfo.originalfilename !== fileInfo.originalFilename
(!(theme === undefined) || ) {
!(city === undefined) || // 같지 않으면 기존의 파일을 디스크에서 삭제한 후
!(title === undefined)) try {
) { console.log("picturepath", newMainimg.fileInfo.picturepath)
await Mainimg.findByIdAndUpdate(newMainimg._id, { await fs.unlink(newMainimg.fileInfo.picturepath);
theme: theme, } catch (error) {
city: city, console.log("error", error);
title: title,
});
await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
originalfilename: originalfilename,
newfilename: newfilename,
});
console.log("error6");
} else {
await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
originalfilename: originalfilename,
newfilename: newfilename,
});
console.log("error5", newfilename, originalfilename, theme, city, title);
} }
} else console.log("error3", newMainimg); const mainimgAvatar = newMainimg.fileInfo as HydratedDocument<IFileInfo>;
}; // 기존 fileinfo의 파일이름과 경로 변경 설정
mainimgAvatar.originalfilename = fileInfo.originalFilename;
mainimgAvatar.newfilename = fileInfo.newFilename;
mainimgAvatar.picturepath = fileInfo.filepath;
await mainimgAvatar.save();
}
newMainimg.theme = theme;
newMainimg.city = city;
newMainimg.title = title;
await newMainimg.save();
console.log("mainimg updated", newMainimg);
return newMainimg;
}
// if (!(newMainimg?.fileInfo === undefined)) {
// if (originalfilename === undefined) {
// await Mainimg.findByIdAndUpdate(newMainimg._id, {
// theme: theme,
// city: city,
// title: title,
// });
// console.log("errrror4");
// } else if (
// !(originalfilename === undefined) &&
// (!(theme === undefined) ||
// !(city === undefined) ||
// !(title === undefined))
// ) {
// await Mainimg.findByIdAndUpdate(newMainimg._id, {
// theme: theme,
// city: city,
// title: title,
// });
// await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
// originalfilename: originalfilename,
// newfilename: newfilename,
// });
// console.log("error6");
// } else {
// await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
// originalfilename: originalfilename,
// newfilename: newfilename,
// });
// console.log("error5", newfilename, originalfilename, theme, city, title);
// }
// } else console.log("error3", newMainimg);
// };
\ No newline at end of file
import express from "express"; import express from "express";
import { mainimgCtrl, authCtrl } from "../controllers"; import { mainimgCtrl, authCtrl, fileInfoCtrl } from "../controllers";
const router = express.Router(); const router = express.Router();
...@@ -11,7 +11,7 @@ router ...@@ -11,7 +11,7 @@ router
router router
.route("/:imgId") .route("/:imgId")
.delete(authCtrl.requireLogin,authCtrl.hasRole("admin"), mainimgCtrl.deleteMainimg) .delete(authCtrl.requireLogin,authCtrl.hasRole("admin"), mainimgCtrl.deleteMainimg)
.put(authCtrl.requireLogin,authCtrl.hasRole("admin"), mainimgCtrl.updateMainimg); .put(authCtrl.requireLogin,authCtrl.hasRole("admin"),fileInfoCtrl.uploadFile, mainimgCtrl.updateMainimg);
export default router; 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