Refactor Dockerfile and docker-compose.yml to use new directory structure and update volume paths
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
const pgp = require('pg-promise')
|
||||
const pool = require('../config/database');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
async function registerUser(username, password) {
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
const connection = await pool.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.execute('INSERT INTO cdn (username, password) VALUES (?, ?)', [username, hashedPassword]);
|
||||
return rows.insertId;
|
||||
} finally {
|
||||
connection.release();
|
||||
}
|
||||
}
|
||||
|
||||
async function getUserByUsername(username) {
|
||||
const connection = await pool.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.execute('SELECT * FROM cdn WHERE username = ?', [username]);
|
||||
return rows[0];
|
||||
} finally {
|
||||
connection.release();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
registerUser,
|
||||
getUserByUsername,
|
||||
};
|
||||
@@ -1,16 +0,0 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
const pool = require('../config/database');
|
||||
|
||||
async function getUsers() {
|
||||
const connection = await pool.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.execute('SELECT * FROM cdn');
|
||||
return rows || [];
|
||||
} finally {
|
||||
connection.release();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getUsers
|
||||
};
|
||||
@@ -74,7 +74,7 @@ class SystemReport {
|
||||
|
||||
|
||||
try {
|
||||
const response = await fetch('https://apollon.dinawo.fr/api/report/receive', {
|
||||
const response = await fetch('https://cdn-apollon-p198-61m1.dinawo.fr/api/report/receive', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
|
||||
30
models/swagger.js
Normal file
30
models/swagger.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const swaggerJsDoc = require('swagger-jsdoc');
|
||||
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.',
|
||||
},
|
||||
servers: [{ url: 'http://localhost:' + (process.env.PORT || 35665) }],
|
||||
basePath: '/api/v1/',
|
||||
},
|
||||
apis: ['./routes/Dpanel/Api/*.js'],
|
||||
};
|
||||
|
||||
const swaggerDocs = swaggerJsDoc(swaggerOptions);
|
||||
|
||||
const customCss = `
|
||||
.swagger-ui .topbar .link {
|
||||
display: none;
|
||||
}
|
||||
`;
|
||||
|
||||
module.exports = {
|
||||
serve: swaggerUi.serve,
|
||||
setup: swaggerUi.setup(swaggerDocs, {
|
||||
customCss
|
||||
}),
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
|
||||
const AdmZip = require('adm-zip');
|
||||
const { logger, ErrorLogger, logRequestInfo } = require('../config/logs');
|
||||
|
||||
function compareAndUpdate(currentPath, updatedPath) {
|
||||
}
|
||||
|
||||
async function downloadUpdate(updateUrl, destinationPath) {
|
||||
const response = await fetch(updateUrl);
|
||||
const buffer = await response.buffer();
|
||||
fs.writeFileSync(destinationPath, buffer);
|
||||
}
|
||||
|
||||
function unzipUpdate(zipPath, extractionPath) {
|
||||
const zip = new AdmZip(zipPath);
|
||||
zip.extractAllTo(extractionPath, /*overwrite*/ true);
|
||||
}
|
||||
|
||||
module.exports = { compareAndUpdate, downloadUpdate, unzipUpdate };
|
||||
@@ -1,141 +0,0 @@
|
||||
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
|
||||
const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
const AdmZip = require('adm-zip');
|
||||
const util = require('util');
|
||||
const ncp = util.promisify(require('ncp').ncp);
|
||||
const { downloadUpdate, unzipUpdate } = require('../models/updateHelper');
|
||||
const { logger, ErrorLogger } = require('../config/logs');
|
||||
|
||||
async function getFilesInVersion() {
|
||||
try {
|
||||
const response = await fetch('https://apollon.dinawo.fr/api/get/version');
|
||||
const data = await response.json();
|
||||
return data.update.files || [];
|
||||
} catch (error) {
|
||||
throw new Error(`Error getting files in version: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function listFilesInZip(zipFilePath) {
|
||||
try {
|
||||
const zip = new AdmZip(zipFilePath);
|
||||
const zipEntries = zip.getEntries();
|
||||
return zipEntries.map(entry => entry.entryName);
|
||||
} catch (error) {
|
||||
throw new Error(`Error listing files in zip: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteFileOrDirectory(filePath) {
|
||||
try {
|
||||
const stats = await fs.stat(filePath);
|
||||
if (stats.isDirectory()) {
|
||||
logger.info(`Skipped deletion of directory: ${filePath}`);
|
||||
} else {
|
||||
await fs.unlink(filePath);
|
||||
logger.info(`Updated file deleted: ${filePath}`);
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`Error deleting updated file or directory ${filePath}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
ncp.limit = 16;
|
||||
|
||||
async function moveFilesFromTemp(basePath, tempExtractFolder, filesInZip) {
|
||||
const entries = await fs.readdir(tempExtractFolder, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const sourcePath = path.join(tempExtractFolder, entry.name);
|
||||
const targetPath = path.join(basePath, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
await fs.mkdir(targetPath, { recursive: true });
|
||||
await ncp(sourcePath, targetPath);
|
||||
} else {
|
||||
const relativePath = path.relative(tempExtractFolder, sourcePath);
|
||||
|
||||
logger.info(`Processing file: ${relativePath}`);
|
||||
|
||||
if (filesInZip.includes(relativePath)) {
|
||||
const destinationPath = path.join(basePath, relativePath);
|
||||
await fs.mkdir(path.dirname(destinationPath), { recursive: true });
|
||||
|
||||
try {
|
||||
await fs.rename(sourcePath, destinationPath);
|
||||
logger.info(`File moved: ${relativePath}`);
|
||||
} catch (moveError) {
|
||||
logger.error(`Error moving file: ${relativePath}`, moveError);
|
||||
}
|
||||
} else {
|
||||
logger.info(`Skipped moving file: ${relativePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function applyUpdate(updateUrl, updateFolder) {
|
||||
const updateFilePath = path.join(updateFolder, 'update.zip');
|
||||
|
||||
try {
|
||||
await downloadUpdate(updateUrl, updateFilePath);
|
||||
|
||||
const filesInZip = await listFilesInZip(updateFilePath);
|
||||
logger.info('Zip contents:', filesInZip);
|
||||
|
||||
const filesInVersion = await getFilesInVersion();
|
||||
logger.info('Content of current version:', filesInVersion);
|
||||
|
||||
for (const file of filesInVersion) {
|
||||
try {
|
||||
await deleteFileOrDirectory(path.join(updateFolder, file));
|
||||
} catch (error) {
|
||||
ErrorLogger.error(`Error deleting updated file or directory ${file}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
const tempExtractFolder = path.join(updateFolder, 'temp_extract');
|
||||
await unzipUpdate(updateFilePath, tempExtractFolder);
|
||||
|
||||
await moveFilesFromTemp(updateFolder, tempExtractFolder, filesInZip);
|
||||
|
||||
logger.info('Update successful. The update has been applied successfully.');
|
||||
|
||||
} catch (error) {
|
||||
ErrorLogger.error(`Error applying update: ${error.message}`);
|
||||
} finally {
|
||||
await cleanUp(updateFolder, updateFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanUp(basePath, zipFilePath) {
|
||||
const tempExtractFolder = path.join(basePath, 'temp_extract');
|
||||
await fs.rm(tempExtractFolder, { recursive: true });
|
||||
|
||||
await fs.unlink(zipFilePath);
|
||||
logger.info('Temporary files successfully deleted.');
|
||||
}
|
||||
|
||||
async function checkForUpdates() {
|
||||
try {
|
||||
logger.info('Checking for updates...');
|
||||
const response = await fetch('https://apollon.dinawo.fr/api/checkupdate');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.updateAvailable) {
|
||||
const updateUrl = 'https://apollon.dinawo.fr/api/download/all';
|
||||
const updateFolder = path.join(__dirname, '..');
|
||||
|
||||
await fs.mkdir(updateFolder, { recursive: true });
|
||||
|
||||
await applyUpdate(updateUrl, updateFolder);
|
||||
} else {
|
||||
logger.info('No updates available.');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Error checking for updates:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { applyUpdate, listFilesInZip, checkForUpdates };
|
||||
Reference in New Issue
Block a user