refac: $user

This commit is contained in:
Timothy Jaeryang Baek
2025-03-31 20:32:12 -07:00
parent 1b7c125f00
commit e0ec2cdeb0
27 changed files with 57 additions and 57 deletions

View File

@@ -1498,7 +1498,7 @@
role: 'system',
content: `${promptTemplate(
params?.system ?? $settings?.system ?? '',
$user.name,
$user?.name,
$settings?.userLocation
? await getAndUpdateUserLocation(localStorage.token).catch((err) => {
console.error(err);
@@ -1572,23 +1572,23 @@
features: {
image_generation:
$config?.features?.enable_image_generation &&
($user.role === 'admin' || $user?.permissions?.features?.image_generation)
($user?.role === 'admin' || $user?.permissions?.features?.image_generation)
? imageGenerationEnabled
: false,
code_interpreter:
$config?.features?.enable_code_interpreter &&
($user.role === 'admin' || $user?.permissions?.features?.code_interpreter)
($user?.role === 'admin' || $user?.permissions?.features?.code_interpreter)
? codeInterpreterEnabled
: false,
web_search:
$config?.features?.enable_web_search &&
($user.role === 'admin' || $user?.permissions?.features?.web_search)
($user?.role === 'admin' || $user?.permissions?.features?.web_search)
? webSearchEnabled || ($settings?.webSearch ?? false) === 'always'
: false
},
variables: {
...getPromptVariables(
$user.name,
$user?.name,
$settings?.userLocation
? await getAndUpdateUserLocation(localStorage.token).catch((err) => {
console.error(err);

View File

@@ -86,7 +86,7 @@
{#if models[selectedModelIdx]?.name}
{models[selectedModelIdx]?.name}
{:else}
{$i18n.t('Hello, {{name}}', { name: $user.name })}
{$i18n.t('Hello, {{name}}', { name: $user?.name })}
{/if}
</div>

View File

@@ -67,7 +67,7 @@
</div>
</Collapsible>
{#if $user.role === 'admin' || $user?.permissions.chat?.controls}
{#if $user?.role === 'admin' || $user?.permissions.chat?.controls}
<hr class="my-2 border-gray-50 dark:border-gray-700/10" />
<Collapsible title={$i18n.t('System Prompt')} open={true} buttonClassName="w-full">

View File

@@ -86,7 +86,7 @@
if (command.content.includes('{{USER_NAME}}')) {
console.log($user);
const name = $user.name || 'User';
const name = $user?.name || 'User';
text = text.replaceAll('{{USER_NAME}}', name);
}

View File

@@ -39,7 +39,7 @@
}
let fileUploadEnabled = true;
$: fileUploadEnabled = $user.role === 'admin' || $user?.permissions?.chat?.file_upload;
$: fileUploadEnabled = $user?.role === 'admin' || $user?.permissions?.chat?.file_upload;
const init = async () => {
if ($_tools === null) {

View File

@@ -920,7 +920,7 @@
{#if message.done}
{#if !readOnly}
{#if $user.role === 'user' ? ($user?.permissions?.chat?.edit ?? true) : true}
{#if $user?.role === 'user' ? ($user?.permissions?.chat?.edit ?? true) : true}
<Tooltip content={$i18n.t('Edit')} placement="bottom">
<button
class="{isLastMessage
@@ -1053,7 +1053,7 @@
</button>
</Tooltip>
{#if $config?.features.enable_image_generation && ($user.role === 'admin' || $user?.permissions?.features?.image_generation) && !readOnly}
{#if $config?.features.enable_image_generation && ($user?.role === 'admin' || $user?.permissions?.features?.image_generation) && !readOnly}
<Tooltip content={$i18n.t('Generate Image')} placement="bottom">
<button
class="{isLastMessage

View File

@@ -45,7 +45,7 @@
label: model.name,
model: model
}))}
showTemporaryChatControl={$user.role === 'user'
showTemporaryChatControl={$user?.role === 'user'
? ($user?.permissions?.chat?.temporary ?? true) &&
!($user?.permissions?.chat?.temporary_enforced ?? false)
: true}

View File

@@ -634,7 +634,7 @@
</div>
{/each}
{#if !(searchValue.trim() in $MODEL_DOWNLOAD_POOL) && searchValue && ollamaVersion && $user.role === 'admin'}
{#if !(searchValue.trim() in $MODEL_DOWNLOAD_POOL) && searchValue && ollamaVersion && $user?.role === 'admin'}
<Tooltip
content={$i18n.t(`Pull "{{searchValue}}" from Ollama.com`, {
searchValue: searchValue

View File

@@ -147,10 +147,10 @@
</button>
</Tooltip>
{#if $user !== undefined}
{#if $user !== undefined && $user !== null}
<UserMenu
className="max-w-[200px]"
role={$user.role}
role={$user?.role}
on:show={(e) => {
if (e.detail === 'archived-chat') {
showArchivedChats.set(true);
@@ -163,7 +163,7 @@
>
<div class=" self-center">
<img
src={$user.profile_image_url}
src={$user?.profile_image_url}
class="size-6 object-cover rounded-full"
alt="User profile"
draggable="false"

View File

@@ -142,7 +142,7 @@
{#if models[selectedModelIdx]?.name}
{models[selectedModelIdx]?.name}
{:else}
{$i18n.t('Hello, {{name}}', { name: $user.name })}
{$i18n.t('Hello, {{name}}', { name: $user?.name })}
{/if}
</div>
</div>

View File

@@ -31,8 +31,8 @@
let profileImageInputElement: HTMLInputElement;
const submitHandler = async () => {
if (name !== $user.name) {
if (profileImageUrl === generateInitialsImage($user.name) || profileImageUrl === '') {
if (name !== $user?.name) {
if (profileImageUrl === generateInitialsImage($user?.name) || profileImageUrl === '') {
profileImageUrl = generateInitialsImage(name);
}
}
@@ -75,8 +75,8 @@
};
onMount(async () => {
name = $user.name;
profileImageUrl = $user.profile_image_url;
name = $user?.name;
profileImageUrl = $user?.profile_image_url;
webhookUrl = $settings?.notifications?.webhook_url ?? '';
APIKey = await getAPIKey(localStorage.token).catch((error) => {
@@ -214,7 +214,7 @@
<button
class=" text-xs text-center text-gray-800 dark:text-gray-400 rounded-full px-4 py-0.5 bg-gray-100 dark:bg-gray-850"
on:click={async () => {
const url = await getGravatarUrl(localStorage.token, $user.email);
const url = await getGravatarUrl(localStorage.token, $user?.email);
profileImageUrl = url;
}}>{$i18n.t('Use Gravatar')}</button

View File

@@ -308,7 +308,7 @@
</div>
</div>
{#if $user.role === 'admin' || $user?.permissions.chat?.controls}
{#if $user?.role === 'admin' || $user?.permissions.chat?.controls}
<hr class="border-gray-100 dark:border-gray-850 my-3" />
<div>

View File

@@ -441,7 +441,7 @@
</div>
</div>
{#if $user.role === 'admin'}
{#if $user?.role === 'admin'}
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs">

View File

@@ -462,7 +462,7 @@
<div class=" self-center">{$i18n.t('Interface')}</div>
</button>
{:else if tabId === 'connections'}
{#if $user.role === 'admin' || ($user.role === 'user' && $config?.features?.enable_direct_connections)}
{#if $user?.role === 'admin' || ($user?.role === 'user' && $config?.features?.enable_direct_connections)}
<button
class="px-0.5 py-1 min-w-fit rounded-lg flex-1 md:flex-none flex text-left transition {selectedTab ===
'connections'
@@ -488,7 +488,7 @@
</button>
{/if}
{:else if tabId === 'tools'}
{#if $user.role === 'admin' || ($user.role === 'user' && $config?.features?.enable_direct_tools)}
{#if $user?.role === 'admin' || ($user?.role === 'user' && $config?.features?.enable_direct_tools)}
<button
class="px-0.5 py-1 min-w-fit rounded-lg flex-1 md:flex-none flex text-left transition {selectedTab ===
'tools'
@@ -636,7 +636,7 @@
<div class=" self-center">{$i18n.t('About')}</div>
</button>
{:else if tabId === 'admin'}
{#if $user.role === 'admin'}
{#if $user?.role === 'admin'}
<button
class="px-0.5 py-1 min-w-fit rounded-lg flex-1 md:flex-none flex text-left transition {selectedTab ===
'admin'