1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-24 05:17:16 +02:00

Adding Album Reset Job and renaming DB reset to Gallery reset job

This commit is contained in:
Patrik J. Braun 2023-01-08 11:31:47 +01:00
parent 64432799d5
commit 4e6922054e
12 changed files with 103 additions and 54 deletions

View File

@ -7,6 +7,7 @@ import {SearchQueryDTO} from '../../../common/entities/SearchQueryDTO';
import {SavedSearchEntity} from './enitites/album/SavedSearchEntity'; import {SavedSearchEntity} from './enitites/album/SavedSearchEntity';
import {Logger} from '../../Logger'; import {Logger} from '../../Logger';
import {IObjectManager} from './IObjectManager'; import {IObjectManager} from './IObjectManager';
import {DirectoryEntity} from './enitites/DirectoryEntity';
const LOG_TAG = '[AlbumManager]'; const LOG_TAG = '[AlbumManager]';
@ -110,4 +111,13 @@ export class AlbumManager implements IObjectManager {
} }
this.isDBValid = true; this.isDBValid = true;
} }
async deleteAll() {
const connection = await SQLConnection.getConnection();
await connection
.getRepository(AlbumBaseEntity)
.createQueryBuilder('album')
.delete()
.execute();
}
} }

View File

@ -13,6 +13,7 @@ import * as path from 'path';
import {Utils} from '../../../common/Utils'; import {Utils} from '../../../common/Utils';
import {PreviewPhotoDTO} from '../../../common/entities/PhotoDTO'; import {PreviewPhotoDTO} from '../../../common/entities/PhotoDTO';
import {IObjectManager} from './IObjectManager'; import {IObjectManager} from './IObjectManager';
import {Logger} from '../../Logger';
const LOG_TAG = '[PreviewManager]'; const LOG_TAG = '[PreviewManager]';
@ -121,7 +122,6 @@ export class PreviewManager implements IObjectManager {
PreviewManager.setSorting(query); PreviewManager.setSorting(query);
return query; return query;
}; };
let previewMedia = null; let previewMedia = null;
if ( if (
Config.Preview.SearchQuery && Config.Preview.SearchQuery &&
@ -130,16 +130,26 @@ export class PreviewManager implements IObjectManager {
text: '', text: '',
} as TextSearch) } as TextSearch)
) { ) {
try {
const previewFilterQuery = await const previewFilterQuery = await
ObjectManagers.getInstance().SearchManager.prepareAndBuildWhereQuery(Config.Preview.SearchQuery); ObjectManagers.getInstance().SearchManager.prepareAndBuildWhereQuery(Config.Preview.SearchQuery);
previewMedia = await previewQuery() previewMedia = await previewQuery()
.andWhere(previewFilterQuery) .andWhere(previewFilterQuery)
.limit(1) .limit(1)
.getOne(); .getOne();
} catch (e) {
Logger.error('Cant get album preview using:', JSON.stringify(album.searchQuery), JSON.stringify(Config.Preview.SearchQuery));
throw e;
}
} }
if (!previewMedia) { if (!previewMedia) {
try {
previewMedia = await previewQuery().limit(1).getOne(); previewMedia = await previewQuery().limit(1).getOne();
} catch (e) {
Logger.error('Cant get album preview using:', JSON.stringify(album.searchQuery));
throw e;
}
} }
return previewMedia || null; return previewMedia || null;
} }

View File

