mirror of
https://github.com/bpatrik/pigallery2.git
synced 2025-02-01 13:17:55 +02:00
Removing sendMail compatibility.
Our bullseye also does not support it natively. Let's just use SMTP. That makes everything simpler. #683
This commit is contained in:
parent
1edb07dbf9
commit
891c155cce
@ -1,5 +0,0 @@
|
||||
/**
|
||||
* Keeps the environment context
|
||||
* Only use it in the Config constructor
|
||||
*/
|
||||
export const ServerEnvironment: { sendMailAvailable?: boolean } = {};
|
@ -26,9 +26,6 @@ import {
|
||||
import {SearchQueryParser} from '../../../common/SearchQueryParser';
|
||||
import {SearchQueryTypes, TextSearch,} from '../../../common/entities/SearchQueryDTO';
|
||||
import {Utils} from '../../../common/Utils';
|
||||
import {createTransport} from 'nodemailer';
|
||||
import {EmailMessagingType, MessagingConfig} from '../../../common/config/private/MessagingConfig';
|
||||
import {ServerEnvironment} from '../../Environment';
|
||||
|
||||
const LOG_TAG = '[ConfigDiagnostics]';
|
||||
|
||||
@ -82,13 +79,6 @@ export class ConfigDiagnostics {
|
||||
}
|
||||
}
|
||||
|
||||
private static async testEmailMessagingConfig(Messaging: MessagingConfig, config: PrivateConfigClass): Promise<void> {
|
||||
Logger.debug(LOG_TAG, 'Testing EmailMessaging config');
|
||||
|
||||
if (Messaging.Email.type === EmailMessagingType.sendmail && ServerEnvironment.sendMailAvailable === false) {
|
||||
throw new Error('sendmail e-mail sending method is not supported as the sendmail application cannot be found in the OS.');
|
||||
}
|
||||
}
|
||||
|
||||
static testVideoConfig(videoConfig: ServerVideoConfig,
|
||||
config: PrivateConfigClass): Promise<void> {
|
||||
@ -296,26 +286,9 @@ export class ConfigDiagnostics {
|
||||
await ConfigDiagnostics.testSharingConfig(config.Sharing, config);
|
||||
await ConfigDiagnostics.testRandomPhotoConfig(config.Sharing, config);
|
||||
await ConfigDiagnostics.testMapConfig(config.Map);
|
||||
await ConfigDiagnostics.testEmailMessagingConfig(config.Messaging, config);
|
||||
|
||||
}
|
||||
|
||||
static async checkAndSetEnvironment(): Promise<void> {
|
||||
Logger.debug(LOG_TAG, 'Checking sendmail availability');
|
||||
const transporter = createTransport({
|
||||
sendmail: true,
|
||||
});
|
||||
try {
|
||||
ServerEnvironment.sendMailAvailable = await transporter.verify();
|
||||
} catch (e) {
|
||||
ServerEnvironment.sendMailAvailable = false;
|
||||
}
|
||||
Config.Environment.sendMailAvailable = ServerEnvironment.sendMailAvailable;
|
||||
if (!ServerEnvironment.sendMailAvailable) {
|
||||
Config.Messaging.Email.type = EmailMessagingType.SMTP;
|
||||
Logger.info(LOG_TAG, 'Sendmail is not available on the OS. You will need to use an SMTP server if you wish the app to send mails.');
|
||||
}
|
||||
}
|
||||
|
||||
static async runDiagnostics(): Promise<void> {
|
||||
|
||||
@ -323,21 +296,6 @@ export class ConfigDiagnostics {
|
||||
NotificationManager.warning('You are running the application with NODE_ENV=debug. This exposes a lot of debug information that can be a security vulnerability. Set NODE_ENV=production, when you finished debugging.');
|
||||
}
|
||||
|
||||
try {
|
||||
await ConfigDiagnostics.checkAndSetEnvironment();
|
||||
} catch (ex) {
|
||||
const err: Error = ex;
|
||||
NotificationManager.error(
|
||||
'Error during checking environment',
|
||||
err.toString()
|
||||
);
|
||||
Logger.error(
|
||||
LOG_TAG,
|
||||
'Error during checking environment',
|
||||
err.toString()
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
await ConfigDiagnostics.testDatabase(Config.Database);
|
||||
@ -570,21 +528,6 @@ export class ConfigDiagnostics {
|
||||
);
|
||||
Config.Map.mapProvider = MapProviders.OpenStreetMap;
|
||||
}
|
||||
try {
|
||||
await ConfigDiagnostics.testEmailMessagingConfig(Config.Messaging, Config);
|
||||
} catch (ex) {
|
||||
const err: Error = ex;
|
||||
NotificationManager.warning(
|
||||
'Setting to SMTP method.',
|
||||
err.toString()
|
||||
);
|
||||
Logger.warn(
|
||||
LOG_TAG,
|
||||
'Setting to SMTP method.',
|
||||
err.toString()
|
||||
);
|
||||
Config.Messaging.Email.type = EmailMessagingType.SMTP;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import {createTransport, Transporter} from 'nodemailer';
|
||||
import {MediaDTO, MediaDTOUtils} from '../../../common/entities/MediaDTO';
|
||||
import {Config} from '../../../common/config/private/Config';
|
||||
import {EmailMessagingType} from '../../../common/config/private/MessagingConfig';
|
||||
import {PhotoProcessing} from '../fileprocessing/PhotoProcessing';
|
||||
import {ThumbnailSourceType} from '../threading/PhotoWorker';
|
||||
import {ProjectPath} from '../../ProjectPath';
|
||||
@ -14,11 +13,6 @@ export class EmailMediaMessenger {
|
||||
transporter: Transporter;
|
||||
|
||||
constructor() {
|
||||
if (Config.Messaging.Email.type === EmailMessagingType.sendmail) {
|
||||
this.transporter = createTransport({
|
||||
sendmail: true
|
||||
});
|
||||
} else {
|
||||
this.transporter = createTransport({
|
||||
host: Config.Messaging.Email.smtp.host,
|
||||
port: Config.Messaging.Email.smtp.port,
|
||||
@ -31,8 +25,6 @@ export class EmailMediaMessenger {
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async getThumbnail(m: MediaDTO) {
|
||||
return await PhotoProcessing.generateThumbnail(
|
||||
path.join(ProjectPath.ImageFolder, m.directory.path, m.directory.name, m.name),
|
||||
|
@ -6,8 +6,6 @@ import {ConfigClass, ConfigClassBuilder} from 'typeconfig/node';
|
||||
import {IConfigClass} from 'typeconfig/common';
|
||||
import {PasswordHelper} from '../../../backend/model/PasswordHelper';
|
||||
import {TAGS} from '../public/ClientConfig';
|
||||
import {ServerEnvironment} from '../../../backend/Environment';
|
||||
import {EmailMessagingType} from './MessagingConfig';
|
||||
|
||||
declare const process: any;
|
||||
|
||||
@ -85,12 +83,6 @@ export class PrivateConfigClass extends ServerConfig {
|
||||
require('../../../../package.json').buildCommitHash;
|
||||
this.Environment.upTime = upTime;
|
||||
this.Environment.isDocker = !!process.env.PI_DOCKER;
|
||||
if (typeof ServerEnvironment.sendMailAvailable !== 'undefined') {
|
||||
this.Environment.sendMailAvailable = ServerEnvironment.sendMailAvailable;
|
||||
if (!this.Environment.sendMailAvailable) { //onNewValue is not yet available as a callback
|
||||
this.Messaging.Email.type = EmailMessagingType.SMTP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async original(): Promise<PrivateConfigClass & IConfigClass> {
|
||||
|
@ -12,10 +12,6 @@ if (typeof $localize === 'undefined') {
|
||||
global.$localize = (s) => s;
|
||||
}
|
||||
|
||||
export enum EmailMessagingType {
|
||||
sendmail = 1,
|
||||
SMTP = 2,
|
||||
}
|
||||
|
||||
@SubConfigClass<TAGS>({softReadonly: true})
|
||||
export class EmailSMTPMessagingConfig {
|
||||
@ -81,19 +77,8 @@ export class EmailSMTPMessagingConfig {
|
||||
|
||||
@SubConfigClass<TAGS>({softReadonly: true})
|
||||
export class EmailMessagingConfig {
|
||||
@ConfigProperty<EmailMessagingType, EmailMessagingConfig>({
|
||||
type: EmailMessagingType,
|
||||
tags:
|
||||
{
|
||||
name: $localize`Sending method`,
|
||||
priority: ConfigPriority.advanced,
|
||||
uiDisabled: (sc: EmailMessagingConfig, c: ServerConfig) => !c.Environment.sendMailAvailable
|
||||
} as TAGS,
|
||||
description: $localize`Sendmail uses the built in unix binary if available. STMP connects to any STMP server of your choice.`
|
||||
})
|
||||
type: EmailMessagingType = EmailMessagingType.sendmail;
|
||||
|
||||
@ConfigProperty<EmailMessagingType, EmailMessagingConfig>({
|
||||
@ConfigProperty({
|
||||
tags:
|
||||
{
|
||||
name: $localize`Sender email`,
|
||||
@ -107,7 +92,6 @@ export class EmailMessagingConfig {
|
||||
tags:
|
||||
{
|
||||
name: $localize`SMTP`,
|
||||
relevant: (c: any) => c.type === EmailMessagingType.SMTP,
|
||||
}
|
||||
})
|
||||
smtp?: EmailSMTPMessagingConfig = new EmailSMTPMessagingConfig();
|
||||
|
@ -30,8 +30,8 @@ import {DefaultsJobs} from '../../entities/job/JobDTO';
|
||||
import {SearchQueryDTO, SearchQueryTypes, TextSearch,} from '../../entities/SearchQueryDTO';
|
||||
import {SortingMethods} from '../../entities/SortingMethods';
|
||||
import {UserRoles} from '../../entities/UserDTO';
|
||||
import {EmailMessagingType, MessagingConfig} from './MessagingConfig';
|
||||
import {MediaPickDTO} from '../../entities/MediaPickDTO';
|
||||
import {MessagingConfig} from './MessagingConfig';
|
||||
|
||||
declare let $localize: (s: TemplateStringsArray) => string;
|
||||
|
||||
@ -1053,16 +1053,6 @@ export class ServerEnvironmentConfig {
|
||||
buildCommitHash: string | undefined;
|
||||
@ConfigProperty({volatile: true})
|
||||
isDocker: boolean | undefined;
|
||||
@ConfigProperty<boolean, ServerConfig, TAGS>({
|
||||
volatile: true,
|
||||
onNewValue: (value, config) => {
|
||||
if (value === false) {
|
||||
config.Messaging.Email.type = EmailMessagingType.SMTP;
|
||||
}
|
||||
},
|
||||
description: 'App updates on start-up if sendmail binary is available'
|
||||
})
|
||||
sendMailAvailable: boolean | undefined;
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,9 +45,7 @@ describe('SettingsRouter', () => {
|
||||
result.body.should.be.a('object');
|
||||
should.equal(result.body.error, null);
|
||||
(result.body.result as ServerConfig).Environment.upTime = null;
|
||||
(result.body.result as ServerConfig).Environment.sendMailAvailable = null;
|
||||
originalSettings.Environment.upTime = null;
|
||||
originalSettings.Environment.sendMailAvailable = null;
|
||||
result.body.result.should.deep.equal(JSON.parse(JSON.stringify(originalSettings.toJSON({
|
||||
attachState: true,
|
||||
attachVolatile: true,
|
||||
|
@ -7,8 +7,6 @@ import {ServerUserConfig} from '../../../../../src/common/config/private/Private
|
||||
import {Config} from '../../../../../src/common/config/private/Config';
|
||||
import {UserRoles} from '../../../../../src/common/entities/UserDTO';
|
||||
import {ConfigClassBuilder} from '../../../../../node_modules/typeconfig/node';
|
||||
import {ServerEnvironment} from '../../../../../src/backend/Environment';
|
||||
import {EmailMessagingType} from '../../../../../src/common/config/private/MessagingConfig';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
@ -26,9 +24,6 @@ describe('Settings middleware', () => {
|
||||
});
|
||||
|
||||
it('should save empty enforced users settings', (done: (err?: any) => void) => {
|
||||
ServerEnvironment.sendMailAvailable = false;
|
||||
Config.Environment.sendMailAvailable = false;
|
||||
Config.Messaging.Email.type = EmailMessagingType.SMTP;
|
||||
const req: any = {
|
||||
session: {},
|
||||
sessionOptions: {},
|
||||
@ -56,9 +51,6 @@ describe('Settings middleware', () => {
|
||||
});
|
||||
it('should save enforced users settings', (done: (err?: any) => void) => {
|
||||
|
||||
ServerEnvironment.sendMailAvailable = false;
|
||||
Config.Environment.sendMailAvailable = false;
|
||||
Config.Messaging.Email.type = EmailMessagingType.SMTP;
|
||||
const req: any = {
|
||||
session: {},
|
||||
sessionOptions: {},
|
||||
|
Loading…
x
Reference in New Issue
Block a user