yuanjiajun commited on
Commit
fc2888c
·
1 Parent(s): ca63dd4

feat: 文件服务

Browse files
Files changed (2) hide show
  1. src/app.ts +1 -2
  2. src/controllers/fileController.ts +0 -4
src/app.ts CHANGED
@@ -39,8 +39,7 @@ app.use(mount('/uploads', staticMiddleware(path.join(__dirname, '../../uploads')
39
  app.use(fileRoutes.routes());
40
  app.use(fileRoutes.allowedMethods());
41
 
42
- // const PORT = process.env.PORT || 3000;
43
- const PORT = process.env.PORT || 3001;
44
 
45
  app.listen(PORT, () => {
46
  console.log(`Server is running on port ${PORT}`);
 
39
  app.use(fileRoutes.routes());
40
  app.use(fileRoutes.allowedMethods());
41
 
42
+ const PORT = process.env.PORT || 3000;
 
43
 
44
  app.listen(PORT, () => {
45
  console.log(`Server is running on port ${PORT}`);
src/controllers/fileController.ts CHANGED
@@ -39,7 +39,6 @@ export const uploadFile = async (ctx: Context) => {
39
  const fileName = fileNameMatch[1];
40
  const targetPath = path.join(UPLOAD_DIR, fileName);
41
 
42
- console.log( fileBuffer);
43
  fs.writeFileSync(targetPath, fileBuffer);
44
  ctx.body = { message: 'File uploaded successfully' };
45
  } catch (error: any) {
@@ -69,7 +68,6 @@ export const getFile = async (ctx: Context) => {
69
 
70
  export const deleteFile = async (ctx: Context) => {
71
  try {
72
- console.log('1231321');
73
  const { fileName } = ctx.request.body;
74
 
75
  if (!fileName) {
@@ -79,8 +77,6 @@ export const deleteFile = async (ctx: Context) => {
79
  }
80
 
81
  const filePath = path.join(UPLOAD_DIR, fileName);
82
- console.log('filePathdsadsadsa');
83
- console.log(filePath);
84
  if (!fs.existsSync(filePath)) {
85
  ctx.status = 404;
86
  ctx.body = { error: 'File not found' };
 
39
  const fileName = fileNameMatch[1];
40
  const targetPath = path.join(UPLOAD_DIR, fileName);
41
 
 
42
  fs.writeFileSync(targetPath, fileBuffer);
43
  ctx.body = { message: 'File uploaded successfully' };
44
  } catch (error: any) {
 
68
 
69
  export const deleteFile = async (ctx: Context) => {
70
  try {
 
71
  const { fileName } = ctx.request.body;
72
 
73
  if (!fileName) {
 
77
  }
78
 
79
  const filePath = path.join(UPLOAD_DIR, fileName);
 
 
80
  if (!fs.existsSync(filePath)) {
81
  ctx.status = 404;
82
  ctx.body = { error: 'File not found' };