@ -1,13 +1,14 @@
import { IJob } from './jobs/IJob'; import {IJob} from './jobs/IJob';
import { IndexingJob } from './jobs/IndexingJob'; import {IndexingJob} from './jobs/IndexingJob';
import { DBRestJob } from './jobs/DBResetJob'; import {GalleryRestJob} from './jobs/GalleryResetJob';
import { VideoConvertingJob } from './jobs/VideoConvertingJob'; import {VideoConvertingJob} from './jobs/VideoConvertingJob';
import { PhotoConvertingJob } from './jobs/PhotoConvertingJob'; import {PhotoConvertingJob} from './jobs/PhotoConvertingJob';
import { ThumbnailGenerationJob } from './jobs/ThumbnailGenerationJob'; import {ThumbnailGenerationJob} from './jobs/ThumbnailGenerationJob';
import { TempFolderCleaningJob } from './jobs/TempFolderCleaningJob'; import {TempFolderCleaningJob} from './jobs/TempFolderCleaningJob';
import { PreviewFillingJob } from './jobs/PreviewFillingJob'; import {PreviewFillingJob} from './jobs/PreviewFillingJob';
import { PreviewRestJob } from './jobs/PreviewResetJob'; import {PreviewRestJob} from './jobs/PreviewResetJob';
import {GPXCompressionJob} from './jobs/GPXCompressionJob'; import {GPXCompressionJob} from './jobs/GPXCompressionJob';
import {AlbumRestJob} from './jobs/AlbumResetJob';
export class JobRepository { export class JobRepository {
private static instance: JobRepository = null; private static instance: JobRepository = null;
@ -33,7 +34,7 @@ export class JobRepository {
} }
JobRepository.Instance.register(new IndexingJob()); JobRepository.Instance.register(new IndexingJob());
JobRepository.Instance.register(new DBRestJob()); JobRepository.Instance.register(new GalleryRestJob());
JobRepository.Instance.register(new PreviewFillingJob()); JobRepository.Instance.register(new PreviewFillingJob());
JobRepository.Instance.register(new PreviewRestJob()); JobRepository.Instance.register(new PreviewRestJob());
JobRepository.Instance.register(new VideoConvertingJob()); JobRepository.Instance.register(new VideoConvertingJob());
@ -41,3 +42,4 @@ JobRepository.Instance.register(new PhotoConvertingJob());
JobRepository.Instance.register(new ThumbnailGenerationJob()); JobRepository.Instance.register(new ThumbnailGenerationJob());
JobRepository.Instance.register(new GPXCompressionJob()); JobRepository.Instance.register(new GPXCompressionJob());
JobRepository.Instance.register(new TempFolderCleaningJob()); JobRepository.Instance.register(new TempFolderCleaningJob());
JobRepository.Instance.register(new AlbumRestJob());

View File

@ -0,0 +1,24 @@
import {ObjectManagers} from '../../ObjectManagers';
import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO';
import {Job} from './Job';
export class AlbumRestJob extends Job {
public readonly Name = DefaultsJobs[DefaultsJobs['Album Reset']];
public readonly ConfigTemplate: ConfigTemplateEntry[] = null;
protected readonly IsInstant = true;
public get Supported(): boolean {
return true;
}
protected async init(): Promise<void> {
// abstract function
}
protected async step(): Promise<boolean> {
this.Progress.Left = 1;
this.Progress.Processed++;
await ObjectManagers.getInstance().AlbumManager.deleteAll();
return false;
}
}

View File

@ -1,29 +0,0 @@
import { ObjectManagers } from '../../ObjectManagers';
import { Config } from '../../../../common/config/private/Config';
import {
ConfigTemplateEntry,
DefaultsJobs,
} from '../../../../common/entities/job/JobDTO';
import { Job } from './Job';
import { DatabaseType } from '../../../../common/config/private/PrivateConfig';
export class DBRestJob extends Job {
public readonly Name = DefaultsJobs[DefaultsJobs['Database Reset']];
public readonly ConfigTemplate: ConfigTemplateEntry[] = null;
protected readonly IsInstant = true;
public get Supported(): boolean {
return true;
}
protected async init(): Promise<void> {
// abstract function
}
protected async step(): Promise<boolean> {
this.Progress.Left = 1;
this.Progress.Processed++;
await ObjectManagers.getInstance().IndexingManager.resetDB();
return false;
}
}

View File

@ -0,0 +1,24 @@
import {ObjectManagers} from '../../ObjectManagers';
import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO';
import {Job} from './Job';
export class GalleryRestJob extends Job {
public readonly Name = DefaultsJobs[DefaultsJobs['Gallery Reset']];
public readonly ConfigTemplate: ConfigTemplateEntry[] = null;
protected readonly IsInstant = true;
public get Supported(): boolean {
return true;
}
protected async init(): Promise<void> {
// abstract function
}
protected async step(): Promise<boolean> {
this.Progress.Left = 1;
this.Progress.Processed++;
await ObjectManagers.getInstance().IndexingManager.resetDB();
return false;
}
}

View File

@ -1049,7 +1049,7 @@ export class ServerConfig extends ClientConfig {
job: DefaultsJobs[DefaultsJobs.Indexing], job: DefaultsJobs[DefaultsJobs.Indexing],
description: $localize`If you add a new folder to your gallery, the site indexes it automatically. If you would like to trigger indexing manually, click index button. (Note: search only works among the indexed directories.)` description: $localize`If you add a new folder to your gallery, the site indexes it automatically. If you would like to trigger indexing manually, click index button. (Note: search only works among the indexed directories.)`
}, { }, {
job: DefaultsJobs[DefaultsJobs['Database Reset']], job: DefaultsJobs[DefaultsJobs['Gallery Reset']],
hideProgress: true hideProgress: true
}] }]
} as TAGS } as TAGS

