Several modifications made to the API and several bug fixes
This commit is contained in:
@@ -20,6 +20,84 @@ let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /dashboard/movefile?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - File
|
||||
* summary: Move file to a different folder
|
||||
* description: This route allows you to move a file to a different folder. It requires a valid JWT token in the Authorization header.
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* fileName:
|
||||
* type: string
|
||||
* description: The name of the file to be moved
|
||||
* folderName:
|
||||
* type: string
|
||||
* description: The name of the destination folder
|
||||
* parameters:
|
||||
* - in: header
|
||||
* name: Authorization
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: The JWT token of your account to have access
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Success
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* 400:
|
||||
* description: Bad Request
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* 403:
|
||||
* description: Unauthorized directory access attempt
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Error moving the file
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
@@ -120,16 +198,25 @@ router.post('/', authenticateToken, async (req, res) => {
|
||||
|
||||
router.post('/:folderName', authenticateToken, async (req, res) => {
|
||||
const fileName = req.body.fileName;
|
||||
const newFolderName = req.body.folderName;
|
||||
let newFolderName = req.body.newFolderName;
|
||||
const oldFolderName = req.params.folderName;
|
||||
const userId = req.user && req.user._json ? req.userData.name : undefined;
|
||||
const userName = req.body.userName;
|
||||
|
||||
console.log('fileName:', fileName);
|
||||
console.log('newFolderName:', newFolderName);
|
||||
console.log('oldFolderName:', oldFolderName);
|
||||
console.log('userName:', userName);
|
||||
|
||||
if (!fileName || !userId || !oldFolderName || !newFolderName) {
|
||||
console.error('fileName, userId, oldFolderName, or newFolderName is undefined');
|
||||
if (newFolderName === 'root') {
|
||||
newFolderName = '';
|
||||
}
|
||||
|
||||
if (fileName === undefined || userName === undefined || oldFolderName === undefined || newFolderName === undefined) {
|
||||
console.error('fileName, userName, oldFolderName, or newFolderName is undefined');
|
||||
return res.status(500).send('Error moving the file.');
|
||||
}
|
||||
|
||||
const userDir = path.join(process.cwd(), 'cdn-files', userId);
|
||||
const userDir = path.join(process.cwd(), 'cdn-files', userName);
|
||||
const sourcePath = path.join(userDir, oldFolderName, fileName);
|
||||
const destinationDir = path.join(userDir, newFolderName);
|
||||
const destinationPath = path.join(destinationDir, fileName);
|
||||
|
||||
Reference in New Issue
Block a user