1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

Ability to exclude directories, and config to choose them.

This commit is contained in:
Tim Morley 2019-12-04 21:40:57 +00:00
parent 91d69dcf3d
commit 719a2e01d8
6 changed files with 101 additions and 2 deletions

View File

@ -57,6 +57,50 @@ export class DiskMangerWorker {
return path.basename(name);
}
public static excludeDir(name: string,relativeDirectoryName: string, absoluteDirectoryName: string) {
const absoluteName=path.normalize(path.join(absoluteDirectoryName,name));
const relativeName=path.normalize(path.join(relativeDirectoryName,name));
console.log("----- Starting exlude dir -----");
console.log("name %s",name);
console.log("absoluteDirectoryName %s",absoluteDirectoryName);
console.log("absoluteName %s",absoluteName);
console.log("relativeDirectoryName %s",relativeDirectoryName);
console.log("relativeName %s",relativeName);
console.log("Config.Server.indexing.excludeFolderList %s",Config.Server.indexing.excludeFolderList);
for (let j = 0; j < Config.Server.indexing.excludeFolderList.length; j++) {
const exclude=Config.Server.indexing.excludeFolderList[j];
console.log("trying dir %s",exclude);
if (exclude.startsWith('/')) {
if (exclude==absoluteName) {
return true;
}
} else if (exclude.includes('/')) {
if (path.normalize(exclude)==relativeName) {
return true;
}
} else {
if (exclude==name) {
return true;
}
}
}
for (let j = 0; j < Config.Server.indexing.excludeFileList.length; j++) {
const exclude=Config.Server.indexing.excludeFileList[j];
console.log("trying file %s",exclude);
if (fs.existsSync(path.join(absoluteName,exclude))) {
return true;
}
}
return false;
}
public static scanDirectory(relativeDirectoryName: string, maxPhotos: number = null, photosOnly: boolean = false): Promise<DirectoryDTO> {
return new Promise<DirectoryDTO>((resolve, reject) => {
relativeDirectoryName = this.normalizeDirPath(relativeDirectoryName);
@ -90,6 +134,9 @@ export class DiskMangerWorker {
if (photosOnly === true) {
continue;
}
if (DiskMangerWorker.excludeDir(file,relativeDirectoryName,absoluteDirectoryName)) {
continue;
}
const d = await DiskMangerWorker.scanDirectory(path.join(relativeDirectoryName, file),
Config.Server.indexing.folderPreviewSize, true
);

View File

@ -54,6 +54,8 @@ export interface IndexingConfig {
folderPreviewSize: number;
cachedFolderTimeout: number; // Do not rescans the folder if seems ok
reIndexingSensitivity: ReIndexingSensitivity;
excludeFolderList: string[]
excludeFileList: string[]
}
export interface ThreadingConfig {

View File

@ -57,7 +57,9 @@ export class PrivateConfigClass extends PublicConfigClass implements IPrivateCon
indexing: {
folderPreviewSize: 2,
cachedFolderTimeout: 1000 * 60 * 60,
reIndexingSensitivity: ReIndexingSensitivity.low
reIndexingSensitivity: ReIndexingSensitivity.low,
excludeFolderList: [],
excludeFileList: []
},
duplicates: {
listingLimit: 1000

View File

@ -49,6 +49,36 @@
</div>
</div>
<div class="form-group row">
<label class="col-md-2 control-label" for="excludeFolderList" i18n>Exclude Folder List</label>
<div class="col-md-10">
<input type="text" class="form-control" placeholder=""
id="excludeFolderList"
[(ngModel)]="excludeFolderList"
name="excludeFolderList" required>
<small class="form-text text-muted">
<ng-container i18n>Folders to exclude from indexing</ng-container><br/>
<ng-container
i18n>';' separated strings. If an entry starts with '/' it is treated as an absolute path. If it doesn't start with '/' but contains a '/', the path is relative to the image directory. If it doesn't contain a '/', any folder with this name will be excluded.</ng-container>
</small>
</div>
</div>
<div class="form-group row">
<label class="col-md-2 control-label" for="excludeFileList" i18n>Exclude File List</label>
<div class="col-md-10">
<input type="text" class="form-control" placeholder=""
id="excludeFileList"
[(ngModel)]="excludeFileList"
name="excludeFileList" required>
<small class="form-text text-muted">
<ng-container i18n>FFiles that mark a folder to be excluded from indexing</ng-container><br/>
<ng-container
i18n>';' separated strings. Any folder that contains a file with this name will be excluded from indexing.</ng-container>
</small>
</div>
</div>
<button class="btn btn-success float-right"
[disabled]="!settingsForm.form.valid || !changed || inProgress"

View File

@ -81,6 +81,22 @@ export class IndexingSettingsComponent extends SettingsComponent<IndexingConfig,
}
};
get excludeFolderList(): string {
return this.settings.excludeFolderList.join(';');
}
set excludeFolderList(value: string) {
this.settings.excludeFolderList = value.split(';');
}
get excludeFileList(): string {
return this.settings.excludeFileList.join(';');
}
set excludeFileList(value: string) {
this.settings.excludeFileList = value.split(';');
}
async ngOnInit() {
super.ngOnInit();
this.types = Utils

View File

@ -109,7 +109,9 @@ export class SettingsService {
indexing: {
cachedFolderTimeout: 0,
folderPreviewSize: 0,
reIndexingSensitivity: ReIndexingSensitivity.medium
reIndexingSensitivity: ReIndexingSensitivity.medium,
excludeFolderList: [],
excludeFileList: []
},
photoMetadataSize: 512 * 1024,
duplicates: {