Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RunOnFluxBot committed Nov 8, 2023
1 parent 5e2b3fa commit 4e5ea56
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 55 deletions.
97 changes: 43 additions & 54 deletions services/appsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1859,30 +1859,23 @@ async function createAppVolume(appSpecifications, appName, isComponent, res) {
}

// if s flag create .stfolder
const containersData = appSpecifications.containerData.split('|');
// eslint-disable-next-line no-restricted-syntax
for (let i = 0; i < containersData.length; i += 1) {
const container = containersData[i];
const containerDataFlags = container.split(':')[1] ? container.split(':')[0] : '';
if (containerDataFlags.includes('s')) {
const containerFolder = i === 0 ? '' : `/appdata${container.split(':')[1].replace(containersData[0], '')}`;
const stFolderCreation = {
status: 'Creating .stfolder for syncthing...',
};
log.info(stFolderCreation);
if (res) {
res.write(serviceHelper.ensureString(stFolderCreation));
}
const execDIRst = `sudo mkdir -p ${appsFolder + appId + containerFolder}/.stfolder`;
// eslint-disable-next-line no-await-in-loop
await cmdAsync(execDIRst);
const stFolderCreation2 = {
status: '.stfolder created',
};
log.info(stFolderCreation2);
if (res) {
res.write(serviceHelper.ensureString(stFolderCreation2));
}
const containerDataFlags = appSpecifications.containerData.split('|')[0].split(':')[1] ? appSpecifications.containerData.split('|')[0].split(':')[0] : '';
if (containerDataFlags.includes('s')) {
const stFolderCreation = {
status: 'Creating .stfolder for syncthing...',
};
log.info(stFolderCreation);
if (res) {
res.write(serviceHelper.ensureString(stFolderCreation));
}
const execDIRst = `sudo mkdir -p ${appsFolder + appId}/.stfolder`;
await cmdAsync(execDIRst);
const stFolderCreation2 = {
status: '.stfolder created',
};
log.info(stFolderCreation2);
if (res) {
res.write(serviceHelper.ensureString(stFolderCreation2));
}
}

Expand Down Expand Up @@ -9823,36 +9816,32 @@ async function stopSyncthingApp(appComponentName, res) {
return;
}
let folderId = null;
// eslint-disable-next-line no-restricted-syntax
for (const syncthingFolder of allSyncthingFolders.data) {
if (syncthingFolder.path === folder || syncthingFolder.path.includes(`${folder}/`)) {
allSyncthingFolders.data.forEach((syncthingFolder) => {
if (syncthingFolder.path === folder) {
folderId = syncthingFolder.id;
}
if (folderId) {
const adjustSyncthingA = {
status: `Stopping syncthing on folder ${syncthingFolder.path}...`,
};
// remove folder from syncthing
// eslint-disable-next-line no-await-in-loop
await syncthingService.adjustConfigFolders('delete', undefined, folderId);
// eslint-disable-next-line no-await-in-loop
const restartRequired = await syncthingService.getConfigRestartRequired();
if (restartRequired.status === 'success' && restartRequired.data.requiresRestart === true) {
// eslint-disable-next-line no-await-in-loop
await syncthingService.systemRestart();
}
const adjustSyncthingB = {
status: 'Syncthing adjusted',
};
log.info(adjustSyncthingA);
if (res) {
res.write(serviceHelper.ensureString(adjustSyncthingA));
}
if (res) {
res.write(serviceHelper.ensureString(adjustSyncthingB));
}
}
folderId = null;
});
if (!folderId) {
return;
}
const adjustSyncthingA = {
status: 'Adjusting Syncthing...',
};
// remove folder from syncthing
await syncthingService.adjustConfigFolders('delete', undefined, folderId);
const restartRequired = await syncthingService.getConfigRestartRequired();
if (restartRequired.status === 'success' && restartRequired.data.requiresRestart === true) {
await syncthingService.systemRestart();
}
const adjustSyncthingB = {
status: 'Syncthing adjusted',
};
log.info(adjustSyncthingA);
if (res) {
res.write(serviceHelper.ensureString(adjustSyncthingA));
}
if (res) {
res.write(serviceHelper.ensureString(adjustSyncthingB));
}
} catch (error) {
log.error(error);
Expand Down Expand Up @@ -9907,7 +9896,7 @@ async function syncthingApps() {
const container = containersData[i];
const containerDataFlags = container.split(':')[1] ? container.split(':')[0] : '';
if (containerDataFlags.includes('s')) {
const containerFolder = i === 0 ? '' : `/appdata${container.split(':')[1].replace(containersData[0], '')}`;
const containerFolder = i === 0 ? '' : container.split(':')[1];
const identifier = installedApp.name;
const appId = dockerService.getAppIdentifier(identifier);
const folder = `${appsFolder + appId + containerFolder}`;
Expand Down Expand Up @@ -9964,7 +9953,7 @@ async function syncthingApps() {
const container = containersData[i];
const containerDataFlags = container.split(':')[1] ? container.split(':')[0] : '';
if (containerDataFlags.includes('s')) {
const containerFolder = i === 0 ? '' : `/appdata${container.split(':')[1].replace(containersData[0], '')}`;
const containerFolder = i === 0 ? '' : container.split(':')[1];
const identifier = `${installedComponent.name}_${installedApp.name}`;
const appId = dockerService.getAppIdentifier(identifier);
const folder = `${appsFolder + appId + containerFolder}`;
Expand Down
2 changes: 1 addition & 1 deletion services/fluxService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ async function adjustBlockedRepositories(req, res) {
error.name,
error.code,
);
res.json(errorResponse);
res.json(errorResponse);
}
});
} else {
Expand Down

0 comments on commit 4e5ea56

Please sign in to comment.