Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RunOnFluxBot committed Dec 9, 2024
1 parent ffe9989 commit dbd784e
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 99 deletions.
8 changes: 5 additions & 3 deletions services/appsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const { invalidMessages } = require('./invalidMessages');
const fluxCommunicationUtils = require('./fluxCommunicationUtils');

const fluxDirPath = path.join(__dirname, '../../../');
const appsFolder = `${fluxDirPath}ZelApps/`;
// ToDo: Fix all the string concatenation in this file and use path.join()
const appsFolderPath = process.env.FLUX_APPS_FOLDER || path.join(fluxDirPath, 'ZelApps');
const appsFolder = `${appsFolderPath}/`;

const cmdAsync = util.promisify(nodecmd.get);
const crontabLoad = util.promisify(systemcrontab.load);
Expand Down Expand Up @@ -4551,10 +4553,10 @@ async function getGlobalAppsSpecifications(req, res) {
query.hash = hash;
}
if (owner) {
query.owner = owner;
query['appSpecifications.owner'] = owner;
}
if (appname) {
query.name = appname;
query['appSpecifications.name'] = appname;
}
const projection = { projection: { _id: 0 } };
const results = await dbHelper.findInDatabase(database, globalAppsInformation, query, projection);
Expand Down
10 changes: 6 additions & 4 deletions services/backupRestoreService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const util = require('util');
const exec = util.promisify(require('child_process').exec);

const fluxDirPath = path.join(__dirname, '../../../');
const appsFolder = `${fluxDirPath}ZelApps/`;
// ToDo: Fix all the string concatenation in this file and use path.join()
const appsFolderPath = process.env.FLUX_APPS_FOLDER || path.join(fluxDirPath, 'ZelApps');
const appsFolder = `${appsFolderPath}/`;

