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
7c5f6d71
"...git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "450b9b6aefa7655afdb06f83d1ccb0929f80eebd"
Commit
7c5f6d71
authored
Apr 02, 2024
by
Timothy J. Baek
Browse files
refac
parent
e49e04c5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
36 deletions
+31
-36
src/lib/apis/auths/index.ts
src/lib/apis/auths/index.ts
+5
-5
src/lib/components/chat/Settings/Account.svelte
src/lib/components/chat/Settings/Account.svelte
+25
-19
src/routes/auth/+page.svelte
src/routes/auth/+page.svelte
+1
-12
No files found.
src/lib/apis/auths/index.ts
View file @
7c5f6d71
...
@@ -319,7 +319,7 @@ export const updateJWTExpiresDuration = async (token: string, duration: string)
...
@@ -319,7 +319,7 @@ export const updateJWTExpiresDuration = async (token: string, duration: string)
return
res
;
return
res
;
};
};
export
const
createA
pi
Key
=
async
(
token
:
string
)
=>
{
export
const
createA
PI
Key
=
async
(
token
:
string
)
=>
{
let
error
=
null
;
let
error
=
null
;
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/auths/api_key`
,
{
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/auths/api_key`
,
{
...
@@ -341,10 +341,10 @@ export const createApiKey = async (token: string) => {
...
@@ -341,10 +341,10 @@ export const createApiKey = async (token: string) => {
if
(
error
)
{
if
(
error
)
{
throw
error
;
throw
error
;
}
}
return
res
;
return
res
.
api_key
;
};
};
export
const
getA
pi
Key
=
async
(
token
:
string
)
=>
{
export
const
getA
PI
Key
=
async
(
token
:
string
)
=>
{
let
error
=
null
;
let
error
=
null
;
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/auths/api_key`
,
{
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/auths/api_key`
,
{
...
@@ -366,10 +366,10 @@ export const getApiKey = async (token: string) => {
...
@@ -366,10 +366,10 @@ export const getApiKey = async (token: string) => {
if
(
error
)
{
if
(
error
)
{
throw
error
;
throw
error
;
}
}
return
res
;
return
res
.
api_key
;
};
};
export
const
deleteA
pi
Key
=
async
(
token
:
string
)
=>
{
export
const
deleteA
PI
Key
=
async
(
token
:
string
)
=>
{
let
error
=
null
;
let
error
=
null
;
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/auths/api_key`
,
{
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/auths/api_key`
,
{
...
...
src/lib/components/chat/Settings/Account.svelte
View file @
7c5f6d71
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
import { onMount, getContext } from 'svelte';
import { onMount, getContext } from 'svelte';
import { user } from '$lib/stores';
import { user } from '$lib/stores';
import { updateUserProfile, createA
pi
Key } from '$lib/apis/auths';
import { updateUserProfile, createA
PIKey, getAPI
Key } from '$lib/apis/auths';
import UpdatePassword from './Account/UpdatePassword.svelte';
import UpdatePassword from './Account/UpdatePassword.svelte';
import { getGravatarUrl } from '$lib/apis/utils';
import { getGravatarUrl } from '$lib/apis/utils';
...
@@ -15,11 +15,14 @@
...
@@ -15,11 +15,14 @@
let profileImageUrl = '';
let profileImageUrl = '';
let name = '';
let name = '';
let showJWTToken = false;
let showJWTToken = false;
let JWTTokenCopied = false;
let JWTTokenCopied = false;
let showApiKey = false;
let ApiKeyCopied = false;
let APIKey = '';
let localApiKey = localStorage.apiKey;
let showAPIKey = false;
let APIKeyCopied = false;
let profileImageInputElement: HTMLInputElement;
let profileImageInputElement: HTMLInputElement;
const submitHandler = async () => {
const submitHandler = async () => {
...
@@ -36,20 +39,23 @@
...
@@ -36,20 +39,23 @@
return false;
return false;
};
};
const createApiKeyHandler = async () => {
const createAPIKeyHandler = async () => {
const apiKey = await createApiKey(localStorage.token);
APIKey = await createAPIKey(localStorage.token);
if (apiKey) {
if (APIKey) {
localApiKey = apiKey['api_key'];
localStorage.apiKey = localApiKey;
toast.success($i18n.t('API Key created.'));
toast.success($i18n.t('API Key created.'));
} else {
} else {
toast.error($i18n.t('Failed to create API Key.'));
toast.error($i18n.t('Failed to create API Key.'));
}
}
};
};
onMount(() => {
onMount(
async
() => {
name = $user.name;
name = $user.name;
profileImageUrl = $user.profile_image_url;
profileImageUrl = $user.profile_image_url;
APIKey = await getAPIKey(localStorage.token).catch((error) => {
console.log(error);
return '';
});
});
});
</script>
</script>
...
@@ -293,18 +299,18 @@
...
@@ -293,18 +299,18 @@
<div class="flex w-full">
<div class="flex w-full">
<input
<input
class="w-full rounded-l-lg py-1.5 pl-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
class="w-full rounded-l-lg py-1.5 pl-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
type={showA
pi
Key ? 'text' : 'password'}
type={showA
PI
Key ? 'text' : 'password'}
value={
localApi
Key}
value={
API
Key}
disabled
disabled
/>
/>
<button
<button
class="px-2 transition rounded-r-lg dark:bg-gray-800"
class="px-2 transition rounded-r-lg dark:bg-gray-800"
on:click={() => {
on:click={() => {
showA
pi
Key = !showA
pi
Key;
showA
PI
Key = !showA
PI
Key;
}}
}}
>
>
{#if showA
pi
Key}
{#if showA
PI
Key}
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
viewBox="0 0 16 16"
...
@@ -341,14 +347,14 @@
...
@@ -341,14 +347,14 @@
<button
<button
class="ml-1.5 px-1.5 py-1 hover:bg-gray-800 transition rounded-lg"
class="ml-1.5 px-1.5 py-1 hover:bg-gray-800 transition rounded-lg"
on:click={() => {
on:click={() => {
copyToClipboard(
localApi
Key);
copyToClipboard(
API
Key);
A
pi
KeyCopied = true;
A
PI
KeyCopied = true;
setTimeout(() => {
setTimeout(() => {
A
pi
KeyCopied = false;
A
PI
KeyCopied = false;
}, 2000);
}, 2000);
}}
}}
>
>
{#if A
pi
KeyCopied}
{#if A
PI
KeyCopied}
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
viewBox="0 0 20 20"
...
@@ -385,7 +391,7 @@
...
@@ -385,7 +391,7 @@
<button
<button
class=" px-1.5 py-1 hover:bg-gray-800 transition rounded-lg"
class=" px-1.5 py-1 hover:bg-gray-800 transition rounded-lg"
on:click={() => {
on:click={() => {
createA
pi
KeyHandler();
createA
PI
KeyHandler();
}}
}}
>
>
<svg
<svg
...
...
src/routes/auth/+page.svelte
View file @
7c5f6d71
<script>
<script>
import { goto } from '$app/navigation';
import { goto } from '$app/navigation';
import { userSignIn, userSignUp
, getApiKey
} from '$lib/apis/auths';
import { userSignIn, userSignUp } from '$lib/apis/auths';
import Spinner from '$lib/components/common/Spinner.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
import { WEBUI_NAME, config, user } from '$lib/stores';
import { WEBUI_NAME, config, user } from '$lib/stores';
...
@@ -27,17 +27,6 @@
...
@@ -27,17 +27,6 @@
}
}
};
};
const setApiKey = async (token) => {
const apiKey = await getApiKey(token).catch((error) => {
toast.error(error);
return null;
});
if (apiKey) {
localStorage.apiKey = apiKey['api-key'];
}
};
const signInHandler = async () => {
const signInHandler = async () => {
const sessionUser = await userSignIn(email, password).catch((error) => {
const sessionUser = await userSignIn(email, password).catch((error) => {
toast.error(error);
toast.error(error);
...
...
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