mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
adding indexing with thumbnails
This commit is contained in:
parent
a2d56e1ea2
commit
48aaf54c7d
@ -11,6 +11,7 @@ import {BasicConfigDTO} from '../../common/entities/settings/BasicConfigDTO';
|
|||||||
import {OtherConfigDTO} from '../../common/entities/settings/OtherConfigDTO';
|
import {OtherConfigDTO} from '../../common/entities/settings/OtherConfigDTO';
|
||||||
import {ProjectPath} from '../ProjectPath';
|
import {ProjectPath} from '../ProjectPath';
|
||||||
import {PrivateConfigClass} from '../../common/config/private/PrivateConfigClass';
|
import {PrivateConfigClass} from '../../common/config/private/PrivateConfigClass';
|
||||||
|
import {IndexingDTO} from '../../common/entities/settings/IndexingDTO';
|
||||||
|
|
||||||
|
|
||||||
const LOG_TAG = '[AdminMWs]';
|
const LOG_TAG = '[AdminMWs]';
|
||||||
@ -317,7 +318,8 @@ export class AdminMWs {
|
|||||||
|
|
||||||
public static startIndexing(req: Request, res: Response, next: NextFunction) {
|
public static startIndexing(req: Request, res: Response, next: NextFunction) {
|
||||||
try {
|
try {
|
||||||
ObjectManagerRepository.getInstance().IndexingManager.startIndexing();
|
const createThumbnails: boolean = (<IndexingDTO>req.body).createThumbnails || false;
|
||||||
|
ObjectManagerRepository.getInstance().IndexingManager.startIndexing(createThumbnails);
|
||||||
req.resultPipe = 'ok';
|
req.resultPipe = 'ok';
|
||||||
return next();
|
return next();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -325,6 +327,7 @@ export class AdminMWs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static getIndexingProgress(req: Request, res: Response, next: NextFunction) {
|
public static getIndexingProgress(req: Request, res: Response, next: NextFunction) {
|
||||||
try {
|
try {
|
||||||
req.resultPipe = ObjectManagerRepository.getInstance().IndexingManager.getProgress();
|
req.resultPipe = ObjectManagerRepository.getInstance().IndexingManager.getProgress();
|
||||||
|
@ -179,7 +179,7 @@ export class ThumbnailGeneratorMWs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static generateThumbnailName(mediaPath: string, size: number): string {
|
public static generateThumbnailName(mediaPath: string, size: number): string {
|
||||||
return crypto.createHash('md5').update(mediaPath).digest('hex') + '_' + size + '.jpg';
|
return crypto.createHash('md5').update(mediaPath).digest('hex') + '_' + size + '.jpg';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {IndexingProgressDTO} from '../../../common/entities/settings/IndexingProgressDTO';
|
import {IndexingProgressDTO} from '../../../common/entities/settings/IndexingProgressDTO';
|
||||||
|
|
||||||
export interface IIndexingManager {
|
export interface IIndexingManager {
|
||||||
startIndexing(): void;
|
startIndexing(createThumbnails?: boolean): void;
|
||||||
|
|
||||||
getProgress(): IndexingProgressDTO;
|
getProgress(): IndexingProgressDTO;
|
||||||
|
|
||||||
|
@ -6,6 +6,11 @@ import * as path from 'path';
|
|||||||
import {SQLConnection} from './SQLConnection';
|
import {SQLConnection} from './SQLConnection';
|
||||||
import {DirectoryEntity} from './enitites/DirectoryEntity';
|
import {DirectoryEntity} from './enitites/DirectoryEntity';
|
||||||
import {Logger} from '../../Logger';
|
import {Logger} from '../../Logger';
|
||||||
|
import {RendererInput, ThumbnailSourceType, ThumbnailWorker} from '../threading/ThumbnailWorker';
|
||||||
|
import {Config} from '../../../common/config/private/Config';
|
||||||
|
import {MediaDTO} from '../../../common/entities/MediaDTO';
|
||||||
|
import {ProjectPath} from '../../ProjectPath';
|
||||||
|
import {ThumbnailGeneratorMWs} from '../../middlewares/thumbnail/ThumbnailGeneratorMWs';
|
||||||
|
|
||||||
const LOG_TAG = '[IndexingManager]';
|
const LOG_TAG = '[IndexingManager]';
|
||||||
|
|
||||||
@ -13,7 +18,7 @@ export class IndexingManager implements IIndexingManager {
|
|||||||
directoriesToIndex: string[] = [];
|
directoriesToIndex: string[] = [];
|
||||||
indexingProgress = null;
|
indexingProgress = null;
|
||||||
enabled = false;
|
enabled = false;
|
||||||
private indexNewDirectory = async () => {
|
private indexNewDirectory = async (createThumbnails: boolean = false) => {
|
||||||
if (this.directoriesToIndex.length === 0) {
|
if (this.directoriesToIndex.length === 0) {
|
||||||
this.indexingProgress = null;
|
this.indexingProgress = null;
|
||||||
if (global.gc) {
|
if (global.gc) {
|
||||||
@ -32,10 +37,29 @@ export class IndexingManager implements IIndexingManager {
|
|||||||
for (let i = 0; i < scanned.directories.length; i++) {
|
for (let i = 0; i < scanned.directories.length; i++) {
|
||||||
this.directoriesToIndex.push(path.join(scanned.directories[i].path, scanned.directories[i].name));
|
this.directoriesToIndex.push(path.join(scanned.directories[i].path, scanned.directories[i].name));
|
||||||
}
|
}
|
||||||
process.nextTick(this.indexNewDirectory);
|
if (createThumbnails) {
|
||||||
|
for (let i = 0; i < scanned.media.length; i++) {
|
||||||
|
const media = scanned.media[i];
|
||||||
|
const mPath = path.join(ProjectPath.ImageFolder, media.directory.path, media.directory.name, media.name);
|
||||||
|
const thPath = path.join(ProjectPath.ThumbnailFolder,
|
||||||
|
ThumbnailGeneratorMWs.generateThumbnailName(mPath, Config.Client.Thumbnail.thumbnailSizes[0]));
|
||||||
|
await ThumbnailWorker.render(<RendererInput>{
|
||||||
|
type: MediaDTO.isVideo(media) ? ThumbnailSourceType.Video : ThumbnailSourceType.Image,
|
||||||
|
mediaPath: mPath,
|
||||||
|
size: Config.Client.Thumbnail.thumbnailSizes[0],
|
||||||
|
thPath: thPath,
|
||||||
|
makeSquare: false,
|
||||||
|
qualityPriority: Config.Server.thumbnail.qualityPriority
|
||||||
|
}, Config.Server.thumbnail.processingLibrary);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
process.nextTick(() => {
|
||||||
|
this.indexNewDirectory(createThumbnails);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
startIndexing(): void {
|
startIndexing(createThumbnails: boolean = false): void {
|
||||||
if (this.directoriesToIndex.length === 0 && this.enabled === false) {
|
if (this.directoriesToIndex.length === 0 && this.enabled === false) {
|
||||||
Logger.info(LOG_TAG, 'Starting indexing');
|
Logger.info(LOG_TAG, 'Starting indexing');
|
||||||
this.indexingProgress = <IndexingProgressDTO>{
|
this.indexingProgress = <IndexingProgressDTO>{
|
||||||
@ -45,7 +69,7 @@ export class IndexingManager implements IIndexingManager {
|
|||||||
};
|
};
|
||||||
this.directoriesToIndex.push('/');
|
this.directoriesToIndex.push('/');
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
this.indexNewDirectory();
|
this.indexNewDirectory(createThumbnails);
|
||||||
} else {
|
} else {
|
||||||
Logger.info(LOG_TAG, 'Already indexing..');
|
Logger.info(LOG_TAG, 'Already indexing..');
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ export class AdminRouter {
|
|||||||
AdminMWs.getIndexingProgress,
|
AdminMWs.getIndexingProgress,
|
||||||
RenderingMWs.renderResult
|
RenderingMWs.renderResult
|
||||||
);
|
);
|
||||||
app.put('/api/admin/indexes/job',
|
app.post('/api/admin/indexes/job',
|
||||||
AuthenticationMWs.authenticate,
|
AuthenticationMWs.authenticate,
|
||||||
AuthenticationMWs.authorise(UserRoles.Admin),
|
AuthenticationMWs.authorise(UserRoles.Admin),
|
||||||
AdminMWs.startIndexing,
|
AdminMWs.startIndexing,
|
||||||
|
3
common/entities/settings/IndexingDTO.ts
Normal file
3
common/entities/settings/IndexingDTO.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export interface IndexingDTO {
|
||||||
|
createThumbnails: boolean;
|
||||||
|
}
|
@ -88,17 +88,22 @@
|
|||||||
<button class="btn btn-success"
|
<button class="btn btn-success"
|
||||||
*ngIf="_settingsService.progress.value == null"
|
*ngIf="_settingsService.progress.value == null"
|
||||||
[disabled]="inProgress"
|
[disabled]="inProgress"
|
||||||
(click)="index()" i18n>Index
|
title="Indexes the folders"
|
||||||
</button>
|
i18n-title
|
||||||
|
(click)="index(false)" i18n>Index</button>
|
||||||
|
<button class="btn btn-primary"
|
||||||
|
title="Indexes the folders and also creates the thumbnails"
|
||||||
|
i18n-title
|
||||||
|
*ngIf="_settingsService.progress.value == null"
|
||||||
|
[disabled]="inProgress"
|
||||||
|
(click)="index(true)" i18n>Index with Thumbnails</button>
|
||||||
<button class="btn btn-default"
|
<button class="btn btn-default"
|
||||||
*ngIf="_settingsService.progress.value != null"
|
*ngIf="_settingsService.progress.value != null"
|
||||||
[disabled]="inProgress"
|
[disabled]="inProgress"
|
||||||
(click)="cancelIndexing()" i18n>Cancel
|
(click)="cancelIndexing()" i18n>Cancel</button>
|
||||||
</button>
|
|
||||||
<button class="btn btn-danger"
|
<button class="btn btn-danger"
|
||||||
[disabled]="inProgress"
|
[disabled]="inProgress"
|
||||||
(click)="resetDatabase()" i18n>Reset Indexes
|
(click)="resetDatabase()" i18n>Reset Indexes</button>
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -96,11 +96,11 @@ export class IndexingSettingsComponent extends SettingsComponent<IndexingConfig,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async index() {
|
async index(createThumbnails: boolean) {
|
||||||
this.inProgress = true;
|
this.inProgress = true;
|
||||||
this.error = '';
|
this.error = '';
|
||||||
try {
|
try {
|
||||||
await this._settingsService.index();
|
await this._settingsService.index(createThumbnails);
|
||||||
this.updateProgress();
|
this.updateProgress();
|
||||||
this.notification.success(this.i18n('Folder indexed'), this.i18n('Success'));
|
this.notification.success(this.i18n('Folder indexed'), this.i18n('Success'));
|
||||||
this.inProgress = false;
|
this.inProgress = false;
|
||||||
|
@ -5,6 +5,7 @@ import {AbstractSettingsService} from '../_abstract/abstract.settings.service';
|
|||||||
import {DatabaseType, IndexingConfig} from '../../../../common/config/private/IPrivateConfig';
|
import {DatabaseType, IndexingConfig} from '../../../../common/config/private/IPrivateConfig';
|
||||||
import {IndexingProgressDTO} from '../../../../common/entities/settings/IndexingProgressDTO';
|
import {IndexingProgressDTO} from '../../../../common/entities/settings/IndexingProgressDTO';
|
||||||
import {BehaviorSubject} from 'rxjs';
|
import {BehaviorSubject} from 'rxjs';
|
||||||
|
import {IndexingDTO} from '../../../../common/entities/settings/IndexingDTO';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IndexingSettingsService extends AbstractSettingsService<IndexingConfig> {
|
export class IndexingSettingsService extends AbstractSettingsService<IndexingConfig> {
|
||||||
@ -27,8 +28,8 @@ export class IndexingSettingsService extends AbstractSettingsService<IndexingCon
|
|||||||
return this._settingsService.settings.value.Server.database.type !== DatabaseType.memory;
|
return this._settingsService.settings.value.Server.database.type !== DatabaseType.memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public index() {
|
public index(createThumbnails) {
|
||||||
return this._networkService.putJson('/admin/indexes/job');
|
return this._networkService.postJson('/admin/indexes/job', <IndexingDTO>{createThumbnails: createThumbnails});
|
||||||
}
|
}
|
||||||
|
|
||||||
public cancel() {
|
public cancel() {
|
||||||
|
@ -1304,30 +1304,51 @@
|
|||||||
</context-group>
|
</context-group>
|
||||||
<target>Note: search only works among the indexed directories</target>
|
<target>Note: search only works among the indexed directories</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="32cc8ef8dc6f4f239b7f637ac8adaecc55b8e1d8" datatype="html">
|
<trans-unit id="170f7de02b14690fb9c1999a16926c0044bfd5c1" datatype="html">
|
||||||
<source>Index
|
<source>Index</source>
|
||||||
</source>
|
<context-group purpose="location">
|
||||||
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
|
<context context-type="linenumber">93</context>
|
||||||
|
</context-group>
|
||||||
|
<target>Index</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="b0a0813328867a956835e6fd09e614c2ad1cbc9d" datatype="html">
|
||||||
|
<source>Indexes the folders</source>
|
||||||
<context-group purpose="location">
|
<context-group purpose="location">
|
||||||
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
<context context-type="linenumber">91</context>
|
<context context-type="linenumber">91</context>
|
||||||
</context-group>
|
</context-group>
|
||||||
<target>Index</target>
|
<target>Indexes the folders</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="e7e43ec575247424aa179da55b338fd740e8aa7f" datatype="html">
|
<trans-unit id="7e546cd01e4ee4cb0571fe34ce9c96ad760f31f7" datatype="html">
|
||||||
<source>Cancel
|
<source>Index with Thumbnails</source>
|
||||||
</source>
|
|
||||||
<context-group purpose="location">
|
<context-group purpose="location">
|
||||||
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
<context context-type="linenumber">96</context>
|
<context context-type="linenumber">99</context>
|
||||||
|
</context-group>
|
||||||
|
<target>Index with Thumbnails</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="b7e4e839063c258440e50826493ef7ee3c8c2be3" datatype="html">
|
||||||
|
<source>Indexes the folders and also creates the thumbnails</source>
|
||||||
|
<context-group purpose="location">
|
||||||
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
|
<context context-type="linenumber">95</context>
|
||||||
|
</context-group>
|
||||||
|
<target>Indexes the folders and also creates the thumbnails</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="d7b35c384aecd25a516200d6921836374613dfe7" datatype="html">
|
||||||
|
<source>Cancel</source>
|
||||||
|
<context-group purpose="location">
|
||||||
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
|
<context context-type="linenumber">103</context>
|
||||||
</context-group>
|
</context-group>
|
||||||
<target>Cancel</target>
|
<target>Cancel</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="d68e02eaea0b78b12fceb483b2183a3f5b70d969" datatype="html">
|
<trans-unit id="6ea6ba32bbd2333f0df2a888252f82e42c8bbe7a" datatype="html">
|
||||||
<source>Reset Indexes
|
<source>Reset Indexes</source>
|
||||||
</source>
|
|
||||||
<context-group purpose="location">
|
<context-group purpose="location">
|
||||||
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
<context context-type="linenumber">100</context>
|
<context context-type="linenumber">106</context>
|
||||||
</context-group>
|
</context-group>
|
||||||
<target>Reset Indexes</target>
|
<target>Reset Indexes</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
@ -1304,30 +1304,51 @@
|
|||||||
</context-group>
|
</context-group>
|
||||||
<target>Megjegyzés: csak az indexelt könyvtárak között működik a keresés</target>
|
<target>Megjegyzés: csak az indexelt könyvtárak között működik a keresés</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="32cc8ef8dc6f4f239b7f637ac8adaecc55b8e1d8" datatype="html">
|
<trans-unit id="170f7de02b14690fb9c1999a16926c0044bfd5c1" datatype="html">
|
||||||
<source>Index
|
<source>Index</source>
|
||||||
</source>
|
<context-group purpose="location">
|
||||||
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
|
<context context-type="linenumber">93</context>
|
||||||
|
</context-group>
|
||||||
|
<target>Index</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="b0a0813328867a956835e6fd09e614c2ad1cbc9d" datatype="html">
|
||||||
|
<source>Indexes the folders</source>
|
||||||
<context-group purpose="location">
|
<context-group purpose="location">
|
||||||
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
<context context-type="linenumber">91</context>
|
<context context-type="linenumber">91</context>
|
||||||
</context-group>
|
</context-group>
|
||||||
<target>Index</target>
|
<target>Indexeli a mappákat</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="e7e43ec575247424aa179da55b338fd740e8aa7f" datatype="html">
|
<trans-unit id="7e546cd01e4ee4cb0571fe34ce9c96ad760f31f7" datatype="html">
|
||||||
<source>Cancel
|
<source>Index with Thumbnails</source>
|
||||||
</source>
|
|
||||||
<context-group purpose="location">
|
<context-group purpose="location">
|
||||||
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
<context context-type="linenumber">96</context>
|
<context context-type="linenumber">99</context>
|
||||||
|
</context-group>
|
||||||
|
<target>Index thumbnail-el</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="b7e4e839063c258440e50826493ef7ee3c8c2be3" datatype="html">
|
||||||
|
<source>Indexes the folders and also creates the thumbnails</source>
|
||||||
|
<context-group purpose="location">
|
||||||
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
|
<context context-type="linenumber">95</context>
|
||||||
|
</context-group>
|
||||||
|
<target>Indexeli a mappákat és legenerálja a thumbnaileket is</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="d7b35c384aecd25a516200d6921836374613dfe7" datatype="html">
|
||||||
|
<source>Cancel</source>
|
||||||
|
<context-group purpose="location">
|
||||||
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
|
<context context-type="linenumber">103</context>
|
||||||
</context-group>
|
</context-group>
|
||||||
<target>Mégse</target>
|
<target>Mégse</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="d68e02eaea0b78b12fceb483b2183a3f5b70d969" datatype="html">
|
<trans-unit id="6ea6ba32bbd2333f0df2a888252f82e42c8bbe7a" datatype="html">
|
||||||
<source>Reset Indexes
|
<source>Reset Indexes</source>
|
||||||
</source>
|
|
||||||
<context-group purpose="location">
|
<context-group purpose="location">
|
||||||
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
<context context-type="sourcefile">app/settings/indexing/indexing.settings.component.html</context>
|
||||||
<context context-type="linenumber">100</context>
|
<context context-type="linenumber">106</context>
|
||||||
</context-group>
|
</context-group>
|
||||||
<target>Indexek visszaállítása</target>
|
<target>Indexek visszaállítása</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user