120 lines
2.9 KiB
JavaScript
120 lines
2.9 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const uploadController = require('../controllers/uploadController');
|
|
|
|
/**
|
|
* @swagger
|
|
* tags:
|
|
* name: Upload
|
|
* description: File upload management
|
|
*/
|
|
|
|
/**
|
|
* @swagger
|
|
* /api/upload/single:
|
|
* post:
|
|
* summary: Upload single file
|
|
* tags: [Upload]
|
|
* requestBody:
|
|
* required: true
|
|
* content:
|
|
* multipart/form-data:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* file:
|
|
* type: string
|
|
* format: binary
|
|
* description: File to upload (images → public/images, audio/video → public/media, others → public/files)
|
|
* responses:
|
|
* 201:
|
|
* description: File uploaded successfully
|
|
* 400:
|
|
* description: No file uploaded or upload error
|
|
* 500:
|
|
* description: Server error
|
|
*/
|
|
router.post('/single', (req, res, next) => {
|
|
uploadController.uploadSingle(req, res, next);
|
|
});
|
|
|
|
/**
|
|
* @swagger
|
|
* /api/upload/multiple:
|
|
* post:
|
|
* summary: Upload multiple files (max 10)
|
|
* tags: [Upload]
|
|
* requestBody:
|
|
* required: true
|
|
* content:
|
|
* multipart/form-data:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* files:
|
|
* type: array
|
|
* items:
|
|
* type: string
|
|
* format: binary
|
|
* description: Files to upload (max 10 files)
|
|
* responses:
|
|
* 201:
|
|
* description: Files uploaded successfully
|
|
* 400:
|
|
* description: No files uploaded or upload error
|
|
* 500:
|
|
* description: Server error
|
|
*/
|
|
router.post('/multiple', (req, res, next) => {
|
|
uploadController.uploadMultiple(req, res, next);
|
|
});
|
|
|
|
/**
|
|
* @swagger
|
|
* /api/upload/file:
|
|
* delete:
|
|
* summary: Delete uploaded file
|
|
* tags: [Upload]
|
|
* requestBody:
|
|
* required: true
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* required:
|
|
* - filepath
|
|
* properties:
|
|
* filepath:
|
|
* type: string
|
|
* example: "public/images/example-1234567890.jpg"
|
|
* responses:
|
|
* 200:
|
|
* description: File deleted successfully
|
|
* 404:
|
|
* description: File not found
|
|
*/
|
|
router.delete('/file', uploadController.deleteFile);
|
|
|
|
/**
|
|
* @swagger
|
|
* /api/upload/info:
|
|
* get:
|
|
* summary: Get file information
|
|
* tags: [Upload]
|
|
* parameters:
|
|
* - in: query
|
|
* name: filepath
|
|
* required: true
|
|
* schema:
|
|
* type: string
|
|
* description: Path to the file
|
|
* responses:
|
|
* 200:
|
|
* description: File info retrieved successfully
|
|
* 404:
|
|
* description: File not found
|
|
*/
|
|
router.get('/info', uploadController.getFileInfo);
|
|
|
|
module.exports = router;
|