Several modifications made to the API and several bug fixes
This commit is contained in:
@@ -20,7 +20,7 @@ steps:
|
||||
repo: swiftlogiclabs/cdn-app-insider
|
||||
tags:
|
||||
- latest
|
||||
- v1.0.0-beta.12
|
||||
- v1.0.0-beta.13
|
||||
dockerfile: Dockerfile
|
||||
username:
|
||||
from_secret: docker_username
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM node:20
|
||||
FROM node:22
|
||||
|
||||
WORKDIR /srv/docker/cdn-app-insider
|
||||
|
||||
|
||||
@@ -4,12 +4,11 @@ const swaggerUi = require('swagger-ui-express');
|
||||
const swaggerOptions = {
|
||||
swaggerDefinition: {
|
||||
info: {
|
||||
title: 'API - ManageMate',
|
||||
version: '1.0-beta.1',
|
||||
description: 'This documentation describes the ManageMate API.',
|
||||
title: 'API - CDN-APP',
|
||||
version: '1.0.0-beta.13',
|
||||
description: 'This documentation describes the CDN-APP API.',
|
||||
},
|
||||
servers: [{ url: 'http://localhost:' + (process.env.PORT || 35665) }],
|
||||
basePath: '/api/v1/',
|
||||
basePath: '/api/dpanel/',
|
||||
},
|
||||
apis: ['./routes/Dpanel/Api/*.js'],
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cdn-app/insider-swiftlogic-labs-dinawo",
|
||||
"version": "1.0.0-beta.12",
|
||||
"version": "1.0.0-beta.13",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -117,6 +117,7 @@
|
||||
background-color: #5b5b82;
|
||||
}
|
||||
|
||||
|
||||
body.dark-theme .navbar-toggler-icon {
|
||||
filter: invert(1);
|
||||
}
|
||||
@@ -168,3 +169,32 @@ body.dark-theme .navbar-toggler-icon {
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.custom-dropdown,
|
||||
.animated-button {
|
||||
position: relative;
|
||||
background: #1d2429;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 10px 20px;
|
||||
font-size: 1em;
|
||||
color: #17a2b8;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
body.white-theme .custom-dropdown,
|
||||
body.white-theme .animated-button {
|
||||
color: #6c757d;
|
||||
background: #e9ecef;
|
||||
}
|
||||
|
||||
.custom-dropdown:hover,
|
||||
.animated-button:hover {
|
||||
background: #343a40;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
body.white-theme .custom-dropdown:hover,
|
||||
body.white-theme .animated-button:hover {
|
||||
background: #343a40;
|
||||
color: #fff;
|
||||
}
|
||||
@@ -14,10 +14,10 @@ const limiter = rateLimit({
|
||||
router.post('/', limiter, (req, res, next) => {
|
||||
passport.authenticate('ActiveDirectory', (err, user) => {
|
||||
if (err) {
|
||||
return res.render('AuthLogin', { isAuthenticated: false, errorMessage: err.message, setupData: {}, showActiveDirectoryForm: true, currentUrl: req.originalUrl });
|
||||
return res.json({ isAuthenticated: false, errorMessage: err.message, setupData: {}, showActiveDirectoryForm: true, currentUrl: req.originalUrl });
|
||||
}
|
||||
if (!user) {
|
||||
return res.render('AuthLogin', { isAuthenticated: false, errorMessage: 'L\'utilisateur n\'est pas autorisé.', setupData: {}, showActiveDirectoryForm: true, currentUrl: req.originalUrl });
|
||||
return res.json({ isAuthenticated: false, errorMessage: 'User is not authorized.', setupData: {}, showActiveDirectoryForm: true, currentUrl: req.originalUrl });
|
||||
}
|
||||
req.user = {
|
||||
...user._json,
|
||||
|
||||
@@ -1,16 +1,166 @@
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const router = express.Router();
|
||||
const fileUpload = require('express-fileupload');
|
||||
const authMiddleware = require('../../../Middlewares/authMiddleware');
|
||||
const { loggers } = require('winston');
|
||||
const ncp = require('ncp').ncp;
|
||||
let configFile = fs.readFileSync(path.join(__dirname, '../../../data', 'setup.json'), 'utf-8')
|
||||
let config = JSON.parse(configFile)[0];
|
||||
const bodyParser = require('body-parser');
|
||||
const crypto = require('crypto');
|
||||
const os = require('os');
|
||||
const { getUserData, getSetupData } = require('../../../Middlewares/watcherMiddleware');
|
||||
|
||||
router.post('/', authMiddleware, (req, res) => {
|
||||
const { backgroundUrl } = req.body;
|
||||
let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
if (!backgroundUrl) {
|
||||
return res.status(400).json({ message: 'Background URL missing.' });
|
||||
/**
|
||||
* @swagger
|
||||
* /dashboard/getfilefolder/{folderName}?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - Folder
|
||||
* summary: Get files and folders in a specific folder
|
||||
* description: This route allows you to get the files and folders in a specific folder. It requires a valid JWT token in the Authorization header.
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: folderName
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: The name of the folder
|
||||
* - 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:
|
||||
* files:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* type:
|
||||
* type: string
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* 404:
|
||||
* description: The specified folder does not exist
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Internal server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
if (authHeader) {
|
||||
token = authHeader.split(' ')[1];
|
||||
} else if (req.query.token) {
|
||||
token = req.query.token;
|
||||
}
|
||||
|
||||
if (token == null) {
|
||||
if (req.user) {
|
||||
return next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
}
|
||||
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
const users = JSON.parse(data);
|
||||
|
||||
const user = users.find(u => u.token === token);
|
||||
|
||||
if (user) {
|
||||
req.user = user;
|
||||
req.userData = user;
|
||||
next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
res.cookie('background', backgroundUrl, { httpOnly: true });
|
||||
res.status(200).json({ message: 'Background updated successfully.' });
|
||||
router.get('/wallpaper', authenticateToken, (req, res) => {
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
return res.status(500).send('Error reading the file');
|
||||
}
|
||||
const users = JSON.parse(data);
|
||||
const user = users.find(u => u.token === req.userData.token);
|
||||
|
||||
res.json({ wallpaper: user.wallpaper || null });
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/wallpaper', authenticateToken, (req, res) => {
|
||||
const newWallpaper = req.body.wallpaper;
|
||||
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
return res.status(500).send('Error reading the file');
|
||||
}
|
||||
|
||||
let users = JSON.parse(data);
|
||||
const userIndex = users.findIndex(u => u.token === req.userData.token);
|
||||
|
||||
if (userIndex !== -1) {
|
||||
users[userIndex].wallpaper = newWallpaper;
|
||||
|
||||
fs.writeFile(path.join(__dirname, '../../../data', 'user.json'), JSON.stringify(users, null, 2), (err) => {
|
||||
if (err) {
|
||||
return res.status(500).send('Error writing to the file');
|
||||
}
|
||||
res.send('Wallpaper updated');
|
||||
});
|
||||
} else {
|
||||
res.status(401).send('Unauthorized');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -18,49 +18,129 @@ let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /dashboard/deletefile?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - File
|
||||
* summary: Delete a specific file for a user
|
||||
* description: This route allows you to delete a specific file for a user. 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 delete
|
||||
* 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:
|
||||
* status:
|
||||
* type: string
|
||||
* 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
|
||||
* 404:
|
||||
* description: The specified file does not exist
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* status:
|
||||
* type: string
|
||||
* message:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Internal server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
|
||||
if (authHeader) {
|
||||
token = authHeader.split(' ')[1];
|
||||
token = authHeader.split(' ')[1];
|
||||
} else if (req.query.token) {
|
||||
token = req.query.token;
|
||||
token = req.query.token;
|
||||
}
|
||||
|
||||
if (token == null) {
|
||||
if (req.user) {
|
||||
return next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
return res.status(401).json({ message: 'Unauthorized: No token provided' });
|
||||
}
|
||||
|
||||
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
const users = JSON.parse(data);
|
||||
|
||||
const user = users.find(u => u.token === token);
|
||||
|
||||
if (user) {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
return res.status(500).json({ message: 'Internal server error' });
|
||||
}
|
||||
|
||||
const users = JSON.parse(data);
|
||||
const user = users.find(u => u.token === token);
|
||||
|
||||
if (!user) {
|
||||
return res.status(401).json({ message: 'Unauthorized: Invalid token' });
|
||||
}
|
||||
|
||||
req.user = user;
|
||||
req.userData = user;
|
||||
next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.status(400).json({ error: 'Bad Request. The request cannot be fulfilled due to bad syntax or missing parameters.' });
|
||||
});
|
||||
|
||||
router.post('/', authenticateToken, (req, res) => {
|
||||
if (!req.userData) {
|
||||
return res.status(401).json({ message: 'Authentication failed.' });
|
||||
}
|
||||
|
||||
const userId = req.userData.name;
|
||||
const { filename } = req.body;
|
||||
|
||||
@@ -90,6 +170,7 @@ router.post('/', authenticateToken, (req, res) => {
|
||||
fs.unlinkSync(filePath);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error deleting file:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -107,9 +188,9 @@ router.post('/', authenticateToken, (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const ncpAsync = (source, destination) => {
|
||||
const userFolderPath = path.join('cdn-files', userId);
|
||||
if (!source.startsWith(userFolderPath) || !destination.startsWith(userFolderPath)) {
|
||||
if (!source.startsWith('cdn-files') || !destination.startsWith('cdn-files')) {
|
||||
throw new Error('Unauthorized directory access attempt');
|
||||
}
|
||||
|
||||
|
||||
@@ -18,31 +18,166 @@ let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /dashboard/deletefolder/{folderName}?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - Folder
|
||||
* summary: Delete a specific file in folder for a user
|
||||
* description: This route allows you to delete a specific file for a user. 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 delete
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: folderName
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: The name of the folder
|
||||
* - in: header
|
||||
* name: Authorization
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: The JWT token of your account to have access
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Folder successfully deleted.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* deleted:
|
||||
* type: boolean
|
||||
* success:
|
||||
* 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: You do not have permission to delete this folder.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* 404:
|
||||
* description: The specified folder does not exist.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Error deleting the folder.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
authMiddleware(req, res, function(err) {
|
||||
if (!err) {
|
||||
return next();
|
||||
}
|
||||
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
if (authHeader) {
|
||||
token = authHeader.split(' ')[1];
|
||||
} else if (req.query.token) {
|
||||
token = req.query.token;
|
||||
}
|
||||
|
||||
if (token == null) {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
const users = JSON.parse(data);
|
||||
|
||||
const user = users.find(u => u.token === token);
|
||||
|
||||
if (user) {
|
||||
req.user = user;
|
||||
req.userData = user;
|
||||
next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.status(400).json({ error: 'Bad Request. The request cannot be fulfilled due to bad syntax or missing parameters.' });
|
||||
res.status(400).json({ error: 'Bad Request. The request cannot be fulfilled due to bad syntax or missing parameters.' });
|
||||
});
|
||||
|
||||
router.delete('/:folderName', authMiddleware, (req, res) => {
|
||||
const userId = req.userData.name;
|
||||
const folderName = req.params.folderName;
|
||||
const userFolderPath = path.join('cdn-files', userId);
|
||||
const folderPath = path.join(userFolderPath, folderName);
|
||||
router.delete('/:folderName', authenticateToken, (req, res) => {
|
||||
|
||||
if (!fs.existsSync(folderPath)) {
|
||||
return res.status(404).json({ error: 'Le dossier spécifié n\'existe pas.' });
|
||||
}
|
||||
const userId = req.userData ? req.userData.name : null;
|
||||
if (!userId) {
|
||||
return res.status(401).json({ error: 'Unauthorized' });
|
||||
}
|
||||
const folderName = req.params.folderName;
|
||||
const userFolderPath = path.join('cdn-files', userId);
|
||||
const folderPath = path.join(userFolderPath, folderName);
|
||||
|
||||
if (!folderPath.startsWith(userFolderPath)) {
|
||||
return res.status(403).json({ error: 'Vous n\'avez pas la permission de supprimer ce dossier.' });
|
||||
}
|
||||
if (!fs.existsSync(folderPath)) {
|
||||
return res.status(404).json({ error: 'The specified folder does not exist.' });
|
||||
}
|
||||
|
||||
fs.rmdir(folderPath, { recursive: true }, (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'Erreur lors de la suppression du dossier.' });
|
||||
}
|
||||
res.json({ deleted: true, success: 'Dossier supprimé avec succès.' });
|
||||
});
|
||||
if (!folderPath.startsWith(userFolderPath)) {
|
||||
return res.status(403).json({ error: 'You do not have permission to delete this folder.' });
|
||||
}
|
||||
|
||||
fs.rmdir(folderPath, { recursive: true }, (err) => {
|
||||
if (err) {
|
||||
return res.status(500).json({ error: 'Error deleting the folder.' });
|
||||
}
|
||||
res.json({ deleted: true, success: 'Folder successfully deleted.' });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -18,6 +18,83 @@ let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /dashboard/getfile?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - File
|
||||
* summary: Get file information
|
||||
* description: This route allows you to get information about a specific file. It requires a valid JWT token in the Authorization header.
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* fileLink:
|
||||
* type: string
|
||||
* description: The link of the file to get information about
|
||||
* 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:
|
||||
* Id:
|
||||
* type: string
|
||||
* fileName:
|
||||
* 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
|
||||
* 404:
|
||||
* description: The specified file does not exist or no information found for the file
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Error reading the file
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.status(400).json({ error: 'Bad Request. The request cannot be fulfilled due to bad syntax or missing parameters.' });
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -18,42 +18,112 @@ let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /dashboard/newfolder?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - Folder
|
||||
* summary: Create a new folder
|
||||
* description: This route allows you to create a new folder. It requires a valid JWT token in the Authorization header.
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* folderName:
|
||||
* type: string
|
||||
* description: The name of the new 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:
|
||||
* message:
|
||||
* type: string
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Error creating the folder
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
if (authHeader) {
|
||||
token = authHeader.split(' ')[1];
|
||||
} else if (req.query.token) {
|
||||
token = req.query.token;
|
||||
}
|
||||
|
||||
if (token == null) {
|
||||
if (req.user) {
|
||||
return next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
authMiddleware(req, res, function(err) {
|
||||
if (!err) {
|
||||
return next();
|
||||
}
|
||||
}
|
||||
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
if (authHeader) {
|
||||
token = authHeader.split(' ')[1];
|
||||
} else if (req.query.token) {
|
||||
token = req.query.token;
|
||||
}
|
||||
|
||||
const users = JSON.parse(data);
|
||||
|
||||
const user = users.find(u => u.token === token);
|
||||
|
||||
if (user) {
|
||||
req.user = user;
|
||||
req.userData = user;
|
||||
next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
|
||||
if (token == null) {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
});
|
||||
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
const users = JSON.parse(data);
|
||||
|
||||
const user = users.find(u => u.token === token);
|
||||
|
||||
if (user) {
|
||||
req.user = user;
|
||||
req.userData = user;
|
||||
next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
@@ -62,12 +132,10 @@ router.get('/', (req, res) => {
|
||||
|
||||
router.post('/', authenticateToken, (req, res) => {
|
||||
try {
|
||||
logger.info('Received POST request to create a new folder.');
|
||||
|
||||
const userId = req.userData.name;
|
||||
const userId = req.user.name;
|
||||
let { folderName } = req.body;
|
||||
|
||||
logger.info('Received folderName:', folderName);
|
||||
|
||||
if (!folderName || typeof folderName !== 'string') {
|
||||
ErrorLogger.error('Invalid folderName:', folderName);
|
||||
@@ -83,7 +151,6 @@ router.post('/', authenticateToken, (req, res) => {
|
||||
const folderPath = path.join('cdn-files', userId, folderName);
|
||||
|
||||
if (fs.existsSync(folderPath)) {
|
||||
logger.info('Folder already exists:', folderPath);
|
||||
return res.status(400).json({ message: 'Folder already exists.' });
|
||||
}
|
||||
|
||||
@@ -92,7 +159,6 @@ router.post('/', authenticateToken, (req, res) => {
|
||||
ErrorLogger.error(err);
|
||||
return res.status(500).json({ message: 'Error creating folder.', error: err });
|
||||
}
|
||||
logger.info('Folder created successfully:', folderPath);
|
||||
res.status(200).json({ message: 'Folder created successfully.' });
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -18,45 +18,163 @@ let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /dashboard/rename?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - File
|
||||
* summary: Rename a file
|
||||
* description: This route allows you to rename a file. It requires a valid JWT token in the Authorization header.
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* currentName:
|
||||
* type: string
|
||||
* description: The current name of the file
|
||||
* newName:
|
||||
* type: string
|
||||
* description: The new name for the file
|
||||
* 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:
|
||||
* message:
|
||||
* type: string
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Error renaming the file
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
if (authHeader) {
|
||||
token = authHeader.split(' ')[1];
|
||||
} else if (req.query.token) {
|
||||
token = req.query.token;
|
||||
}
|
||||
|
||||
if (token == null) {
|
||||
if (req.user) {
|
||||
return next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
}
|
||||
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
const users = JSON.parse(data);
|
||||
|
||||
const user = users.find(u => u.token === token);
|
||||
|
||||
if (user) {
|
||||
console.log('User found:', user);
|
||||
req.user = user;
|
||||
req.userData = user;
|
||||
next();
|
||||
} else {
|
||||
console.log('No user found for token:', token);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.status(400).json({ error: 'Bad Request. The request cannot be fulfilled due to bad syntax or missing parameters.' });
|
||||
});
|
||||
|
||||
router.post('/', authMiddleware, async (req, res) => {
|
||||
const userId = req.userData.name;
|
||||
const { currentName, newName } = req.body;
|
||||
const userId = req.userData.name;
|
||||
const { currentName, newName } = req.body;
|
||||
const filePath = path.join(req.params.filePath || '', req.params[0] || '');
|
||||
|
||||
if (!currentName || !newName) {
|
||||
return res.status(400).send('Both currentName and newName must be provided.');
|
||||
}
|
||||
if (!currentName || !newName) {
|
||||
return res.status(400).json('Both currentName and newName must be provided.');
|
||||
}
|
||||
|
||||
const currentPath = path.join('cdn-files', userId || '', currentName);
|
||||
const newPath = path.join('cdn-files', userId, newName);
|
||||
const userDir = path.join('cdn-files', userId);
|
||||
const currentPath = path.join(userDir, filePath, currentName);
|
||||
const newPath = path.join(userDir, filePath, newName);
|
||||
|
||||
try {
|
||||
await fs.promises.rename(currentPath, newPath);
|
||||
if (!currentPath.startsWith(userDir) || !newPath.startsWith(userDir)) {
|
||||
ErrorLogger.error('Unauthorized directory access attempt');
|
||||
return res.status(403).json('Unauthorized directory access attempt');
|
||||
}
|
||||
|
||||
const data = await fs.promises.readFile(path.join(__dirname, '../../../data', 'file_info.json'), 'utf-8')
|
||||
let fileInfo = JSON.parse(data);
|
||||
try {
|
||||
await fs.promises.rename(currentPath, newPath);
|
||||
|
||||
let found = false;
|
||||
for (let i = 0; i < fileInfo.length; i++) {
|
||||
if (fileInfo[i].fileName === currentName) {
|
||||
fileInfo[i].fileName = newName;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const data = await fs.promises.readFile(path.join(__dirname, '../../../data', 'file_info.json'), 'utf8');
|
||||
let fileInfo = JSON.parse(data);
|
||||
|
||||
if (found) {
|
||||
await fs.promises.writeFile(path.join(__dirname, '../../../data', 'file_info.json'), JSON.stringify(fileInfo, null, 2), 'utf8');
|
||||
}
|
||||
let found = false;
|
||||
for (let i = 0; i < fileInfo.length; i++) {
|
||||
if (fileInfo[i].fileName === currentName) {
|
||||
fileInfo[i].fileName = newName;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).send('L\'opération a été effectuée avec succès.');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return res.status(500).send('Erreur lors du changement de nom du fichier.');
|
||||
}
|
||||
if (found) {
|
||||
await fs.promises.writeFile(path.join(__dirname, '../../../data', 'file_info.json'), JSON.stringify(fileInfo, null, 2), 'utf8');
|
||||
}
|
||||
|
||||
res.status(200).json('Operation was successful.');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return res.status(500).json('Error renaming the file.');
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/:filePath*', authMiddleware, async (req, res) => {
|
||||
@@ -65,7 +183,7 @@ router.post('/:filePath*', authMiddleware, async (req, res) => {
|
||||
const filePath = path.join(req.params.filePath, req.params[0] || '');
|
||||
|
||||
if (!currentName || !newName) {
|
||||
return res.status(400).send('Both currentName and newName must be provided.');
|
||||
return res.status(400).json('Both currentName and newName must be provided.');
|
||||
}
|
||||
|
||||
const userDir = path.join('cdn-files', userId);
|
||||
@@ -74,7 +192,7 @@ router.post('/:filePath*', authMiddleware, async (req, res) => {
|
||||
|
||||
if (!currentPath.startsWith(userDir) || !newPath.startsWith(userDir)) {
|
||||
ErrorLogger.error('Unauthorized directory access attempt');
|
||||
return res.status(403).send('Unauthorized directory access attempt');
|
||||
return res.status(403).json('Unauthorized directory access attempt');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -96,10 +214,10 @@ router.post('/:filePath*', authMiddleware, async (req, res) => {
|
||||
await fs.promises.writeFile(path.join(__dirname, '../../../data', 'file_info.json'), JSON.stringify(fileInfo, null, 2), 'utf8');
|
||||
}
|
||||
|
||||
res.status(200).send('L\'opération a été effectuée avec succès.');
|
||||
res.status(200).json('Operation was successful.');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return res.status(500).send('Erreur lors du changement de nom du fichier.');
|
||||
return res.status(500).json('Error renaming the file.');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -18,6 +18,82 @@ let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /dpanel/upload?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - File
|
||||
* summary: Upload a file
|
||||
* description: This route allows you to upload a file. It requires a valid JWT token in the Authorization header.
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* multipart/form-data:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* file:
|
||||
* type: string
|
||||
* format: binary
|
||||
* description: The file to upload
|
||||
* expiryDate:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: The expiry date of the file
|
||||
* password:
|
||||
* type: string
|
||||
* description: The password to protect the file
|
||||
* 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:
|
||||
* message:
|
||||
* type: string
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Error uploading the file
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
@@ -17,6 +17,85 @@ let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /dashboard/getfile?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - File
|
||||
* summary: Get files and folders in a specific folder
|
||||
* description: This route allows you to delete a specific file for a user. 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 delete
|
||||
* 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:
|
||||
* status:
|
||||
* type: string
|
||||
* 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
|
||||
* 404:
|
||||
* description: The specified file does not exist
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* status:
|
||||
* type: string
|
||||
* message:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Internal server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
158
routes/Dpanel/API/getFileFolder.js
Normal file
158
routes/Dpanel/API/getFileFolder.js
Normal file
@@ -0,0 +1,158 @@
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const router = express.Router();
|
||||
const fileUpload = require('express-fileupload');
|
||||
const authMiddleware = require('../../../Middlewares/authMiddleware');
|
||||
const { loggers } = require('winston');
|
||||
const ncp = require('ncp').ncp;
|
||||
let configFile = fs.readFileSync(path.join(__dirname, '../../../data', 'setup.json'), 'utf-8')
|
||||
let config = JSON.parse(configFile)[0];
|
||||
const bodyParser = require('body-parser');
|
||||
const crypto = require('crypto');
|
||||
const os = require('os');
|
||||
const { getUserData, getSetupData } = require('../../../Middlewares/watcherMiddleware');
|
||||
|
||||
let setupData = getSetupData();
|
||||
let userData = getUserData();
|
||||
router.use(bodyParser.json());
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /dashboard/getfilefolder/{folderName}?token={token}:
|
||||
* post:
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* tags:
|
||||
* - Folder
|
||||
* summary: Get files and folders in a specific folder
|
||||
* description: This route allows you to get the files and folders in a specific folder. It requires a valid JWT token in the Authorization header.
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: folderName
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: The name of the folder
|
||||
* - 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:
|
||||
* files:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* type:
|
||||
* type: string
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* 404:
|
||||
* description: The specified folder does not exist
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* 500:
|
||||
* description: Internal server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
*/
|
||||
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
if (authHeader) {
|
||||
token = authHeader.split(' ')[1];
|
||||
} else if (req.query.token) {
|
||||
token = req.query.token;
|
||||
}
|
||||
|
||||
if (token == null) {
|
||||
if (req.user) {
|
||||
return next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
}
|
||||
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
const users = JSON.parse(data);
|
||||
|
||||
const user = users.find(u => u.token === token);
|
||||
|
||||
if (user) {
|
||||
req.user = user;
|
||||
req.userData = user;
|
||||
next();
|
||||
} else {
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
router.post('/:folderName', authenticateToken, async (req, res) => {
|
||||
const userName = req.userData.name;
|
||||
const folderName = req.params.folderName;
|
||||
const downloadDir = path.join('cdn-files', userName, folderName);
|
||||
|
||||
if (!fs.existsSync(downloadDir)) {
|
||||
return res.status(404).json({ error: 'The specified folder does not exist.' });
|
||||
}
|
||||
|
||||
try {
|
||||
const files = await fs.promises.readdir(downloadDir);
|
||||
|
||||
const fileDetails = files.map(file => {
|
||||
const filePath = path.join(downloadDir, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
const fileType = stats.isDirectory() ? 'folder' : 'file';
|
||||
|
||||
return {
|
||||
name: file,
|
||||
type: fileType
|
||||
};
|
||||
});
|
||||
|
||||
res.json({ files: fileDetails });
|
||||
} catch (err) {
|
||||
console.error('Error reading directory:', err);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -19,6 +19,7 @@ router.use(bodyParser.json());
|
||||
|
||||
router.get('/:folderName', authMiddleware, async (req, res) => {
|
||||
const userId = req.userData.name;
|
||||
const userName = req.userData.name;
|
||||
const folderName = req.params.folderName || '';
|
||||
const folderPath = path.join('cdn-files', userId, folderName);
|
||||
const userFolderPath = path.join('cdn-files', userId);
|
||||
@@ -114,7 +115,7 @@ router.get('/:folderName', authMiddleware, async (req, res) => {
|
||||
.then(fileDetails => {
|
||||
const availableExtensions = Array.from(new Set(fileDetails.map(file => file.extension)));
|
||||
|
||||
res.render('folder', { files: fileDetails, folders, allFolders, extensions: availableExtensions, currentFolder: currentFolderName, folderName: folderName, fileInfoNames });
|
||||
res.render('folder', { files: fileDetails, folders, allFolders, extensions: availableExtensions, currentFolder: currentFolderName, folderName: folderName, fileInfoNames, userName });
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error processing file details:', error);
|
||||
|
||||
@@ -12,7 +12,8 @@ const AttachmentsRoute = require('./attachments.js');
|
||||
const buildMetadataRoute = require('./BuildMetaData.js');
|
||||
const DpanelBackgroundCustomRoute = require('./Dpanel/API/BackgroundCustom.js');
|
||||
const getFileDashboardRoute = require('./Dpanel/API/getFile.js');
|
||||
|
||||
const getFileFolderRoute = require('./Dpanel/API/getFileFolder.js');
|
||||
const swagger = require('../models/swagger.js');
|
||||
const NewFolderRoute = require('./Dpanel/API/NewFolder.js');
|
||||
const RenameFileRoute = require('./Dpanel/API/RenameFile.js');
|
||||
const DeleteFileRoute = require('./Dpanel/API/DeleteFile.js');
|
||||
@@ -39,6 +40,7 @@ const GenerateTokenRoute = require('./Dpanel/API/GenerateToken.js');
|
||||
router.use('/', indexRoute);
|
||||
router.use('/attachments', AttachmentsRoute);
|
||||
router.use('/build-metadata', buildMetadataRoute);
|
||||
router.use('/api/docs', swagger.serve, swagger.setup);
|
||||
|
||||
router.use('/dpanel/dashboard', DpanelDashboardRoute);
|
||||
router.use('/dpanel/upload', DpanelUploadRoute);
|
||||
@@ -61,7 +63,8 @@ router.use('/api/dpanel/dashboard/deletefile/', discordWebhookSuspisiousAlertMid
|
||||
router.use('/api/dpanel/dashboard/getmetadatafile',discordWebhookSuspisiousAlertMiddleware, logApiRequest, GetMetaDataFileRoute);
|
||||
router.use('/api/dpanel/dashboard/backgroundcustom',discordWebhookSuspisiousAlertMiddleware, logApiRequest, DpanelBackgroundCustomRoute);
|
||||
router.use('/api/dpanel/generate-token',discordWebhookSuspisiousAlertMiddleware, logApiRequest, GenerateTokenRoute);
|
||||
router.use('/api/dpanel/dashboard/getfile', getFileDashboardRoute);
|
||||
router.use('/api/dpanel/dashboard/getfile', getFileDashboardRoute, logApiRequest);
|
||||
router.use('/api/dpanel/dashboard/getfilefolder', getFileFolderRoute, logApiRequest);
|
||||
|
||||
router.use('/auth/login', loginRoute);
|
||||
router.use('/auth/logout', logoutRoute);
|
||||
|
||||
@@ -35,20 +35,20 @@
|
||||
<ul class="navbar-nav ml-auto">
|
||||
<li class="nav-item">
|
||||
<form action="/dpanel/upload" class="form-inline">
|
||||
<button class="btn btn-primary btn-round mr-2">
|
||||
<button class="btn btn-primary btn-round mr-2 animated-button">
|
||||
<i class="fas fa-cloud-upload-alt"></i> Téléverser un fichier
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<form id="newFolderModalForm" class="form-inline ml-2">
|
||||
<button type="submit" class="btn btn-success btn-round ml-2" id="newFolderModalBtn" data-toggle="modal" data-target="#newFolderModal">
|
||||
<button type="submit" class="btn btn-success btn-round ml-2 animated-button" id="newFolderModalBtn" data-toggle="modal" data-target="#newFolderModal">
|
||||
<i class="fas fa-folder-open"></i> Nouveau Dossier
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button id="styleSwitcher" class="btn btn-link btn-round">
|
||||
<button id="styleSwitcher" class="btn btn-link btn-round animated-button">
|
||||
<i id="themeIcon"></i>
|
||||
</button>
|
||||
</li>
|
||||
@@ -117,41 +117,41 @@
|
||||
<% if (file.type === 'folder') { %>
|
||||
<form class="file-actions mb-2">
|
||||
<input type="hidden" name="folderName" value="<%= file.name %>">
|
||||
<button class="delete-folder-button btn btn-danger btn-round" type="button">
|
||||
<button class="delete-folder-button btn btn-danger btn-round animated-button" type="button">
|
||||
<i class="fas fa-trash-alt"></i>
|
||||
</button>
|
||||
</form>
|
||||
<a href="/dpanel/dashboard/folder/<%= file.name %>" class="btn btn-primary btn-round mb-2">
|
||||
<a href="/dpanel/dashboard/folder/<%= file.name %>" class="btn btn-primary btn-round mb-2 animated-button">
|
||||
<i class="fas fa-folder-open"></i> Accéder
|
||||
</a>
|
||||
<% } else { %>
|
||||
<button class="btn btn-primary btn-round" onclick="renameFile('<%= folderName %>', '<%= file.name %>')">
|
||||
<button class="btn btn-primary btn-round animated-button animated-button" onclick="renameFile('<%= folderName %>', '<%= file.name %>')">
|
||||
<i class="fas fa-edit"></i> Renommer
|
||||
</button>
|
||||
<form class="file-actions mb-2" id="deleteForm" action="/api/dpanel/dashboard/delete" method="post">
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="filename" value="<%= file.name %>">
|
||||
<button class="delete-button btn btn-danger btn-round" type="button" onclick="confirmDelete('<%= file.name %>')">
|
||||
<button class="delete-button btn btn-danger btn-round animated-button" type="button" onclick="confirmDelete('<%= file.name %>')">
|
||||
<i class="fas fa-trash-alt"></i>
|
||||
</button>
|
||||
</form>
|
||||
<form class="file-actions mb-2">
|
||||
<div class="copy-link-container d-flex align-items-center">
|
||||
<input type="text" class="file-link form-control rounded mr-2" value="<%= file.url %>" readonly style="display: none;">
|
||||
<button class="button copy-button btn btn-success btn-round" data-file="<%= file.name %>">
|
||||
<button class="button copy-button btn btn-success btn-round animated-button" data-file="<%= file.name %>">
|
||||
<i class="fas fa-copy"></i>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<form class="file-actions d-flex align-items-center mb-2" action="/api/dpanel/dashboard/movefile" method="post">
|
||||
<input type="hidden" name="fileName" value="<%= file.name %>">
|
||||
<select class="form-control rounded mr-2" name="folderName">
|
||||
<select class="form-control rounded mr-2 custom-dropdown" name="folderName">
|
||||
<option value="" disabled selected>Déplacer vers...</option>
|
||||
<% allFolders.forEach(folder => { %>
|
||||
<option value="<%= folder %>"><%= folder %></option>
|
||||
<% }); %>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-success btn-round">Déplacer</button>
|
||||
<button type="submit" class="btn btn-success btn-round animated-button">Déplacer</button>
|
||||
</form>
|
||||
|
||||
<% } %>
|
||||
@@ -167,7 +167,7 @@
|
||||
<div class="modal-dialog modal-lg rounded-lg" role="document">
|
||||
<div class="modal-content dark-mode">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="patchNoteModalLabel">Patch Note<span class="badge badge-info ml-1">v1.0.0-beta.12</span></h5>
|
||||
<h5 class="modal-title" id="patchNoteModalLabel">Patch Note<span class="badge badge-info ml-1">v1.0.0-beta.13</span></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
@@ -177,15 +177,14 @@
|
||||
<p><i class="fas fa-tools"></i> Améliorations :</p>
|
||||
<ul>
|
||||
<li>Améliorations mineures et corrections mineures.<span class="badge badge-success ml-1">AMÉLIORATION MINEURE</span></li>
|
||||
<li>Optimisation de la lecture des vidéos<span class="badge badge-success ml-1">AMÉLIORATION MAJEUR</span></li>
|
||||
<li>Correction de l'affichage des meta-données qui sont passées sur le nouveau système (géré par l'API)<span class="badge badge-success ml-1">AMÉLIORATION MINEURE</span></li>
|
||||
<li>Déplacement de fichier d'un dossier à la racine<span class="badge badge-success ml-1">AMÉLIORATION MAJEUR</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="patch-note-item pl-3">
|
||||
<p><i class="fas fa-wrench"></i> Ajout :</p>
|
||||
<ul>
|
||||
<li>Ajout des endpoints d'api externe à l'application<span class="badge badge-success ml-1">AJOUT EXPERIENCE MAJEUR</span></li>
|
||||
<li>Ajout des endpoints d'api manquant externe à l'application<span class="badge badge-success ml-1">AJOUT EXPERIENCE MAJEUR</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -231,7 +230,7 @@
|
||||
<ul class="nav justify-content-center border-bottom pb-3 mb-3">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link px-2 text-muted" href="#" data-toggle="modal" data-target="#patchNoteModal">
|
||||
Version: 1.0.0-beta.12
|
||||
Version: 1.0.0-beta.13
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -31,18 +31,18 @@
|
||||
<div class="collapse navbar-collapse ml-auto" id="navbarNav">
|
||||
<ul class="navbar-nav ml-auto">
|
||||
<li class="nav-item">
|
||||
<button class="btn btn-warning btn-round mr-2" onclick="window.location.href='/dpanel/dashboard';">
|
||||
<button class="btn btn-warning btn-round mr-2 animated-button" onclick="window.location.href='/dpanel/dashboard';">
|
||||
<i class="fas fa-home"></i>Page principal</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<form action="/dpanel/upload" class="form-inline">
|
||||
<button class="btn btn-primary btn-round mr-2">
|
||||
<button class="btn btn-primary btn-round mr-2 animated-button">
|
||||
<i class="fas fa-cloud-upload-alt"></i> Téléverser un fichier
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button id="styleSwitcher" class="btn btn-link btn-round">
|
||||
<button id="styleSwitcher" class="btn btn-link btn-round animated-button">
|
||||
<span id="themeIcon" class="fas theme-icon"></span>
|
||||
</button>
|
||||
</li>
|
||||
@@ -119,37 +119,38 @@
|
||||
<td class="d-flex justify-content-end align-items-center">
|
||||
<% if (file.type === 'folder') { %>
|
||||
<a href="/dpanel/dashboard/folder/<%= file.name %>" class="btn btn-primary btn-round mb-2">
|
||||
<i class="fas fa-folder-open fa-xs btn-icon"></i> Accéder
|
||||
<i class="fas fa-folder-open fa-xs btn-icon animated-button "></i> Accéder
|
||||
</a>
|
||||
<% } else { %>
|
||||
<button class="btn btn-primary btn-round" onclick="renameFile('<%= folderName %>', '<%= file.name %>')">
|
||||
<button class="btn btn-primary btn-round animated-button" onclick="renameFile('<%= folderName %>', '<%= file.name %>')">
|
||||
<i class="fas fa-edit fa-xs btn-icon"></i> Renommer
|
||||
</button>
|
||||
<form class="file-actions mb-2" id="deleteForm" action="/api/dpanel/dashboard/delete" method="post">
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="filename" value="<%= file.name %>">
|
||||
<button class="delete-button btn btn-danger btn-round" type="button" onclick="confirmDeleteFile('<%= currentFolder %>', '<%= file.name %>')">
|
||||
<button class="delete-button btn btn-danger btn-round animated-button" type="button" onclick="confirmDeleteFile('<%= currentFolder %>', '<%= file.name %>')">
|
||||
<i class="fas fa-trash-alt fa-xs btn-icon"></i>
|
||||
</button>
|
||||
</form>
|
||||
<form class="file-actions mb-2">
|
||||
<div class="copy-link-container d-flex align-items-center">
|
||||
<input type="text" class="file-link form-control rounded mr-2" value="<%= file.url %>" readonly style="display: none;">
|
||||
<button class="button copy-button btn btn-success btn-round" data-file="<%= file.name %>">
|
||||
<button class="button copy-button btn btn-success btn-round animated-button" data-file="<%= file.name %>">
|
||||
<i class="fas fa-copy fa-xs btn-icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<form class="file-actions d-flex align-items-center mb-2" action="/api/dpanel/dashboard/movefile/<%= folderName %>" method="post">
|
||||
<form class="file-actions d-flex align-items-center mb-2" action="/api/dpanel/dashboard/movefile/<%= folderName %>" method="post">
|
||||
<input type="hidden" name="fileName" value="<%= file.name %>">
|
||||
<select class="form-control rounded mr-2" name="folderName">
|
||||
<input type="hidden" name="userName" value="<%= userName %>">
|
||||
<select class="form-control rounded mr-2 custom-dropdown" name="folderName">
|
||||
<option value="" disabled selected>Déplacer vers...</option>
|
||||
<% allFolders.forEach(folder => { %>
|
||||
<option value="<%= folder %>"><%= folder %></option>
|
||||
<% }); %>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-success btn-round">Déplacer</button>
|
||||
</form>
|
||||
<button type="submit" class="btn btn-success btn-round animated-button">Déplacer</button>
|
||||
</form>
|
||||
<% } %>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -171,7 +172,7 @@
|
||||
<div class="container">
|
||||
<footer class="py-3 my-4">
|
||||
<ul class="nav justify-content-center border-bottom pb-3 mb-3">
|
||||
<li class="nav-item"><a class="nav-link px-2 text-muted">Version: 1.0.0-beta.10</a></li>
|
||||
<li class="nav-item"><a class="nav-link px-2 text-muted">Version: 1.0.0-beta.13</a></li>
|
||||
</ul>
|
||||
<p class="text-center text-muted">© 2024 SwiftLogic Labs</p>
|
||||
</footer>
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<td><%= user.name %></td>
|
||||
<td><%= user.role %></td>
|
||||
<td>
|
||||
<form action="/api/dpanel/dashboard/admin/update-role" method="POST" class="d-flex align-items-center">
|
||||
<form id="update-role-form" action="/api/dpanel/dashboard/admin/update-role" method="POST" class="d-flex align-items-center">
|
||||
<input type="hidden" name="id" value="<%= user.id %>">
|
||||
<input type="hidden" name="name" value="<%= user.name %>">
|
||||
<select class="form-control rounded mr-2" name="role">
|
||||
@@ -91,7 +91,7 @@
|
||||
</select>
|
||||
<button type="submit" class="btn btn-primary btn-round custom-btn">Mettre à jour</button>
|
||||
</form>
|
||||
<form action="/api/dpanel/generate-token" method="POST" class="d-flex align-items-center mt-2">
|
||||
<form id="generate-token-form" action="/api/dpanel/generate-token" method="POST" class="d-flex align-items-center mt-2">
|
||||
<input type="hidden" name="id" value="<%= user.id %>">
|
||||
<input type="hidden" name="name" value="<%= user.name %>">
|
||||
<button type="submit" class="btn btn-secondary btn-round custom-btn">Générer Token</button>
|
||||
@@ -193,8 +193,7 @@
|
||||
searchInput.placeholder = isMac ? 'Rechercher par nom ou ID (Cmd + K)' : 'Rechercher par nom ou ID (Ctrl + K)';
|
||||
|
||||
|
||||
document.querySelectorAll('form').forEach(form => {
|
||||
form.addEventListener('submit', function(e) {
|
||||
document.getElementById('generate-token-form').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
var url = this.getAttribute('action');
|
||||
var method = this.getAttribute('method');
|
||||
@@ -231,7 +230,6 @@
|
||||
Swal.fire('Error', error.message, 'error');
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user