View File

@ -4,6 +4,7 @@ import {SortingMethods} from '../../entities/SortingMethods';
import {UserRoles} from '../../entities/UserDTO'; import {UserRoles} from '../../entities/UserDTO';
import {ConfigProperty, SubConfigClass} from 'typeconfig/common'; import {ConfigProperty, SubConfigClass} from 'typeconfig/common';
import {SearchQueryDTO} from '../../entities/SearchQueryDTO'; import {SearchQueryDTO} from '../../entities/SearchQueryDTO';
import { DefaultsJobs } from '../../entities/job/JobDTO';
declare let $localize: (s: TemplateStringsArray) => string; declare let $localize: (s: TemplateStringsArray) => string;
if (typeof $localize === 'undefined') { if (typeof $localize === 'undefined') {
@ -855,7 +856,11 @@ export class ClientConfig {
@ConfigProperty({ @ConfigProperty({
tags: { tags: {
name: $localize`Album`, name: $localize`Album`,
uiIcon: 'grid-two-up' uiIcon: 'grid-two-up',
uiJob: [ {
job: DefaultsJobs[DefaultsJobs['Album Reset']],
hideProgress: true
}]
} as TAGS, } as TAGS,
}) })
Album: ClientAlbumConfig = new ClientAlbumConfig(); Album: ClientAlbumConfig = new ClientAlbumConfig();

View File

@ -4,7 +4,7 @@ export type fieldType = 'string' | 'number' | 'boolean' | 'number-array';
export enum DefaultsJobs { export enum DefaultsJobs {
Indexing = 1, Indexing = 1,
'Database Reset' = 2, 'Gallery Reset' = 2,
'Video Converting' = 3, 'Video Converting' = 3,
'Photo Converting' = 4, 'Photo Converting' = 4,
'Thumbnail Generation' = 5, 'Thumbnail Generation' = 5,
@ -12,6 +12,7 @@ export enum DefaultsJobs {
'Preview Filling' = 7, 'Preview Filling' = 7,
'Preview Reset' = 8, 'Preview Reset' = 8,
'GPX Compression' = 9, 'GPX Compression' = 9,
'Album Reset' = 10,
} }
export interface ConfigTemplateEntry { export interface ConfigTemplateEntry {

View File

@ -31,8 +31,10 @@ export class BackendtextService {
switch (job as DefaultsJobs) { switch (job as DefaultsJobs) {
case DefaultsJobs.Indexing: case DefaultsJobs.Indexing:
return $localize`Indexing`; return $localize`Indexing`;
case DefaultsJobs['Database Reset']: case DefaultsJobs['Gallery Reset']:
return $localize`Database reset`; return $localize`Gallery reset`;
case DefaultsJobs['Album Reset']:
return $localize`Album reset`;
case DefaultsJobs['Thumbnail Generation']: case DefaultsJobs['Thumbnail Generation']:
return $localize`Thumbnail generation`; return $localize`Thumbnail generation`;
case DefaultsJobs['Photo Converting']: case DefaultsJobs['Photo Converting']:

View File

@ -38,7 +38,7 @@ export class SettingsService {
this.jobsService.onJobFinish.subscribe((jobName: string) => { this.jobsService.onJobFinish.subscribe((jobName: string) => {
if ( if (
jobName === DefaultsJobs[DefaultsJobs.Indexing] || jobName === DefaultsJobs[DefaultsJobs.Indexing] ||
jobName === DefaultsJobs[DefaultsJobs['Database Reset']] jobName === DefaultsJobs[DefaultsJobs['Gallery Reset']]
) { ) {
this.loadStatistic(); this.loadStatistic();
} }

View File

@ -127,7 +127,7 @@
[soloRun]="true" [soloRun]="true"
(jobError)="error=$event" (jobError)="error=$event"
[allowParallelRun]="false" [allowParallelRun]="false"
[danger]="i>0" [danger]="job.job.includes('Reset')"
[jobName]="job.job"></app-settings-job-button> [jobName]="job.job"></app-settings-job-button>
</ng-container> </ng-container>