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

implementing duplicate backend

This commit is contained in:
Patrik J. Braun 2019-01-17 20:17:17 +01:00
parent 06c6ae3dfb
commit 849a081cba
5 changed files with 50 additions and 4 deletions

View File

@ -42,6 +42,25 @@ export class AdminMWs {
}
}
public static async getDuplicates(req: Request, res: Response, next: NextFunction) {
if (Config.Server.database.type === DatabaseType.memory) {
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Statistic is only available for indexed content'));
}
const galleryManager = <ISQLGalleryManager>ObjectManagerRepository.getInstance().GalleryManager;
try {
req.resultPipe = await galleryManager.getPossibleDuplicates();
return next();
} catch (err) {
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Error while getting duplicates: ' + err.toString(), err));
}
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Error while getting duplicates', err));
}
}
public static async updateDatabaseSettings(req: Request, res: Response, next: NextFunction) {
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {

View File

@ -169,6 +169,22 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
.getCount();
}
public async getPossibleDuplicates() {
const connection = await SQLConnection.getConnection();
const mediaRepository = connection.getRepository(MediaEntity);
const duplicates = await mediaRepository.createQueryBuilder('media')
.innerJoin(query => query.from(MediaEntity, 'innerMedia')
.select(['innerMedia.name as name', 'innerMedia.metadata.fileSize as fileSize', 'count(*)'])
.groupBy('innerMedia.name, innerMedia.metadata.fileSize')
.having('count(*)>1'),
'innerMedia',
'media.name=innerMedia.name AND media.metadata.fileSize = innerMedia.fileSize')
.innerJoinAndSelect('media.directory', 'directory').getMany();
return duplicates;
}
protected async selectParentDir(connection: Connection, directoryName: string, directoryParent: string): Promise<DirectoryEntity> {
const query = connection
.getRepository(DirectoryEntity)
@ -232,5 +248,4 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
}
}
}

View File

@ -1,5 +1,6 @@
import {DirectoryDTO} from '../../../common/entities/DirectoryDTO';
import {IGalleryManager} from '../interfaces/IGalleryManager';
import {MediaEntity} from './enitites/MediaEntity';
export interface ISQLGalleryManager extends IGalleryManager {
listDirectory(relativeDirectoryName: string,
@ -13,4 +14,6 @@ export interface ISQLGalleryManager extends IGalleryManager {
countVideos(): Promise<number>;
countMediaSize(): Promise<number>;
getPossibleDuplicates(): Promise<MediaEntity[]>;
}

View File

@ -166,7 +166,7 @@ export class MetadataLoader {
metadata.creationDate = <number>(iptcData.date_time ? iptcData.date_time.getTime() : metadata.creationDate);
} catch (err) {
Logger.debug(LOG_TAG, 'Error parsing iptc data', fullPath, err);
// Logger.debug(LOG_TAG, 'Error parsing iptc data', fullPath, err);
}
metadata.creationDate = metadata.creationDate || 0;

View File

@ -8,6 +8,7 @@ export class AdminRouter {
public static route(app: Express) {
this.addGetStatistic(app);
this.addGetDuplicates(app);
this.addIndexGallery(app);
this.addSettings(app);
}
@ -20,6 +21,14 @@ export class AdminRouter {
RenderingMWs.renderResult
);
}
private static addGetDuplicates(app: Express) {
app.get('/api/admin/duplicates',
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Admin),
AdminMWs.getDuplicates,
RenderingMWs.renderResult
);
}
private static addIndexGallery(app: Express) {
app.get('/api/admin/indexes/job/progress',