A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.
chore: facilitate missing replication storage creation fix in pluton-pro
towfiqi05e490625387
diff --git a/backend/__tests__/utils/helpers.test.ts b/backend/__tests__/utils/helpers.test.tsindex 6c37226..4c61c63 100644--- a/backend/__tests__/utils/helpers.test.ts+++ b/backend/__tests__/utils/helpers.test.ts@@ -1,4 +1,9 @@-import { generateUID, getNestedValue, setNestedValue } from '../../src/utils/helpers';+import {+ generateUID,+ getNestedValue,+ normalizeStorageName,+ setNestedValue,+} from '../../src/utils/helpers';describe('helpers', () => {describe('generateUID', () => {@@ -294,4 +299,26 @@ describe('helpers', () => {expect(getNestedValue(obj, fullPath)).toBe('localhost');});});++ describe('normalizeStorageName', () => {+ it('should map the built-in local storage names to the rclone remote name', () => {+ expect(normalizeStorageName('Local')).toBe('local');+ expect(normalizeStorageName('Local Storage')).toBe('local');+ });++ it('should leave any other name untouched, including spaces', () => {+ expect(normalizeStorageName('SFTP sur Backupix')).toBe('SFTP sur Backupix');+ expect(normalizeStorageName('my-bucket')).toBe('my-bucket');+ });++ it('should be case sensitive, since rclone section names match exactly', () => {+ expect(normalizeStorageName('local storage')).toBe('local storage');+ });++ it('should return an empty string for missing input', () => {+ expect(normalizeStorageName(undefined)).toBe('');+ expect(normalizeStorageName(null)).toBe('');+ expect(normalizeStorageName('')).toBe('');+ });+ });});diff --git a/backend/src/services/PlanService.ts b/backend/src/services/PlanService.tsindex 3bc2cb0..1aaeacc 100644--- a/backend/src/services/PlanService.ts+++ b/backend/src/services/PlanService.ts@@ -16,7 +16,7 @@ import {PlanNotificationType,} from '../types/plans';import { planLogger } from '../utils/logger';-import { generateUID } from '../utils/helpers';+import { generateUID, normalizeStorageName } from '../utils/helpers';import { intervalToCron } from '../utils/intervalToCron';import { LocalStrategy as LocalBackupStrategy } from '../strategies/backup/LocalStrategy';import { RemoteStrategy as RemoteBackupStrategy } from '../strategies/backup/RemoteStrategy';@@ -714,7 +714,7 @@ export class PlanService {throw new NotFoundError('Storage not found');}return {- name: storage.id === 'local' ? 'local' : storage.name,+ name: storage.id === 'local' ? 'local' : normalizeStorageName(storage.name),type: storage.type as string,authType: storage.authType as string,settings: storage.settings as Record<string, string>,@@ -742,9 +742,8 @@ export class PlanService {return plan.settings.replication.storages.map(rs => {const record = storageRecords.find(s => s.id === rs.storageId);- const name = record?.name || '';return {- storageName: name === 'Local' || name === 'Local Storage' ? 'local' : name,+ storageName: normalizeStorageName(record?.name),storagePath: rs.storagePath,};})diff --git a/backend/src/services/StorageService.ts b/backend/src/services/StorageService.tsindex 6e4e51b..2325239 100644--- a/backend/src/services/StorageService.ts+++ b/backend/src/services/StorageService.ts@@ -165,9 +165,8 @@ export class StorageService {throw new AppError(400, 'Invalid storage data provided');}const { authType, credentials, settings, tags } = parsedStorageData;- // Update remote settings of all the devices first- const devicesWithStorage: string[] = [];- const plansWithStorage = await this.planStore.getStoragePlans(existingStorage.id);+ // Update remote settings of all the sources first+ const devicesWithStorage = await this.resolveStorageSources(existingStorage.id);const deviceUpdateResult: Record<string,{@@ -175,13 +174,7 @@ export class StorageService {result: string;}> = {};- if (plansWithStorage && plansWithStorage.length > 0) {- plansWithStorage.forEach(async plan => {- if (plan.sourceId && !devicesWithStorage.includes(plan.sourceId)) {- devicesWithStorage.push(plan.sourceId);- }- });-+ if (devicesWithStorage.length > 0) {//decrypt the existing credentialsconst existingCreds = existingStorage?.credentials;const decryptedOldCred: Record<string, string> = {};@@ -241,6 +234,26 @@ export class StorageService {}}+ /**+ * Resolves which sources hold an rclone config for a storage and therefore+ * need it re-pushed when the storage is edited.+ */+ protected async resolveStorageSources(storageId: string): Promise<string[]> {+ const plansWithStorage = await this.planStore.getStoragePlans(storageId);+ if (!plansWithStorage || plansWithStorage.length === 0) {+ return [];+ }++ const sourceIds = new Set<string>();+ for (const plan of plansWithStorage) {+ if (plan.sourceId) {+ sourceIds.add(plan.sourceId);+ }+ }++ return [...sourceIds];+ }+async deleteStorage(id: string): Promise<boolean> {try {const storage = await this.storageStore.getById(id);diff --git a/backend/src/utils/helpers.ts b/backend/src/utils/helpers.tsindex 03302f9..eb37987 100644--- a/backend/src/utils/helpers.ts+++ b/backend/src/utils/helpers.ts@@ -58,6 +58,15 @@ export function setNestedValue(obj: any, path: string, value: any): void {target[lastKey] = value;}+/**+ * Canonicalises a storage's display name to its rclone remote name. The built-in+ * local storage is stored as "Local"/"Local Storage" but its remote is "local".+ */+export function normalizeStorageName(name?: string | null): string {+ if (!name) return '';+ return name === 'Local' || name === 'Local Storage' ? 'local' : name;+}+export const safeCompare = (a: string, b: string): boolean => {if (a.length !== b.length) return false;return timingSafeEqual(Buffer.from(a), Buffer.from(b));