refac
This commit is contained in:
@@ -300,32 +300,6 @@ export const updateUserSettings = async (token: string, settings: object) => {
|
||||
return res;
|
||||
};
|
||||
|
||||
export const getUserById = async (token: string, userId: string) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/users/${userId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
error = err.detail;
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const getUserInfoById = async (token: string, userId: string) => {
|
||||
let error = null;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { LinkPreview } from 'bits-ui';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
import { getUserById } from '$lib/apis/users';
|
||||
import { getUserInfoById } from '$lib/apis/users';
|
||||
|
||||
import UserStatus from './UserStatus.svelte';
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
let user = null;
|
||||
onMount(async () => {
|
||||
if (id) {
|
||||
user = await getUserById(localStorage.token, id).catch((error) => {
|
||||
user = await getUserInfoById(localStorage.token, id).catch((error) => {
|
||||
console.error('Error fetching user by ID:', error);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
import { user as _user } from '$lib/stores';
|
||||
import { getUserById, searchUsers } from '$lib/apis/users';
|
||||
import { getUserInfoById, searchUsers } from '$lib/apis/users';
|
||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
@@ -84,7 +84,7 @@
|
||||
|
||||
if (userIds.length > 0) {
|
||||
userIds.forEach(async (id) => {
|
||||
const res = await getUserById(localStorage.token, id).catch((error) => {
|
||||
const res = await getUserInfoById(localStorage.token, id).catch((error) => {
|
||||
console.error(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
import Messages from '$lib/components/chat/Messages.svelte';
|
||||
|
||||
import { getUserById, getUserSettings } from '$lib/apis/users';
|
||||
import { getUserInfoById, getUserSettings } from '$lib/apis/users';
|
||||
import { getModels } from '$lib/apis';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
||||
@@ -92,7 +92,7 @@
|
||||
});
|
||||
|
||||
if (chat) {
|
||||
user = await getUserById(localStorage.token, chat.user_id).catch((error) => {
|
||||
user = await getUserInfoById(localStorage.token, chat.user_id).catch((error) => {
|
||||
console.error(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user