Skip to content

Commit

Permalink
icon fix, localization, squaredBuffer avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
berry-13 committed Dec 2, 2023
1 parent cbe0a33 commit 1421c1c
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 28 deletions.
5 changes: 2 additions & 3 deletions api/server/routes/profilePicture.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
const express = require('express');
const router = express.Router();
const multer = require('multer'); // Aggiunto per gestire i dati FormData
const multer = require('multer');

const uploadProfilePicture = require('~/server/services/ProfilePictureCreate');
const { requireJwtAuth } = require('../middleware/');
const { getUserController } = require('../controllers/AuthController');

// Configura multer per gestire i dati FormData
const upload = multer();

router.get('/', requireJwtAuth, getUserController);

router.post('/', upload.single('input'), async (req, res) => {
try {
const { userId } = req.body;
const input = req.file.buffer; // Utilizza req.file.buffer per ottenere i dati del file
const input = req.file.buffer;

if (!userId) {
throw new Error('User ID is undefined');
Expand Down
16 changes: 13 additions & 3 deletions api/server/services/ProfilePictureCreate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const sharp = require('sharp');
const { storage, ref, uploadBytes, getDownloadURL } = require('./firebase');
const fetch = require('node-fetch');
const fs = require('fs').promises; // Aggiunta per gestire i file
const fs = require('fs').promises;

async function convertToWebP(inputBuffer) {
return sharp(inputBuffer).resize({ width: 150 }).toFormat('webp').toBuffer();
Expand All @@ -27,14 +27,24 @@ async function uploadProfilePicture(userId, input) {
} else if (input instanceof Buffer) {
imageBuffer = input;
} else if (typeof input === 'object' && input instanceof File) {
// Se l'input è un oggetto File, leggi il suo contenuto come buffer
const fileContent = await fs.readFile(input.path);
imageBuffer = Buffer.from(fileContent);
} else {
throw new Error('Invalid input type. Expected URL, Buffer, or File.');
}

const webPBuffer = await convertToWebP(imageBuffer);
const { width, height } = await sharp(imageBuffer).metadata();
const minSize = Math.min(width, height);
const squaredBuffer = await sharp(imageBuffer)
.extract({
left: Math.floor((width - minSize) / 2),
top: Math.floor((height - minSize) / 2),
width: minSize,
height: minSize,
})
.toBuffer();

const webPBuffer = await convertToWebP(squaredBuffer);

await uploadBytes(profilePicRef, webPBuffer);

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Nav/NavLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function NavLinks() {
<Menu.Item as="div">
<NavLink
className="flex w-full cursor-pointer items-center gap-3 rounded-none px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-700"
svg={() => <GearIcon />}
svg={() => <GearIcon className="icon-md" />}
text={localize('com_nav_settings')}
clickHandler={() => setShowSettings(true)}
/>
Expand Down
3 changes: 1 addition & 2 deletions client/src/components/Nav/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Tabs from '@radix-ui/react-tabs';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '~/components/ui';
import { GearIcon, DataIcon } from '~/components/svg';
import { UserIcon } from 'lucide-react';
import { GearIcon, DataIcon, UserIcon } from '~/components/svg';
import { useMediaQuery, useLocalize } from '~/hooks';
import type { TDialogProps } from '~/common';
import { General, Data, Account } from './SettingsTabs';
Expand Down
20 changes: 13 additions & 7 deletions client/src/components/Nav/SettingsTabs/Account/ProfilePicture.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import { FileUp } from 'lucide-react';
import { FileImage } from 'lucide-react';
import { useAuthContext } from '~/hooks';
import { cn } from '~/utils/';
import { useLocalize } from '~/hooks';
Expand Down Expand Up @@ -78,21 +78,21 @@ function ProfilePictureUpload() {
return (
<>
<div className="flex items-center justify-between">
<span>Profile Picture</span>
<span>{localize('com_nav_profile_picture')}</span>
<label
htmlFor={'file-upload-profile-picture'}
className={cn(
'flex h-auto cursor-pointer items-center rounded bg-transparent px-2 py-1 text-xs font-medium font-normal transition-colors hover:bg-slate-200 hover:text-green-700 dark:bg-transparent dark:text-gray-300 dark:hover:bg-gray-800 dark:hover:text-green-500',
statusColor,
)}
>
<FileUp className="mr-1 flex w-[22px] items-center stroke-1" />
<FileImage className="mr-1 flex w-[22px] items-center stroke-1" />
<span>
{status === 'success'
? localize('com_ui_upload_success')
: status === 'invalid'
? localize('com_ui_upload_invalid')
: localize('com_endpoint_import')}
: localize('com_nav_change_picture')}
</span>
<input
id={'file-upload-profile-picture'}
Expand All @@ -112,7 +112,7 @@ function ProfilePictureUpload() {
>
<DialogHeader>
<DialogTitle className="text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">
Preview
{localize('com_ui_preview')}
</DialogTitle>
</DialogHeader>
<div className="flex flex-col items-center justify-center">
Expand All @@ -121,15 +121,21 @@ function ProfilePictureUpload() {
src={previewUrl}
alt="Preview"
className="mb-2 rounded-full"
style={{ maxWidth: '100%', maxHeight: '150px' }}
style={{
maxWidth: '100%',
maxHeight: '150px',
width: '150px',
height: '150px',
objectFit: 'cover',
}}
/>
)}
{showUploadButton && (
<button
className="mt-4 rounded bg-green-500 px-4 py-2 text-white"
onClick={handleUpload}
>
Upload
{localize('com_ui_upload')}
</button>
)}
</div>
Expand Down
16 changes: 11 additions & 5 deletions client/src/components/svg/GearIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React from 'react';

export default function GearIcon() {
interface GearIconProps {
className?: string;
}

const GearIcon: React.FC<GearIconProps> = ({ className = '' }) => {
return (
<svg
width="18"
height="18"
className={className}
width="17"
height="16"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className="icon-md"
>
<path
d="M11.6439 3C10.9352 3 10.2794 3.37508 9.92002 3.98596L9.49644 4.70605C8.96184 5.61487 7.98938 6.17632 6.93501 6.18489L6.09967 6.19168C5.39096 6.19744 4.73823 6.57783 4.38386 7.19161L4.02776 7.80841C3.67339 8.42219 3.67032 9.17767 4.01969 9.7943L4.43151 10.5212C4.95127 11.4386 4.95127 12.5615 4.43151 13.4788L4.01969 14.2057C3.67032 14.8224 3.67339 15.5778 4.02776 16.1916L4.38386 16.8084C4.73823 17.4222 5.39096 17.8026 6.09966 17.8083L6.93502 17.8151C7.98939 17.8237 8.96185 18.3851 9.49645 19.294L9.92002 20.014C10.2794 20.6249 10.9352 21 11.6439 21H12.3561C13.0648 21 13.7206 20.6249 14.08 20.014L14.5035 19.294C15.0381 18.3851 16.0106 17.8237 17.065 17.8151L17.9004 17.8083C18.6091 17.8026 19.2618 17.4222 19.6162 16.8084L19.9723 16.1916C20.3267 15.5778 20.3298 14.8224 19.9804 14.2057L19.5686 13.4788C19.0488 12.5615 19.0488 11.4386 19.5686 10.5212L19.9804 9.7943C20.3298 9.17767 20.3267 8.42219 19.9723 7.80841L19.6162 7.19161C19.2618 6.57783 18.6091 6.19744 17.9004 6.19168L17.065 6.18489C16.0106 6.17632 15.0382 5.61487 14.5036 4.70605L14.08 3.98596C13.7206 3.37508 13.0648 3 12.3561 3H11.6439Z"
Expand All @@ -19,4 +23,6 @@ export default function GearIcon() {
<circle cx="12" cy="12" r="2.5" stroke="currentColor" strokeWidth="2"></circle>
</svg>
);
}
};

export default GearIcon;
12 changes: 5 additions & 7 deletions client/src/components/svg/UserIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import React from 'react';

export default function UserIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
width="18"
height="18"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="lucide lucide-user-round"
className="lucide lucide-user"
>
<circle cx="12" cy="8" r="5" />
<path d="M20 21a8 8 0 0 0-16 0" />
<path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" />
<circle cx="12" cy="7" r="4" />
</svg>
);
}
1 change: 1 addition & 0 deletions client/src/components/svg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ export { default as BingAIMinimalIcon } from './BingAIMinimalIcon';
export { default as PaLMinimalIcon } from './PaLMinimalIcon';
export { default as AnthropicMinimalIcon } from './AnthropicMinimalIcon';
export { default as SendMessageIcon } from './SendMessageIcon';
export { default as UserIcon } from './UserIcon';
4 changes: 4 additions & 0 deletions client/src/localization/languages/Eng.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export default {
com_ui_delete: 'Delete',
com_ui_delete_conversation: 'Delete chat?',
com_ui_delete_conversation_confirm: 'This will delete',
com_ui_preview: 'Preview',
com_ui_upload: 'Upload',
com_auth_error_login:
'Unable to login with the information provided. Please check your credentials and try again.',
com_auth_error_login_rl:
Expand Down Expand Up @@ -230,6 +232,8 @@ export default {
com_endpoint_config_key_google_vertex_api_role:
'Make sure to click \'Create and Continue\' to give at least the \'Vertex AI User\' role. Lastly, create a JSON key to import here.',
com_nav_auto_scroll: 'Auto-scroll to Newest on Open',
com_nav_profile_picture: 'Profile Picture',
com_nav_change_picture: 'Change picture',
com_nav_plugin_store: 'Plugin store',
com_nav_plugin_search: 'Search plugins',
com_nav_plugin_auth_error:
Expand Down
4 changes: 4 additions & 0 deletions client/src/localization/languages/It.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export default {
com_ui_chats: 'chat',
com_ui_delete_conversation: 'Elimina chat?',
com_ui_delete_conversation_confirm: 'Questo eliminerà',
com_ui_preview: 'Anteprima',
com_ui_upload: 'Carica',
com_auth_error_login:
'Impossibile accedere con le informazioni fornite. Controlla le tue credenziali e riprova.',
com_auth_error_login_rl:
Expand Down Expand Up @@ -228,6 +230,8 @@ export default {
com_endpoint_config_key_google_vertex_api_role:
'Assicurati di fare clic su \'Crea e continua\' per dare almeno il ruolo \'Utente Vertex AI\'. Infine, crea una chiave JSON da importare qui.',
com_nav_auto_scroll: 'Scorrimento automatico',
com_nav_profile_picture: 'Immagine del profilo',
com_nav_change_picture: 'Cambia immagine',
com_nav_plugin_store: 'Negozio dei plugin',
com_nav_plugin_search: 'Cerca plugin',
com_nav_plugin_auth_error:
Expand Down

0 comments on commit 1421c1c

Please sign in to comment.