Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RunOnFluxBot committed Nov 22, 2023
1 parent f8acbca commit 9145965
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions services/appsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9922,10 +9922,13 @@ async function syncthingApps() {
const devicesConfiguration = [];
const folderIds = [];
const foldersConfiguration = [];
const newFoldersConfiguration = [];
const myDeviceID = await syncthingService.getDeviceID();
if (myDeviceID.status !== 'success') {
return;
}
const allFoldersResp = await syncthingService.getConfigFolders();
log.info(`SyncthingApps getConfigFolders: ${JSON.stringify(allFoldersResp)}`);
// eslint-disable-next-line no-restricted-syntax
for (const installedApp of appsInstalled.data) {
if (installedApp.version <= 3) {
Expand Down Expand Up @@ -10010,6 +10013,26 @@ async function syncthingApps() {
paused: false,
type: folderSyncType,
});
const syncFolder = allFoldersResp.data.find((syncthingFolder) => syncthingFolder.id === id);
if (!syncFolder) {
newFoldersConfiguration.push({
id,
label,
path: folder,
devices,
paused: false,
type: folderSyncType,
});
} else if (syncFolder.paused || syncFolder.type !== folderSyncType) {
newFoldersConfiguration.push({
id,
label,
path: folder,
devices,
paused: false,
type: folderSyncType,
});
}
}
}
} else {
Expand Down Expand Up @@ -10096,13 +10119,32 @@ async function syncthingApps() {
paused: false,
type: folderSyncType,
});
const syncFolder = allFoldersResp.data.find((syncthingFolder) => syncthingFolder.id === id);
if (!syncFolder) {
newFoldersConfiguration.push({
id,
label,
path: folder,
devices,
paused: false,
type: folderSyncType,
});
} else if (syncFolder.paused || syncFolder.type !== folderSyncType) {
newFoldersConfiguration.push({
id,
label,
path: folder,
devices,
paused: false,
type: folderSyncType,
});
}
}
}
}
}
}
// remove folders that should not be synced anymore (this shall actually not trigger)
const allFoldersResp = await syncthingService.getConfigFolders();
const nonUsedFolders = allFoldersResp.data.filter((syncthingFolder) => !folderIds.includes(syncthingFolder.id));
// eslint-disable-next-line no-restricted-syntax
for (const nonUsedFolder of nonUsedFolders) {
Expand All @@ -10126,9 +10168,11 @@ async function syncthingApps() {
// now we have new accurate devicesConfiguration and foldersConfiguration
// add more of current devices
// excludes our current deviceID adjustment

await syncthingService.adjustConfigDevices('put', devicesConfiguration);
// add more of current folders
await syncthingService.adjustConfigFolders('put', foldersConfiguration);

await syncthingService.adjustConfigFolders('put', newFoldersConfiguration);

// all configuration changes applied

// check for errors in folders and if true reset that index database
Expand Down

0 comments on commit 9145965

Please sign in to comment.