Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

feat(frontend:sync): validate path filters in settings

johavenbf89ea1b107d
diff --git a/frontend/src/app/applications/sync/components/dialogs/sync-path-settings.dialog.component.html b/frontend/src/app/applications/sync/components/dialogs/sync-path-settings.dialog.component.html
index 4203c302..54862f70 100644
--- a/frontend/src/app/applications/sync/components/dialogs/sync-path-settings.dialog.component.html
+++ b/frontend/src/app/applications/sync/components/dialogs/sync-path-settings.dialog.component.html
@@ -10,7 +10,8 @@
<tab customClass="tab-dialog">
<ng-template tabHeading>
<span class="app-tab-heading">
- <span class="app-tab-label">{{ 'Settings' | translate:locale.language }}</span>
+ <svg [lucideIcon]="icons.LucideSettings"></svg>
+ <span class="app-tab-label">{{ 'Settings' | translate: locale.language }}</span>
</span>
</ng-template>
<div class="app-tab-content">
@@ -20,7 +21,17 @@
<tab customClass="tab-dialog">
<ng-template tabHeading>
<span class="app-tab-heading">
- <span class="app-tab-label">{{ 'Filters' | translate:locale.language }}</span>
+ <svg [lucideIcon]="icons.LucideFunnel"></svg>
+ <span class="app-tab-label">{{ 'Filters' | translate: locale.language }}</span>
+ @if (hasInvalidFilters()) {
+ <span
+ class="text-danger fw-bold"
+ [attr.aria-label]="'Invalid regular expression' | translate: locale.language"
+ [title]="'Invalid regular expression' | translate: locale.language"
+ >
+ !
+ </span>
+ }
</span>
</ng-template>
<div class="app-tab-content sync-filters-tab">
@@ -47,9 +58,11 @@
id="sync-filter-value"
[(ngModel)]="currentFilter"
[disabled]="currentFilterType === SYNC_PATH_FILTER_TYPE.FILE || currentFilterType === SYNC_PATH_FILTER_TYPE.FOLDER"
- [placeholder]="filterTypePlaceholder[currentFilterType] | translate:locale.language"
+ [placeholder]="filterTypePlaceholder[currentFilterType] | translate: locale.language"
+ [class.is-invalid]="isCurrentFilterInvalid()"
class="form-control"
- type="text">
+ type="text"
+ />
<div class="sync-filters-actions">
@if (currentFilterType === SYNC_PATH_FILTER_TYPE.FILE) {
<button (click)="onSelect()" class="btn btn-default" l10nTranslate type="button">Browse</button>
@@ -57,7 +70,15 @@
@if (currentFilterType === SYNC_PATH_FILTER_TYPE.FOLDER) {
<button (click)="onSelect(ELECTRON_DIALOG.DIRECTORY)" class="btn btn-default" l10nTranslate type="button">Browse</button>
}
- <button (click)="addFilter()" [disabled]="!currentFilter" class="btn btn-success" l10nTranslate type="button">Add</button>
+ <button
+ (click)="addFilter()"
+ [disabled]="!currentFilter || syncPath.settings.filters.length >= SYNC_MAX_PATH_FILTERS || isCurrentFilterInvalid()"
+ class="btn btn-success"
+ l10nTranslate
+ type="button"
+ >
+ Add
+ </button>
</div>
</div>
</div>
@@ -69,10 +90,13 @@
@if (syncPath.settings.filters.length) {
@for (f of syncPath.settings.filters; track $index; let i = $index) {
<div class="sync-filter-item">
- <input [ngModel]="f"
- (ngModelChange)="syncPath.settings.filters[i] = $event"
- class="form-control"
- type="text">
+ <input
+ [ngModel]="f"
+ (ngModelChange)="onFilterChange(i, $event)"
+ [class.is-invalid]="isInvalidFilter(i)"
+ class="form-control"
+ type="text"
+ />
<button (click)="onRemoveFilter(i)" class="btn btn-danger" data-dismiss="modal" type="button">
<svg [lucideIcon]="icons.LucideX"></svg>
</button>
@@ -88,18 +112,20 @@
</tabset>
</div>
<div class="modal-footer">
- <button (click)="confirmDeletion = true"
- [disabled]="confirmDeletion"
- class="btn btn-danger me-2" data-dismiss="modal" type="button" l10nTranslate>
+ <button (click)="confirmDeletion = true" [disabled]="confirmDeletion" class="btn btn-danger me-2" data-dismiss="modal" type="button" l10nTranslate>
Remove
</button>
@if (store.isElectronApp()) {
<button (click)="onFlush()" class="btn btn-warning" data-dismiss="modal" type="button" l10nTranslate>Reset</button>
}
<button (click)="onCancel()" class="btn btn-secondary ms-auto" data-dismiss="modal" type="button" l10nTranslate>Cancel</button>
- <button (click)="onSubmit()"
- [disabled]="!syncPath.settings.name"
- class="btn {{confirmDeletion ? 'btn-danger' : 'btn-primary'}}" type="submit" l10nTranslate>
+ <button
+ (click)="onSubmit()"
+ [disabled]="!syncPath.settings.name"
+ class="btn {{ confirmDeletion ? 'btn-danger' : 'btn-primary' }}"
+ type="submit"
+ l10nTranslate
+ >
{{ confirmDeletion ? 'Confirm deletion' : 'Confirm' }}
</button>
</div>
diff --git a/frontend/src/app/applications/sync/components/dialogs/sync-path-settings.dialog.component.ts b/frontend/src/app/applications/sync/components/dialogs/sync-path-settings.dialog.component.ts
index e4de4f2b..ed5f4fcf 100755
--- a/frontend/src/app/applications/sync/components/dialogs/sync-path-settings.dialog.component.ts
+++ b/frontend/src/app/applications/sync/components/dialogs/sync-path-settings.dialog.component.ts
@@ -1,9 +1,11 @@
import { HttpErrorResponse } from '@angular/common/http'
import { Component, EventEmitter, inject, Input, OnInit, Output } from '@angular/core'
import { FormsModule } from '@angular/forms'
-import { LucideDynamicIcon, LucideRefreshCw, LucideX } from '@lucide/angular'
+import { LucideDynamicIcon, LucideFunnel, LucideRefreshCw, LucideSettings, LucideX } from '@lucide/angular'
import { L10N_LOCALE, L10nLocale, L10nTranslateDirective, L10nTranslatePipe } from 'angular-l10n'
import { TabDirective, TabHeadingDirective, TabsetComponent } from 'ngx-bootstrap/tabs'
+import { SYNC_MAX_PATH_FILTERS } from '@sync-in-server/backend/src/applications/sync/utils/path-filters/constants'
+import { validatePathFilterList } from '@sync-in-server/backend/src/applications/sync/utils/path-filters/path-filter-compiler'
import { ELECTRON_DIALOG } from '../../../../electron/constants/dialogs'
import { LayoutService } from '../../../../layout/layout.service'
import { StoreService } from '../../../../store/store.service'
@@ -36,6 +38,7 @@ export class SyncPathSettingsDialogComponent implements OnInit {
protected readonly layout = inject(LayoutService)
protected readonly store = inject(StoreService)
protected readonly ELECTRON_DIALOG = ELECTRON_DIALOG
+ protected readonly SYNC_MAX_PATH_FILTERS = SYNC_MAX_PATH_FILTERS
protected readonly SYNC_PATH_FILTER_TYPE = SYNC_PATH_FILTER_TYPE
protected syncPath: SyncPathModel
protected currentFilter: string
@@ -48,8 +51,12 @@ export class SyncPathSettingsDialogComponent implements OnInit {
[this.SYNC_PATH_FILTER_TYPE.END]: "with the extension ('.mp3', '.avi', '.mov' ...)",
[this.SYNC_PATH_FILTER_TYPE.EXPERT]: '[-+]?[0-9]*\\.?[0-9]*'
}
- protected readonly icons = { LucideX, LucideRefreshCw }
+ protected readonly icons = { LucideX, LucideRefreshCw, LucideSettings, LucideFunnel }
protected confirmDeletion = false
+ private invalidFilterIndexes = new Set<number>()
+ private filtersValidationPending = true
+ private lastValidatedFilter: string | undefined
+ private lastValidatedFilterIsInvalid = false
private readonly syncService = inject(SyncService)
ngOnInit() {
@@ -111,6 +118,12 @@ export class SyncPathSettingsDialogComponent implements OnInit {
onRemoveFilter(index: number) {
this.syncPath.settings.filters.splice(index, 1)
+ this.filtersValidationPending = true
+ }
+
+ protected onFilterChange(index: number, filter: string) {
+ this.syncPath.settings.filters[index] = filter
+ this.filtersValidationPending = true
}
onSelect(type: ELECTRON_DIALOG = this.ELECTRON_DIALOG.FILE) {
@@ -124,20 +137,36 @@ export class SyncPathSettingsDialogComponent implements OnInit {
}
addFilter() {
- if (
- this.currentFilterType === this.SYNC_PATH_FILTER_TYPE.FILE ||
- this.currentFilterType === this.SYNC_PATH_FILTER_TYPE.FOLDER ||
- this.currentFilterType === this.SYNC_PATH_FILTER_TYPE.EXPERT
- ) {
- this.syncPath.settings.filters.unshift(this.currentFilter)
- } else if (this.currentFilterType === this.SYNC_PATH_FILTER_TYPE.START) {
- this.syncPath.settings.filters.unshift(`^${this.currentFilter}.*`)
- } else if (this.currentFilterType === this.SYNC_PATH_FILTER_TYPE.IN) {
- this.syncPath.settings.filters.unshift(`.*${this.currentFilter}.*`)
- } else if (this.currentFilterType === this.SYNC_PATH_FILTER_TYPE.END) {
- this.syncPath.settings.filters.unshift(`.*${this.currentFilter}$`)
+ if (this.syncPath.settings.filters.length >= SYNC_MAX_PATH_FILTERS) {
+ return
}
+
+ this.syncPath.settings.filters.unshift(this.buildFilter(this.currentFilter))
this.currentFilter = null
+ this.filtersValidationPending = true
+ }
+
+ protected isInvalidFilter(index: number): boolean {
+ this.validateFilters()
+ return this.invalidFilterIndexes.has(index)
+ }
+
+ protected isCurrentFilterInvalid(): boolean {
+ if (!this.currentFilter) {
+ return false
+ }
+
+ const filter = this.buildFilter(this.currentFilter)
+ if (filter !== this.lastValidatedFilter) {
+ this.lastValidatedFilter = filter
+ this.lastValidatedFilterIsInvalid = validatePathFilterList([filter]).length > 0
+ }
+ return this.lastValidatedFilterIsInvalid
+ }
+
+ protected hasInvalidFilters(): boolean {
+ this.validateFilters()
+ return this.invalidFilterIndexes.size > 0
}
onCancel() {
@@ -147,4 +176,26 @@ export class SyncPathSettingsDialogComponent implements OnInit {
this.layout.closeDialog()
}
}
+
+ private buildFilter(filter: string): string {
+ if (this.currentFilterType === this.SYNC_PATH_FILTER_TYPE.START) {
+ return `^${filter}.*`
+ }
+ if (this.currentFilterType === this.SYNC_PATH_FILTER_TYPE.IN) {
+ return `.*${filter}.*`
+ }
+ if (this.currentFilterType === this.SYNC_PATH_FILTER_TYPE.END) {
+ return `.*${filter}$`
+ }
+ return filter
+ }
+
+ private validateFilters(): void {
+ if (!this.filtersValidationPending || !this.syncPath) {
+ return
+ }
+
+ this.filtersValidationPending = false
+ this.invalidFilterIndexes = new Set(validatePathFilterList(this.syncPath.settings.filters))
+ }
}
diff --git a/frontend/src/i18n/ca.json b/frontend/src/i18n/ca.json
index 9f6c71d4..cfbd62f3 100644
--- a/frontend/src/i18n/ca.json
+++ b/frontend/src/i18n/ca.json
@@ -790,6 +790,7 @@
"Version": "Versió",
"Filter type": "Tipus de filtre",
"Filter value": "Valor del filtre",
+ "Invalid regular expression": "Expressió regular no vàlida",
"No filter configured": "Cap filtre configurat",
"checksums are not identical": "Les sumes de comprovació no són idèntiques",
"size has changed since parsing": "La mida ha canviat des que s'ha analitzat",
diff --git a/frontend/src/i18n/de.json b/frontend/src/i18n/de.json
index 8cfb528b..f2e0d8e3 100644
--- a/frontend/src/i18n/de.json
+++ b/frontend/src/i18n/de.json
@@ -790,6 +790,7 @@
"Version": "Version",
"Filter type": "Filtertyp",
"Filter value": "Filterwert",
+ "Invalid regular expression": "Ungültiger regulärer Ausdruck",
"No filter configured": "Kein Filter konfiguriert",
"checksums are not identical": "Prüfsummen sind nicht identisch",
"size has changed since parsing": "Die Größe hat sich seit dem Parsen geändert",
diff --git a/frontend/src/i18n/es.json b/frontend/src/i18n/es.json
index eebc3f67..d26fce0d 100644
--- a/frontend/src/i18n/es.json
+++ b/frontend/src/i18n/es.json
@@ -790,6 +790,7 @@
"Version": "Versión",
"Filter type": "Tipo de filtro",
"Filter value": "Valor del filtro",
+ "Invalid regular expression": "Expresión regular no válida",
"No filter configured": "Ningún filtro configurado",
"checksums are not identical": "Las sumas de comprobación no son idénticas",
"size has changed since parsing": "El tamaño ha cambiado desde el análisis",
diff --git a/frontend/src/i18n/fr.json b/frontend/src/i18n/fr.json
index 098521ee..bcc56c0e 100644
--- a/frontend/src/i18n/fr.json
+++ b/frontend/src/i18n/fr.json
@@ -790,6 +790,7 @@
"Version": "Version",
"Filter type": "Type de filtre",
"Filter value": "Valeur du filtre",
+ "Invalid regular expression": "Expression régulière invalide",
"No filter configured": "Aucun filtre configuré",
"checksums are not identical": "Les sommes de contrôle ne sont pas identiques",
"size has changed since parsing": "La taille a changé depuis l'analyse",
diff --git a/frontend/src/i18n/hi.json b/frontend/src/i18n/hi.json
index 871d684c..7bc7185e 100644
--- a/frontend/src/i18n/hi.json
+++ b/frontend/src/i18n/hi.json
@@ -790,6 +790,7 @@
"Version": "संस्करण",
"Filter type": "फ़िल्टर प्रकार",
"Filter value": "फ़िल्टर मान",
+ "Invalid regular expression": "अमान्य रेगुलर एक्सप्रेशन",
"No filter configured": "कोई फ़िल्टर कॉन्फ़िगर नहीं है",
"checksums are not identical": "चेकसम एक जैसे नहीं हैं",
"size has changed since parsing": "पार्सिंग के बाद से आकार बदल गया है",
diff --git a/frontend/src/i18n/it.json b/frontend/src/i18n/it.json
index 108fa820..688a0478 100644
--- a/frontend/src/i18n/it.json
+++ b/frontend/src/i18n/it.json
@@ -790,6 +790,7 @@
"Version": "Versione",
"Filter type": "Tipo di filtro",
"Filter value": "Valore del filtro",
+ "Invalid regular expression": "Espressione regolare non valida",
"No filter configured": "Nessun filtro configurato",
"checksums are not identical": "I checksum non sono identici",
"size has changed since parsing": "La dimensione è cambiata dall'analisi",
diff --git a/frontend/src/i18n/ja.json b/frontend/src/i18n/ja.json
index 3596eb3a..2f86a6df 100644
--- a/frontend/src/i18n/ja.json
+++ b/frontend/src/i18n/ja.json
@@ -790,6 +790,7 @@
"Version": "バージョン",
"Filter type": "フィルタータイプ",
"Filter value": "フィルター値",
+ "Invalid regular expression": "無効な正規表現",
"No filter configured": "フィルターが設定されていません",
"checksums are not identical": "チェックサムが一致しません",
"size has changed since parsing": "解析後にサイズが変更されました",
diff --git a/frontend/src/i18n/ko.json b/frontend/src/i18n/ko.json
index 63720aec..0830573f 100644
--- a/frontend/src/i18n/ko.json
+++ b/frontend/src/i18n/ko.json
@@ -790,6 +790,7 @@
"Version": "버전",
"Filter type": "필터 유형",
"Filter value": "필터 값",
+ "Invalid regular expression": "잘못된 정규식",
"No filter configured": "구성된 필터가 없습니다",
"checksums are not identical": "체크섬이 동일하지 않습니다",
"size has changed since parsing": "파싱 이후 크기가 변경되었습니다",
diff --git a/frontend/src/i18n/nl.json b/frontend/src/i18n/nl.json
index 867ac8f0..60ef49fa 100644
--- a/frontend/src/i18n/nl.json
+++ b/frontend/src/i18n/nl.json
@@ -790,6 +790,7 @@
"Version": "Versie",
"Filter type": "Filtering",
"Filter value": "Filterwaarde",
+ "Invalid regular expression": "Ongeldige reguliere expressie",
"No filter configured": "Geen filter ingesteld",
"checksums are not identical": "controlesommen komen niet overeen",
"size has changed since parsing": "grootte is gewijzigd sinds verwerking",
diff --git a/frontend/src/i18n/pl.json b/frontend/src/i18n/pl.json
index 0e099abf..01ab24ae 100644
--- a/frontend/src/i18n/pl.json
+++ b/frontend/src/i18n/pl.json
@@ -790,6 +790,7 @@
"Version": "Wersja",
"Filter type": "Typ filtra",
"Filter value": "Wartość filtra",
+ "Invalid regular expression": "Nieprawidłowe wyrażenie regularne",
"No filter configured": "Brak skonfigurowanych filtrów",
"checksums are not identical": "Sumy kontrolne nie są identyczne",
"size has changed since parsing": "Rozmiar zmienił się od czasu parsowania",
diff --git a/frontend/src/i18n/pt-BR.json b/frontend/src/i18n/pt-BR.json
index 8804f730..674cadb5 100644
--- a/frontend/src/i18n/pt-BR.json
+++ b/frontend/src/i18n/pt-BR.json
@@ -790,6 +790,7 @@
"Version": "Versão",
"Filter type": "Tipo de filtro",
"Filter value": "Valor do filtro",
+ "Invalid regular expression": "Expressão regular inválida",
"No filter configured": "Nenhum filtro configurado",
"checksums are not identical": "As somas de verificação não são idênticas",
"size has changed since parsing": "O tamanho mudou desde a análise",
diff --git a/frontend/src/i18n/pt.json b/frontend/src/i18n/pt.json
index acd320ec..9f14834a 100644
--- a/frontend/src/i18n/pt.json
+++ b/frontend/src/i18n/pt.json
@@ -790,6 +790,7 @@
"Version": "Versão",
"Filter type": "Tipo de filtro",
"Filter value": "Valor do filtro",
+ "Invalid regular expression": "Expressão regular inválida",
"No filter configured": "Nenhum filtro configurado",
"checksums are not identical": "As somas de verificação não são idênticas",
"size has changed since parsing": "O tamanho mudou desde a análise",
diff --git a/frontend/src/i18n/ru.json b/frontend/src/i18n/ru.json
index 13a1418a..eb02a1b1 100644
--- a/frontend/src/i18n/ru.json
+++ b/frontend/src/i18n/ru.json
@@ -790,6 +790,7 @@
"Version": "Версия",
"Filter type": "Тип фильтра",
"Filter value": "Значение фильтра",
+ "Invalid regular expression": "Недопустимое регулярное выражение",
"No filter configured": "Фильтры не настроены",
"checksums are not identical": "Контрольные суммы не совпадают",
"size has changed since parsing": "Размер изменился с момента разбора",
diff --git a/frontend/src/i18n/tr.json b/frontend/src/i18n/tr.json
index af3e2097..3d56a5d3 100644
--- a/frontend/src/i18n/tr.json
+++ b/frontend/src/i18n/tr.json
@@ -790,6 +790,7 @@
"Version": "Sürüm",
"Filter type": "Filtre türü",
"Filter value": "Filtre değeri",
+ "Invalid regular expression": "Geçersiz düzenli ifade",
"No filter configured": "Yapılandırılmış filtre yok",
"checksums are not identical": "Sağlama toplamları aynı değil",
"size has changed since parsing": "Boyut ayrıştırmadan beri değişti",
diff --git a/frontend/src/i18n/zh.json b/frontend/src/i18n/zh.json
index 7c9cc46a..1368368e 100644
--- a/frontend/src/i18n/zh.json
+++ b/frontend/src/i18n/zh.json
@@ -790,6 +790,7 @@
"Version": "版本",
"Filter type": "过滤器类型",
"Filter value": "过滤器值",
+ "Invalid regular expression": "无效的正则表达式",
"No filter configured": "未配置过滤器",
"checksums are not identical": "校验和不一致",
"size has changed since parsing": "自解析后大小已更改",