Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
0c43897f
Commit
0c43897f
authored
Apr 04, 2024
by
Danny Liu
Browse files
refac: move generateInitialsImage function to utils
parent
4195af49
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
24 deletions
+25
-24
src/lib/components/chat/Settings/Account.svelte
src/lib/components/chat/Settings/Account.svelte
+1
-23
src/lib/utils/index.ts
src/lib/utils/index.ts
+22
-0
src/routes/auth/+page.svelte
src/routes/auth/+page.svelte
+2
-1
No files found.
src/lib/components/chat/Settings/Account.svelte
View file @
0c43897f
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
import { updateUserProfile } from '$lib/apis/auths';
import { updateUserProfile } from '$lib/apis/auths';
import UpdatePassword from './Account/UpdatePassword.svelte';
import UpdatePassword from './Account/UpdatePassword.svelte';
import { ge
tGravatarUrl
} from '$lib/
apis/
utils';
import { ge
nerateInitialsImage
} from '$lib/utils';
import { copyToClipboard } from '$lib/utils';
import { copyToClipboard } from '$lib/utils';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
...
@@ -19,28 +19,6 @@
...
@@ -19,28 +19,6 @@
let JWTTokenCopied = false;
let JWTTokenCopied = false;
let profileImageInputElement: HTMLInputElement;
let profileImageInputElement: HTMLInputElement;
const generateInitialsImage = (name) => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = 100;
canvas.height = 100;
ctx.fillStyle = '#F39C12';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#FFFFFF';
ctx.font = '40px Helvetica';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
const initials = name
.split(' ')
.map((word) => word[0])
.join('');
ctx.fillText(initials.toUpperCase(), canvas.width / 2, canvas.height / 2);
return canvas.toDataURL();
};
const submitHandler = async () => {
const submitHandler = async () => {
const isInitialsImage: boolean =
const isInitialsImage: boolean =
profileImageUrl === generateInitialsImage($user.name) || profileImageUrl === '';
profileImageUrl === generateInitialsImage($user.name) || profileImageUrl === '';
...
...
src/lib/utils/index.ts
View file @
0c43897f
...
@@ -96,6 +96,28 @@ export const getGravatarURL = (email) => {
...
@@ -96,6 +96,28 @@ export const getGravatarURL = (email) => {
return
`https://www.gravatar.com/avatar/
${
hash
}
`
;
return
`https://www.gravatar.com/avatar/
${
hash
}
`
;
};
};
export
const
generateInitialsImage
=
(
name
)
=>
{
const
canvas
=
document
.
createElement
(
'
canvas
'
);
const
ctx
=
canvas
.
getContext
(
'
2d
'
);
canvas
.
width
=
100
;
canvas
.
height
=
100
;
ctx
.
fillStyle
=
'
#F39C12
'
;
ctx
.
fillRect
(
0
,
0
,
canvas
.
width
,
canvas
.
height
);
ctx
.
fillStyle
=
'
#FFFFFF
'
;
ctx
.
font
=
'
40px Helvetica
'
;
ctx
.
textAlign
=
'
center
'
;
ctx
.
textBaseline
=
'
middle
'
;
const
initials
=
name
.
split
(
'
'
)
.
map
((
word
)
=>
word
[
0
])
.
join
(
''
);
ctx
.
fillText
(
initials
.
toUpperCase
(),
canvas
.
width
/
2
,
canvas
.
height
/
2
);
return
canvas
.
toDataURL
();
};
export
const
copyToClipboard
=
(
text
)
=>
{
export
const
copyToClipboard
=
(
text
)
=>
{
if
(
!
navigator
.
clipboard
)
{
if
(
!
navigator
.
clipboard
)
{
const
textArea
=
document
.
createElement
(
'
textarea
'
);
const
textArea
=
document
.
createElement
(
'
textarea
'
);
...
...
src/routes/auth/+page.svelte
View file @
0c43897f
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
import { WEBUI_NAME, config, user } from '$lib/stores';
import { WEBUI_NAME, config, user } from '$lib/stores';
import { onMount, getContext } from 'svelte';
import { onMount, getContext } from 'svelte';
import { toast } from 'svelte-sonner';
import { toast } from 'svelte-sonner';
import { generateInitialsImage } from '$lib/utils';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
...
@@ -35,7 +36,7 @@
...
@@ -35,7 +36,7 @@
};
};
const signUpHandler = async () => {
const signUpHandler = async () => {
const sessionUser = await userSignUp(name, email, password).catch((error) => {
const sessionUser = await userSignUp(name, email, password
, generateInitialsImage(name)
).catch((error) => {
toast.error(error);
toast.error(error);
return null;
return null;
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment