mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2025-12-31 19:59:31 -05:00
feat(email validation): email requirement and validation + better importer
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
NotificationAgentKey,
|
||||
} from '../../settings';
|
||||
import { BaseAgent, NotificationAgent, NotificationPayload } from './agent';
|
||||
import * as EmailValidator from 'email-validator';
|
||||
|
||||
class EmailAgent
|
||||
extends BaseAgent<NotificationAgentEmail>
|
||||
@@ -215,14 +216,23 @@ class EmailAgent
|
||||
this.getSettings(),
|
||||
payload.notifyUser.settings?.pgpKey
|
||||
);
|
||||
await email.send(
|
||||
this.buildMessage(
|
||||
type,
|
||||
payload,
|
||||
payload.notifyUser.email,
|
||||
payload.notifyUser.displayName
|
||||
)
|
||||
);
|
||||
if (EmailValidator.validate(payload.notifyUser.email)) {
|
||||
await email.send(
|
||||
this.buildMessage(
|
||||
type,
|
||||
payload,
|
||||
payload.notifyUser.email,
|
||||
payload.notifyUser.displayName
|
||||
)
|
||||
);
|
||||
} else {
|
||||
logger.warn('Invalid email address provided for user', {
|
||||
label: 'Notifications',
|
||||
recipient: payload.notifyUser.displayName,
|
||||
type: Notification[type],
|
||||
subject: payload.subject,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('Error sending email notification', {
|
||||
label: 'Notifications',
|
||||
@@ -268,9 +278,18 @@ class EmailAgent
|
||||
this.getSettings(),
|
||||
user.settings?.pgpKey
|
||||
);
|
||||
await email.send(
|
||||
this.buildMessage(type, payload, user.email, user.displayName)
|
||||
);
|
||||
if (EmailValidator.validate(user.email)) {
|
||||
await email.send(
|
||||
this.buildMessage(type, payload, user.email, user.displayName)
|
||||
);
|
||||
} else {
|
||||
logger.warn('Invalid email address provided for user', {
|
||||
label: 'Notifications',
|
||||
recipient: user.displayName,
|
||||
type: Notification[type],
|
||||
subject: payload.subject,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('Error sending email notification', {
|
||||
label: 'Notifications',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router } from 'express';
|
||||
import gravatarUrl from 'gravatar-url';
|
||||
import { findIndex, sortBy } from 'lodash';
|
||||
import { findIndex, forEach, sortBy } from 'lodash';
|
||||
import { getRepository, In, Not } from 'typeorm';
|
||||
import JellyfinAPI from '../../api/jellyfin';
|
||||
import PlexTvAPI from '../../api/plextv';
|
||||
@@ -492,62 +492,44 @@ router.post(
|
||||
);
|
||||
jellyfinClient.setUserId(admin.jellyfinUserId ?? '');
|
||||
|
||||
const jellyfinUsersResponse = await jellyfinClient.getUsers();
|
||||
//const jellyfinUsersResponse = await jellyfinClient.getUsers();
|
||||
const createdUsers: User[] = [];
|
||||
const { hostname, externalHostname } = getSettings().jellyfin;
|
||||
const jellyfinHost =
|
||||
externalHostname && externalHostname.length > 0
|
||||
? externalHostname
|
||||
: hostname;
|
||||
for (const account of jellyfinUsersResponse.users) {
|
||||
if (account.Name) {
|
||||
const user = await userRepository
|
||||
.createQueryBuilder('user')
|
||||
.where('user.jellyfinUserId = :id', { id: account.Id })
|
||||
.orWhere('user.email = :email', {
|
||||
email: account.Name,
|
||||
})
|
||||
.getOne();
|
||||
|
||||
const avatar = account.PrimaryImageTag
|
||||
? `${jellyfinHost}/Users/${account.Id}/Images/Primary/?tag=${account.PrimaryImageTag}&quality=90`
|
||||
: '/os_logo_square.png';
|
||||
forEach(body.jellyfinUserIds, async (jellyfinUserId) => {
|
||||
jellyfinClient.setUserId(jellyfinUserId);
|
||||
const jellyfinUser = await jellyfinClient.getUser();
|
||||
|
||||
if (user) {
|
||||
// Update the user's avatar with their Jellyfin thumbnail, in case it changed
|
||||
user.avatar = avatar;
|
||||
user.email = account.Name;
|
||||
user.jellyfinUsername = account.Name;
|
||||
const user = await userRepository.findOne({
|
||||
select: ['id', 'jellyfinUserId'],
|
||||
where: { jellyfinUserId: jellyfinUserId },
|
||||
});
|
||||
|
||||
// In case the user was previously a local account
|
||||
if (user.userType === UserType.LOCAL) {
|
||||
user.userType = UserType.JELLYFIN;
|
||||
user.jellyfinUserId = account.Id;
|
||||
}
|
||||
await userRepository.save(user);
|
||||
} else if (!body || body.jellyfinUserIds.includes(account.Id)) {
|
||||
// logger.error('CREATED USER', {
|
||||
// label: 'API',
|
||||
// });
|
||||
if (!user) {
|
||||
const newUser = new User({
|
||||
jellyfinUsername: jellyfinUser.Name,
|
||||
jellyfinUserId: jellyfinUser.Id,
|
||||
jellyfinDeviceId: Buffer.from(
|
||||
`BOT_jellyseerr_${jellyfinUser.Name ?? ''}`
|
||||
).toString('base64'),
|
||||
email: jellyfinUser.Name,
|
||||
permissions: settings.main.defaultPermissions,
|
||||
avatar: jellyfinUser.PrimaryImageTag
|
||||
? `${jellyfinHost}/Users/${jellyfinUser.Id}/Images/Primary/?tag=${jellyfinUser.PrimaryImageTag}&quality=90`
|
||||
: '/os_logo_square.png',
|
||||
userType: UserType.JELLYFIN,
|
||||
});
|
||||
|
||||
const newUser = new User({
|
||||
jellyfinUsername: account.Name,
|
||||
jellyfinUserId: account.Id,
|
||||
jellyfinDeviceId: Buffer.from(
|
||||
`BOT_overseerr_${account.Name ?? ''}`
|
||||
).toString('base64'),
|
||||
email: account.Name,
|
||||
permissions: settings.main.defaultPermissions,
|
||||
avatar,
|
||||
userType: UserType.JELLYFIN,
|
||||
});
|
||||
await userRepository.save(newUser);
|
||||
createdUsers.push(newUser);
|
||||
}
|
||||
await userRepository.save(newUser);
|
||||
createdUsers.push(newUser);
|
||||
}
|
||||
}
|
||||
|
||||
return res.status(201).json(User.filterMany(createdUsers));
|
||||
return res.status(201).json(User.filterMany(createdUsers));
|
||||
});
|
||||
} catch (e) {
|
||||
next({ status: 500, message: e.message });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user