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

Merge pull request #686 from bpatrik/top-pick-sending

Improving e-mail sending #683
This commit is contained in:
Patrik J. Braun 2023-08-01 15:31:23 +02:00 committed by GitHub
commit 5bfd384a21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 34 deletions

View File

@ -154,6 +154,7 @@ export abstract class Job<T extends Record<string, any> = Record<string, any>> i
this.run();
} catch (e) {
Logger.error(LOG_TAG, e);
this.Progress.log('Failed with: ' + (typeof e.toString === 'function') ? e.toString() : JSON.stringify(e));
this.Progress.State = JobProgressStates.failed;
}
});

View File

@ -44,17 +44,11 @@ export class TopPickSendJob extends Job<{
defaultValue: 5,
}, {
id: 'emailTo',
type: 'email',
type: 'string-array',
name: backendTexts.emailTo.name,
description: backendTexts.emailTo.description,
defaultValue: '',
}, {
id: 'emailFrom',
type: 'email',
name: backendTexts.emailFrom.name,
description: backendTexts.emailFrom.description,
defaultValue: 'norelpy@pigallery2.com',
}, {
defaultValue: [],
}, {
id: 'emailSubject',
type: 'string',
name: backendTexts.emailSubject.name,
@ -105,7 +99,6 @@ export class TopPickSendJob extends Job<{
this.Progress.log('Sending emails');
const messenger = new EmailMediaMessenger();
await messenger.sendMedia({
from: this.config.emailFrom,
to: this.config.emailTo,
subject: this.config.emailSubject,
text: this.config.emailText

View File

@ -42,7 +42,6 @@ export class EmailMediaMessenger {
}
public async sendMedia(mailSettings: {
from: string,
to: string,
subject: string,
text: string
@ -60,11 +59,11 @@ export class EmailMediaMessenger {
for (let i = 0; i < media.length; ++i) {
const thPath = await this.getThumbnail(media[i]);
const linkUrl = Utils.concatUrls(Config.Server.publicUrl, '/gallery/', path.join(media[i].directory.path, media[i].directory.name));
const location = (media[0].metadata as PhotoMetadata).positionData?.country ?
(media[0].metadata as PhotoMetadata).positionData?.country :
((media[0].metadata as PhotoMetadata).positionData?.city ?
(media[0].metadata as PhotoMetadata).positionData?.city : '');
const caption = (new Date(media[0].metadata.creationDate)).getFullYear() + (location ? ', ' + location : '');
const location = (media[i].metadata as PhotoMetadata).positionData?.country ?
(media[i].metadata as PhotoMetadata).positionData?.country :
((media[i].metadata as PhotoMetadata).positionData?.city ?
(media[i].metadata as PhotoMetadata).positionData?.city : '');
const caption = (new Date(media[i].metadata.creationDate)).getFullYear() + (location ? ', ' + location : '');
attachments.push({
filename: media[i].name,
path: thPath,
@ -84,7 +83,7 @@ export class EmailMediaMessenger {
}
return await this.transporter.sendMail({
from: mailSettings.from,
from: Config.Messaging.Email.emailFrom,
to: mailSettings.to,
subject: mailSettings.subject,
html: htmlStart + htmlMiddle + htmlEnd,

View File

@ -7,7 +7,6 @@ export const backendTexts = {
sortBy: {name: 50, description: 52},
pickAmount: {name: 60, description: 62},
emailTo: {name: 70, description: 72},
emailFrom: {name: 80, description: 82},
emailSubject: {name: 90, description: 92},
emailText: {name: 100, description: 102}

View File

@ -3,6 +3,7 @@ import {SubConfigClass} from '../../../../node_modules/typeconfig/src/decorators
import {ConfigPriority, TAGS} from '../public/ClientConfig';
import {ConfigProperty} from '../../../../node_modules/typeconfig/src/decorators/property/ConfigPropoerty';
import {ServerConfig} from './PrivateConfig';
declare let $localize: (s: TemplateStringsArray) => string;
if (typeof $localize === 'undefined') {
@ -10,6 +11,7 @@ if (typeof $localize === 'undefined') {
// @ts-ignore
global.$localize = (s) => s;
}
export enum EmailMessagingType {
sendmail = 1,
SMTP = 2,
@ -91,6 +93,16 @@ export class EmailMessagingConfig {
})
type: EmailMessagingType = EmailMessagingType.sendmail;
@ConfigProperty<EmailMessagingType, EmailMessagingConfig>({
tags:
{
name: $localize`Sender email`,
priority: ConfigPriority.advanced,
} as TAGS,
description: $localize`Some services do not allow sending from random e-mail addresses. Set this accordingly.`
})
emailFrom: string = 'noreply@pigallery2.com';
@ConfigProperty({
tags:
{

View File

@ -1,6 +1,6 @@
import {backendText} from '../../BackendTexts';
export type fieldType = 'string' | 'email' | 'number' | 'boolean' | 'number-array' | 'SearchQuery' | 'sort-array';
export type fieldType = 'string' | 'string-array' | 'number' | 'boolean' | 'number-array' | 'SearchQuery' | 'sort-array';
export enum DefaultsJobs {
Indexing = 1,

View File

@ -35,10 +35,6 @@ export class BackendtextService {
return $localize`E-mail to`;
case backendTexts.emailTo.description:
return $localize`E-mail address of the recipient.`;
case backendTexts.emailFrom.name:
return $localize`E-mail From`;
case backendTexts.emailFrom.description:
return $localize`E-mail sender address.`;
case backendTexts.emailSubject.name:
return $localize`Subject`;
case backendTexts.emailSubject.description:

View File

@ -176,12 +176,12 @@
[(ngModel)]="schedule.config[configEntry.id]" required>
</ng-container>
<ng-container *ngSwitchCase="'email'">
<input type="email" class="form-control" [name]="configEntry.id+'_'+i"
<ng-container *ngSwitchCase="'string-array'">
<input type="text" class="form-control"
[name]="configEntry.id+'_'+i"
[id]="configEntry.id+'_'+i"
placeholder="adress@domain.com"
(ngModelChange)="onChange($event)"
[(ngModel)]="schedule.config[configEntry.id]" required>
(ngModelChange)="setEmailArray(schedule.config,configEntry.id,$event); onChange($event);"
[ngModel]="getArray($any(schedule.config),configEntry.id)" required>
</ng-container>
<ng-container *ngSwitchCase="'number'">
@ -196,7 +196,7 @@
[name]="configEntry.id+'_'+i"
[id]="configEntry.id+'_'+i"
(ngModelChange)="setNumberArray(schedule.config,configEntry.id,$event); onChange($event);"
[ngModel]="getNumberArray($any(schedule.config),configEntry.id)" required>
[ngModel]="getArray($any(schedule.config),configEntry.id)" required>
</ng-container>
<app-gallery-search-field

View File

@ -159,6 +159,17 @@ export class WorkflowComponent implements ControlValueAccessor, Validator, OnIni
}
}
setEmailArray(configElement: any, id: string, value: string): void {
value = value.replace(new RegExp(',', 'g'), ';');
value = value.replace(new RegExp(' ', 'g'), ';');
configElement[id] = value
.split(';').filter((i: string) => i != '');
}
getArray(configElement: Record<string, number[]>, id: string): string {
return configElement[id] && Array.isArray(configElement[id]) ? configElement[id].join('; ') : '';
}
setNumberArray(configElement: any, id: string, value: string): void {
value = value.replace(new RegExp(',', 'g'), ';');
value = value.replace(new RegExp(' ', 'g'), ';');
@ -168,9 +179,6 @@ export class WorkflowComponent implements ControlValueAccessor, Validator, OnIni
.filter((i: number) => !isNaN(i) && i > 0);
}
getNumberArray(configElement: Record<string, number[]>, id: string): string {
return configElement[id] ? configElement[id].join('; ') : '';
}
public shouldIdent(curr: JobScheduleDTO, prev: JobScheduleDTO): boolean {
return (
@ -284,7 +292,6 @@ export class WorkflowComponent implements ControlValueAccessor, Validator, OnIni
}
AsSortArray(configElement: string | number | string[] | number[]): SortingMethods[] {
return configElement as SortingMethods[];
}
@ -294,6 +301,6 @@ export class WorkflowComponent implements ControlValueAccessor, Validator, OnIni
}
AddNewSorting(configElement: string | number | string[] | number[]): void {
(configElement as SortingMethods[]).push(SortingMethods.ascDate)
(configElement as SortingMethods[]).push(SortingMethods.ascDate);
}
}