/**
* Validates if a file path belongs to a specific set of upload types within the appsFolder.
Expand Down Expand Up @@ -168,7 +170,7 @@ async function getRemoteFileSize(req, res) {
}
const response = messageHelper.createDataMessage(fileSize);
return res ? res.json(response) : response;
// eslint-disable-next-line no-else-return
// eslint-disable-next-line no-else-return
} else {
const errorResponse = messageHelper.errUnauthorizedMessage();
return res ? res.json(errorResponse) : errorResponse;
Expand Down Expand Up @@ -209,7 +211,7 @@ async function removeBackupFile(req, res) {
const output = await IOUtils.removeFile(filepath);
const response = messageHelper.createSuccessMessage(output);
return res.json(response);
// eslint-disable-next-line no-else-return
// eslint-disable-next-line no-else-return
} else {
const errMessage = messageHelper.errUnauthorizedMessage();
return res.json(errMessage);
Expand Down Expand Up @@ -252,7 +254,7 @@ async function downloadLocalFile(req, res) {
const cmd = `sudo chmod 777 "${filepath}"`;
await exec(cmd, { maxBuffer: 1024 * 1024 * 10 });
return res.download(filepath, fileName);
// eslint-disable-next-line no-else-return
// eslint-disable-next-line no-else-return
} else {
const errMessage = messageHelper.errUnauthorizedMessage();
return res.json(errMessage);
Expand Down
3 changes: 2 additions & 1 deletion services/benchmarkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ let response = messageHelper.createErrorMessage();
let benchdClient = null;

async function buildBenchdClient() {
// just use process.cwd() or os.homedir() or something
const homeDirPath = path.join(__dirname, '../../../../');
const fluxbenchdPath = path.join(homeDirPath, '.fluxbenchmark');
const fluxbenchdPath = process.env.FLUXBENCH_PATH || path.join(homeDirPath, '.fluxbenchmark');

const exists = await fs.stat(fluxbenchdPath).catch(() => false);

Expand Down
4 changes: 3 additions & 1 deletion services/dockerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const deviceHelper = require('./deviceHelper');
const log = require('../lib/log');

const fluxDirPath = path.join(__dirname, '../../../');
const appsFolder = `${fluxDirPath}ZelApps/`;
// ToDo: Fix all the string concatenation in this file and use path.join()
const appsFolderPath = process.env.FLUX_APPS_FOLDER || path.join(fluxDirPath, 'ZelApps');
const appsFolder = `${appsFolderPath}/`;

const docker = new Docker();

Expand Down
41 changes: 17 additions & 24 deletions services/fluxshareService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const generalService = require('./generalService');
const log = require('../lib/log');
const IOUtils = require('./IOUtils');

const dirpath = path.join(__dirname, '../../../');
const appsFolder = process.env.FLUX_APPS_FOLDER || path.join(dirpath, 'ZelApps');

/**
* Delete a specific FluxShare file.
* @param {string} file Name of file to be deleted.
Expand Down Expand Up @@ -88,8 +91,7 @@ function getAllFiles(dirPath, arrayOfFiles) {
* @returns {number} Total file size (GB).
*/
function getFluxShareSize() {
const dirpath = path.join(__dirname, '../../../');
const directoryPath = `${dirpath}ZelApps/ZelShare`;
const directoryPath = path.join(appsFolder, 'ZelShare');

const arrayOfFiles = getAllFiles(directoryPath);

Expand Down Expand Up @@ -300,8 +302,7 @@ async function fluxShareDownloadFolder(req, res, authorized = false) {
return;
}

const dirpath = path.join(__dirname, '../../../');
const folderpath = `${dirpath}ZelApps/ZelShare/${folder}`;
const folderpath = path.join(appsFolder, 'ZelShare', folder);

// beautify name
const folderNameArray = folderpath.split('/');
Expand Down Expand Up @@ -360,8 +361,7 @@ async function fluxShareDownloadFile(req, res) {
return;
}

const dirpath = path.join(__dirname, '../../../');
const filepath = `${dirpath}ZelApps/ZelShare/${file}`;
const filepath = path.join(appsFolder, 'ZelShare', file);

// beautify name
const fileNameArray = file.split('/');
Expand Down Expand Up @@ -392,8 +392,7 @@ async function fluxShareDownloadFile(req, res) {
}

// check if file is file. If directory use zelshareDwonloadFolder
const dirpath = path.join(__dirname, '../../../');
const filepath = `${dirpath}ZelApps/ZelShare/${file}`;
const filepath = path.join(appsFolder, 'ZelShare', file);
const fileStats = await fs.promises.lstat(filepath);
const isDirectory = fileStats.isDirectory();

Expand Down Expand Up @@ -452,14 +451,13 @@ async function fluxShareRename(req, res) {
const fileURI = encodeURIComponent(oldpath);
await fluxShareDatabaseFileDeleteMultiple(fileURI);

const dirpath = path.join(__dirname, '../../../');
const oldfullpath = `${dirpath}ZelApps/ZelShare/${oldpath}`;
let newfullpath = `${dirpath}ZelApps/ZelShare/${newname}`;
const oldfullpath = path.join(appsFolder, 'ZelShare', oldpath);
let newfullpath = path.join(appsFolder, 'ZelShare', newname);
const fileURIArray = fileURI.split('%2F');
fileURIArray.pop();
if (fileURIArray.length > 0) {
const renamingFolder = fileURIArray.join('/');
newfullpath = `${dirpath}ZelApps/ZelShare/${renamingFolder}/${newname}`;
newfullpath = path.join(appsFolder, 'ZelShare', renamingFolder, newname);
}
await fs.promises.rename(oldfullpath, newfullpath);

Expand Down Expand Up @@ -504,8 +502,7 @@ async function fluxShareRemoveFile(req, res) {

await fluxShareDatabaseFileDelete(fileURI);

const dirpath = path.join(__dirname, '../../../');
const filepath = `${dirpath}ZelApps/ZelShare/${file}`;
const filepath = path.join(appsFolder, 'ZelShare', file);
await fs.promises.unlink(filepath);

const response = messageHelper.createSuccessMessage('File Removed');
Expand Down Expand Up @@ -545,8 +542,7 @@ async function fluxShareRemoveFolder(req, res) {
throw new Error('No folder specified');
}

const dirpath = path.join(__dirname, '../../../');
const filepath = `${dirpath}ZelApps/ZelShare/${folder}`;
const filepath = path.join(appsFolder, 'ZelShare', folder);
// await fs.promises.rmdir(filepath);
await IOUtils.removeDirectory(filepath);
const response = messageHelper.createSuccessMessage('Folder Removed');
Expand Down Expand Up @@ -583,8 +579,7 @@ async function fluxShareGetFolder(req, res) {
let { folder } = req.params;
folder = folder || req.query.folder || '';

const dirpath = path.join(__dirname, '../../../');
const filepath = `${dirpath}ZelApps/ZelShare/${folder}`;
const filepath = path.join(appsFolder, 'ZelShare', folder);
const options = {
withFileTypes: false,
};
Expand Down Expand Up @@ -654,8 +649,7 @@ async function fluxShareCreateFolder(req, res) {
let { folder } = req.params;
folder = folder || req.query.folder || '';

const dirpath = path.join(__dirname, '../../../');
const filepath = `${dirpath}ZelApps/ZelShare/${folder}`;
const filepath = path.join(appsFolder, 'ZelShare', folder);

await fs.promises.mkdir(filepath);

Expand Down Expand Up @@ -684,8 +678,7 @@ async function fluxShareFileExists(req, res) {
let { file } = req.params;
file = file || req.query.file;

const dirpath = path.join(__dirname, '../../../');
const filepath = `${dirpath}ZelApps/ZelShare/${file}`;
const filepath = path.join(appsFolder, 'ZelShare', file);
let fileExists = true;
try {
await fs.promises.access(filepath, fs.constants.F_OK); // check file exists and write ability
Expand Down Expand Up @@ -802,8 +795,8 @@ async function fluxShareUpload(req, res) {
if (folder) {
folder += '/';
}
const dirpath = path.join(__dirname, '../../../');
const uploadDir = `${dirpath}ZelApps/ZelShare/${folder}`;
const uploadDir = path.join(appsFolder, 'ZelShare', folder);

const options = {
multiples: true,
uploadDir,
Expand Down
Loading

0 comments on commit dbd784e

Please sign in to comment.