1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Toppick should send unique photos #683

This commit is contained in:
Patrik J. Braun 2023-09-08 19:45:56 +02:00
parent 518fe59921
commit b6b8170187
3 changed files with 16 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import {ObjectManagers} from '../../ObjectManagers';
import {PhotoEntity} from '../../database/enitites/PhotoEntity';
import {EmailMediaMessenger} from '../../mediamessengers/EmailMediaMessenger';
import {MediaPickDTO} from '../../../../common/entities/MediaPickDTO';
import {MediaDTOUtils} from '../../../../common/entities/MediaDTO';
export class TopPickSendJob extends Job<{
@ -83,11 +84,17 @@ export class TopPickSendJob extends Job<{
this.Progress.log('Collecting Photos and videos to Send.');
this.mediaList = [];
for (let i = 0; i < this.config.mediaPick.length; ++i) {
const media = await ObjectManagers.getInstance().SearchManager.getNMedia(this.config.mediaPick[i].searchQuery, this.config.mediaPick[i].sortBy, this.config.mediaPick[i].pick);
const media = await ObjectManagers.getInstance().SearchManager
.getNMedia(this.config.mediaPick[i].searchQuery, this.config.mediaPick[i].sortBy, this.config.mediaPick[i].pick);
this.Progress.log('Find ' + media.length + ' photos and videos from ' + (i + 1) + '. load');
this.mediaList = this.mediaList.concat(media);
}
// make the list unique
this.mediaList = this.mediaList
.filter((value, index, arr) =>
arr.findIndex(m => MediaDTOUtils.equals(m, value)) === index);
this.Progress.Processed++;
// console.log(this.mediaList);
return false;

View File

@ -73,4 +73,10 @@ export const MediaDTOUtils = {
calcAspectRatio: (photo: MediaDTO): number => {
return (photo.metadata.size.width / photo.metadata.size.height) || 1; // NaN should be treated as square photo
},
equals: (a: MediaDTO, b: MediaDTO): boolean => {
return a.directory.path === b.directory.path &&
a.directory.name === b.directory.name &&
a.name === b.name;
}
};

View File

@ -310,7 +310,8 @@ export class WorkflowComponent implements ControlValueAccessor, Validator, OnIni
AddNewMediaPickDTO(configElement: string | number | string[] | number[] | MediaPickDTO[]): void {
(configElement as MediaPickDTO[]).push({
searchQuery: {type: SearchQueryTypes.any_text, text: ''} as TextSearch,
sortBy: [{method: SortByTypes.Rating, ascending: true}],
sortBy: [{method: SortByTypes.Rating, ascending: true},
{method: SortByTypes.PersonCount, ascending: true}],
pick: 5
});
}