From d2f651081ac9ab372f82be2f271cb16cbad05a9f Mon Sep 17 00:00:00 2001 From: JoaquinOlivero Date: Mon, 26 Aug 2024 18:58:02 +0000 Subject: [PATCH] refactor: checks if the default avatar is cached to avoid creating duplicates for different users --- server/routes/auth.ts | 33 ++++- server/routes/avatarproxy.ts | 10 +- server/routes/user/index.ts | 16 +- src/components/IssueDetails/index.tsx | 140 +++++++++--------- src/components/ManageSlideOver/index.tsx | 9 +- .../UserList/JellyfinImportModal.tsx | 31 ++-- src/components/UserList/index.tsx | 50 ++++--- 7 files changed, 173 insertions(+), 116 deletions(-) diff --git a/server/routes/auth.ts b/server/routes/auth.ts index 395c987d..14ede058 100644 --- a/server/routes/auth.ts +++ b/server/routes/auth.ts @@ -343,6 +343,14 @@ authRoutes.post('/jellyfin', async (req, res, next) => { }), userType: UserType.EMBY, }); + + if ( + user.avatar.includes('https://gravatar.com') && + user.avatar.includes('default=mm&size=200') + ) { + user.avatar = 'https://gravatar.com/avatar/?default=mm&size=200'; + } + break; case MediaServerType.JELLYFIN: settings.main.mediaServerType = MediaServerType.JELLYFIN; @@ -361,6 +369,14 @@ authRoutes.post('/jellyfin', async (req, res, next) => { }), userType: UserType.JELLYFIN, }); + + if ( + user.avatar.includes('https://gravatar.com') && + user.avatar.includes('default=mm&size=200') + ) { + user.avatar = 'https://gravatar.com/avatar/?default=mm&size=200'; + } + break; default: throw new Error('select_server_type'); @@ -415,15 +431,23 @@ authRoutes.post('/jellyfin', async (req, res, next) => { } user.avatar = avatar; } else { - const avatar = gravatarUrl(user.email || account.User.Name, { + let avatar = gravatarUrl(user.email || account.User.Name, { default: 'mm', size: 200, }); + if ( + avatar.includes('https://gravatar.com') && + avatar.includes('default=mm&size=200') + ) { + avatar = 'https://gravatar.com/avatar/?default=mm&size=200'; + } + if (avatar !== user.avatar) { const avatarProxy = new ImageProxy('avatar', ''); avatarProxy.clearCachedImage(user.avatar); } + user.avatar = avatar; } user.jellyfinUsername = account.User.Name; @@ -474,6 +498,13 @@ authRoutes.post('/jellyfin', async (req, res, next) => { ? UserType.JELLYFIN : UserType.EMBY, }); + + if ( + user.avatar.includes('https://gravatar.com') && + user.avatar.includes('default=mm&size=200') + ) { + user.avatar = 'https://gravatar.com/avatar/?default=mm&size=200'; + } //initialize Jellyfin/Emby users with local login const passedExplicitPassword = body.password && body.password.length > 0; if (passedExplicitPassword) { diff --git a/server/routes/avatarproxy.ts b/server/routes/avatarproxy.ts index 746bc51d..e6f5c2ee 100644 --- a/server/routes/avatarproxy.ts +++ b/server/routes/avatarproxy.ts @@ -7,8 +7,16 @@ const router = Router(); const avatarImageProxy = new ImageProxy('avatar', ''); // Proxy avatar images router.get('/*', async (req, res) => { - const imagePath = req.url.startsWith('/') ? req.url.slice(1) : req.url; + let imagePath = req.url.startsWith('/') ? req.url.slice(1) : req.url; + try { + if ( + imagePath.includes('https://gravatar.com') && + imagePath.includes('default=mm&size=200') + ) { + imagePath = 'https://gravatar.com/avatar/?default=mm&size=200'; + } + const imageData = await avatarImageProxy.getImage(imagePath); res.writeHead(200, { diff --git a/server/routes/user/index.ts b/server/routes/user/index.ts index f8a0d41a..3296aff7 100644 --- a/server/routes/user/index.ts +++ b/server/routes/user/index.ts @@ -122,7 +122,14 @@ router.post( } const passedExplicitPassword = body.password && body.password.length > 0; - const avatar = gravatarUrl(email, { default: 'mm', size: 200 }); + let avatar = gravatarUrl(email, { default: 'mm', size: 200 }); + + if ( + avatar.includes('https://gravatar.com') && + avatar.includes('default=mm&size=200') + ) { + avatar = 'https://gravatar.com/avatar/?default=mm&size=200'; + } if ( !passedExplicitPassword && @@ -557,6 +564,13 @@ router.post( : UserType.EMBY, }); + if ( + newUser.avatar.includes('https://gravatar.com') && + newUser.avatar.includes('default=mm&size=200') + ) { + newUser.avatar = 'https://gravatar.com/avatar/?default=mm&size=200'; + } + await userRepository.save(newUser); createdUsers.push(newUser); } diff --git a/src/components/IssueDetails/index.tsx b/src/components/IssueDetails/index.tsx index b16af8e9..c011eb04 100644 --- a/src/components/IssueDetails/index.tsx +++ b/src/components/IssueDetails/index.tsx @@ -28,7 +28,6 @@ import type Issue from '@server/entity/Issue'; import type { MovieDetails } from '@server/models/Movie'; import type { TvDetails } from '@server/models/Tv'; import { Field, Form, Formik } from 'formik'; -import Image from 'next/image'; import Link from 'next/link'; import { useRouter } from 'next/router'; import { useState } from 'react'; @@ -264,8 +263,9 @@ const IssueDetails = () => {

{title} @@ -302,7 +302,7 @@ const IssueDetails = () => { { { {settings.currentSettings.mediaServerType === - MediaServerType.EMBY + MediaServerType.EMBY ? intl.formatMessage(messages.playonplex, { - mediaServerName: 'Emby', - }) + mediaServerName: 'Emby', + }) : settings.currentSettings.mediaServerType === MediaServerType.PLEX - ? intl.formatMessage(messages.playonplex, { + ? intl.formatMessage(messages.playonplex, { mediaServerName: 'Plex', }) - : intl.formatMessage(messages.playonplex, { + : intl.formatMessage(messages.playonplex, { mediaServerName: 'Jellyfin', })} @@ -436,16 +436,16 @@ const IssueDetails = () => { {settings.currentSettings.mediaServerType === - MediaServerType.EMBY + MediaServerType.EMBY ? intl.formatMessage(messages.play4konplex, { - mediaServerName: 'Emby', - }) + mediaServerName: 'Emby', + }) : settings.currentSettings.mediaServerType === MediaServerType.PLEX - ? intl.formatMessage(messages.play4konplex, { + ? intl.formatMessage(messages.play4konplex, { mediaServerName: 'Plex', }) - : intl.formatMessage(messages.play4konplex, { + : intl.formatMessage(messages.play4konplex, { mediaServerName: 'Jellyfin', })} @@ -530,52 +530,52 @@ const IssueDetails = () => {
{(hasPermission(Permission.MANAGE_ISSUES) || belongsToUser) && ( - <> - {issueData.status === IssueStatus.OPEN ? ( - - ) : ( - + ) : ( + - )} - - )} + if (values.message) { + handleSubmit(); + } + }} + > + + + {intl.formatMessage( + values.message + ? messages.reopenissueandcomment + : messages.reopenissue + )} + + + )} + + )}