mirror of
https://github.com/open-webui/open-webui
synced 2025-04-28 02:01:41 +00:00
add FORCED_IMAGE_COMPRESSION_WIDTH and _HEIGHT to override (and hide) corresponding user settings for image compression
This commit is contained in:
parent
6ac153c989
commit
6f6c9b0e1b
backend/open_webui
src/lib
@ -18,6 +18,8 @@ from open_webui.env import (
|
|||||||
DATA_DIR,
|
DATA_DIR,
|
||||||
DATABASE_URL,
|
DATABASE_URL,
|
||||||
ENV,
|
ENV,
|
||||||
|
FORCED_IMAGE_COMPRESSION_WIDTH,
|
||||||
|
FORCED_IMAGE_COMPRESSION_HEIGHT,
|
||||||
REDIS_URL,
|
REDIS_URL,
|
||||||
REDIS_SENTINEL_HOSTS,
|
REDIS_SENTINEL_HOSTS,
|
||||||
REDIS_SENTINEL_PORT,
|
REDIS_SENTINEL_PORT,
|
||||||
|
@ -460,3 +460,9 @@ OTEL_TRACES_SAMPLER = os.environ.get(
|
|||||||
|
|
||||||
PIP_OPTIONS = os.getenv("PIP_OPTIONS", "").split()
|
PIP_OPTIONS = os.getenv("PIP_OPTIONS", "").split()
|
||||||
PIP_PACKAGE_INDEX_OPTIONS = os.getenv("PIP_PACKAGE_INDEX_OPTIONS", "").split()
|
PIP_PACKAGE_INDEX_OPTIONS = os.getenv("PIP_PACKAGE_INDEX_OPTIONS", "").split()
|
||||||
|
|
||||||
|
####################################
|
||||||
|
# FORCED IMAGE COMPRESSION
|
||||||
|
####################################
|
||||||
|
FORCED_IMAGE_COMPRESSION_WIDTH = os.environ.get("FORCED_IMAGE_COMPRESSION_WIDTH", "")
|
||||||
|
FORCED_IMAGE_COMPRESSION_HEIGHT = os.environ.get("FORCED_IMAGE_COMPRESSION_HEIGHT", "")
|
||||||
|
@ -293,6 +293,8 @@ from open_webui.config import (
|
|||||||
DEFAULT_LOCALE,
|
DEFAULT_LOCALE,
|
||||||
OAUTH_PROVIDERS,
|
OAUTH_PROVIDERS,
|
||||||
WEBUI_URL,
|
WEBUI_URL,
|
||||||
|
FORCED_IMAGE_COMPRESSION_WIDTH,
|
||||||
|
FORCED_IMAGE_COMPRESSION_HEIGHT,
|
||||||
# Admin
|
# Admin
|
||||||
ENABLE_ADMIN_CHAT_ACCESS,
|
ENABLE_ADMIN_CHAT_ACCESS,
|
||||||
ENABLE_ADMIN_EXPORT,
|
ENABLE_ADMIN_EXPORT,
|
||||||
@ -1265,6 +1267,10 @@ async def get_app_config(request: Request):
|
|||||||
"max_size": app.state.config.FILE_MAX_SIZE,
|
"max_size": app.state.config.FILE_MAX_SIZE,
|
||||||
"max_count": app.state.config.FILE_MAX_COUNT,
|
"max_count": app.state.config.FILE_MAX_COUNT,
|
||||||
},
|
},
|
||||||
|
"forced_image_compression_size": {
|
||||||
|
"width": FORCED_IMAGE_COMPRESSION_WIDTH,
|
||||||
|
"height": FORCED_IMAGE_COMPRESSION_HEIGHT,
|
||||||
|
},
|
||||||
"permissions": {**app.state.config.USER_PERMISSIONS},
|
"permissions": {**app.state.config.USER_PERMISSIONS},
|
||||||
"google_drive": {
|
"google_drive": {
|
||||||
"client_id": GOOGLE_DRIVE_CLIENT_ID.value,
|
"client_id": GOOGLE_DRIVE_CLIENT_ID.value,
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
const forcedImageCompressionWidth = $config?.forced_image_compression_size.width ?? null;
|
||||||
|
const forcedImageCompressionHeight = $config?.forced_image_compression_size.height ?? null;
|
||||||
|
const forcedImageCompression = Boolean(forcedImageCompressionWidth) || Boolean(forcedImageCompressionHeight);
|
||||||
|
|
||||||
import { config, mobile, settings, socket } from '$lib/stores';
|
import { config, mobile, settings, socket } from '$lib/stores';
|
||||||
import { blobToFile, compressImage } from '$lib/utils';
|
import { blobToFile, compressImage } from '$lib/utils';
|
||||||
|
|
||||||
@ -111,7 +115,10 @@
|
|||||||
reader.onload = async (event) => {
|
reader.onload = async (event) => {
|
||||||
let imageUrl = event.target.result;
|
let imageUrl = event.target.result;
|
||||||
|
|
||||||
if ($settings?.imageCompression ?? false) {
|
if (forcedImageCompression) {
|
||||||
|
imageUrl = await compressImage(imageUrl, forcedImageCompressionWidth, forcedImageCompressionHeight);
|
||||||
|
}
|
||||||
|
else if ($settings?.imageCompression ?? false) {
|
||||||
const width = $settings?.imageCompressionSize?.width ?? null;
|
const width = $settings?.imageCompressionSize?.width ?? null;
|
||||||
const height = $settings?.imageCompressionSize?.height ?? null;
|
const height = $settings?.imageCompressionSize?.height ?? null;
|
||||||
|
|
||||||
|
@ -50,6 +50,10 @@
|
|||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
const forcedImageCompressionWidth = $config?.forced_image_compression_size.width ?? null;
|
||||||
|
const forcedImageCompressionHeight = $config?.forced_image_compression_size.height ?? null;
|
||||||
|
const forcedImageCompression = Boolean(forcedImageCompressionWidth) || Boolean(forcedImageCompressionHeight);
|
||||||
|
|
||||||
export let transparentBackground = false;
|
export let transparentBackground = false;
|
||||||
|
|
||||||
export let onChange: Function = () => {};
|
export let onChange: Function = () => {};
|
||||||
@ -252,7 +256,10 @@
|
|||||||
reader.onload = async (event) => {
|
reader.onload = async (event) => {
|
||||||
let imageUrl = event.target.result;
|
let imageUrl = event.target.result;
|
||||||
|
|
||||||
if ($settings?.imageCompression ?? false) {
|
if (forcedImageCompression) {
|
||||||
|
imageUrl = await compressImage(imageUrl, forcedImageCompressionWidth, forcedImageCompressionHeight);
|
||||||
|
}
|
||||||
|
else if ($settings?.imageCompression ?? false) {
|
||||||
const width = $settings?.imageCompressionSize?.width ?? null;
|
const width = $settings?.imageCompressionSize?.width ?? null;
|
||||||
const height = $settings?.imageCompressionSize?.height ?? null;
|
const height = $settings?.imageCompressionSize?.height ?? null;
|
||||||
|
|
||||||
|
@ -50,6 +50,9 @@
|
|||||||
width: '',
|
width: '',
|
||||||
height: ''
|
height: ''
|
||||||
};
|
};
|
||||||
|
const forcedImageCompressionWidth = $config?.forced_image_compression_size.width ?? null;
|
||||||
|
const forcedImageCompressionHeight = $config?.forced_image_compression_size.height ?? null;
|
||||||
|
const forcedImageCompression = Boolean(forcedImageCompressionWidth) || Boolean(forcedImageCompressionHeight);
|
||||||
|
|
||||||
// Admin - Show Update Available Toast
|
// Admin - Show Update Available Toast
|
||||||
let showUpdateToast = true;
|
let showUpdateToast = true;
|
||||||
@ -860,23 +863,29 @@
|
|||||||
<div class=" py-0.5 flex w-full justify-between">
|
<div class=" py-0.5 flex w-full justify-between">
|
||||||
<div class=" self-center text-xs">{$i18n.t('Image Compression')}</div>
|
<div class=" self-center text-xs">{$i18n.t('Image Compression')}</div>
|
||||||
|
|
||||||
<button
|
{#if forcedImageCompression}
|
||||||
class="p-1 px-3 text-xs flex rounded-sm transition"
|
<div class="p-1 px-3 text-xs flex rounded-sm transition">
|
||||||
on:click={() => {
|
|
||||||
toggleImageCompression();
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
{#if imageCompression === true}
|
|
||||||
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
||||||
{:else}
|
</div>
|
||||||
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
{:else}
|
||||||
{/if}
|
<button
|
||||||
</button>
|
class="p-1 px-3 text-xs flex rounded-sm transition"
|
||||||
|
on:click={() => {
|
||||||
|
toggleImageCompression();
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{#if imageCompression || forcedImageCompression}
|
||||||
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
||||||
|
{:else}
|
||||||
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if imageCompression}
|
{#if imageCompression && !forcedImageCompression}
|
||||||
<div>
|
<div>
|
||||||
<div class=" py-0.5 flex w-full justify-between text-xs">
|
<div class=" py-0.5 flex w-full justify-between text-xs">
|
||||||
<div class=" self-center text-xs">{$i18n.t('Image Max Compression Size')}</div>
|
<div class=" self-center text-xs">{$i18n.t('Image Max Compression Size')}</div>
|
||||||
|
@ -199,6 +199,10 @@ type Config = {
|
|||||||
default_locale: string;
|
default_locale: string;
|
||||||
default_models: string;
|
default_models: string;
|
||||||
default_prompt_suggestions: PromptSuggestion[];
|
default_prompt_suggestions: PromptSuggestion[];
|
||||||
|
forced_image_compression_size: {
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
};
|
||||||
features: {
|
features: {
|
||||||
auth: boolean;
|
auth: boolean;
|
||||||
auth_trusted_header: boolean;
|
auth_trusted_header: boolean;
|
||||||
|
Loading…
Reference in New Issue
Block a user