diff --git a/backend/apps/webui/main.py b/backend/apps/webui/main.py index 5bb199352..b823859a6 100644 --- a/backend/apps/webui/main.py +++ b/backend/apps/webui/main.py @@ -25,6 +25,7 @@ from config import ( JWT_EXPIRES_IN, WEBUI_BANNERS, AppConfig, + ENABLE_COMMUNITY_SHARING, ) app = FastAPI() @@ -43,6 +44,7 @@ app.state.config.USER_PERMISSIONS = USER_PERMISSIONS app.state.config.WEBHOOK_URL = WEBHOOK_URL app.state.config.BANNERS = WEBUI_BANNERS +app.state.config.ENABLE_COMMUNITY_SHARING = ENABLE_COMMUNITY_SHARING app.state.MODELS = {} app.state.AUTH_TRUSTED_EMAIL_HEADER = WEBUI_AUTH_TRUSTED_EMAIL_HEADER diff --git a/backend/config.py b/backend/config.py index 731a3572a..28ace5d5d 100644 --- a/backend/config.py +++ b/backend/config.py @@ -568,6 +568,11 @@ WEBHOOK_URL = PersistentConfig( ENABLE_ADMIN_EXPORT = os.environ.get("ENABLE_ADMIN_EXPORT", "True").lower() == "true" +ENABLE_COMMUNITY_SHARING = PersistentConfig( + "ENABLE_COMMUNITY_SHARING", + "ui.enable_community_sharing", + os.environ.get("ENABLE_COMMUNITY_SHARING", "True").lower() == "true", +) class BannerModel(BaseModel): id: str diff --git a/backend/main.py b/backend/main.py index 66fae2b60..d1d267ce0 100644 --- a/backend/main.py +++ b/backend/main.py @@ -358,14 +358,17 @@ async def get_app_config(): "status": True, "name": WEBUI_NAME, "version": VERSION, - "auth": WEBUI_AUTH, - "auth_trusted_header": bool(webui_app.state.AUTH_TRUSTED_EMAIL_HEADER), - "enable_signup": webui_app.state.config.ENABLE_SIGNUP, - "enable_image_generation": images_app.state.config.ENABLED, - "enable_admin_export": ENABLE_ADMIN_EXPORT, "default_locale": default_locale, "default_models": webui_app.state.config.DEFAULT_MODELS, "default_prompt_suggestions": webui_app.state.config.DEFAULT_PROMPT_SUGGESTIONS, + "features": { + "auth": WEBUI_AUTH, + "auth_trusted_header": bool(webui_app.state.AUTH_TRUSTED_EMAIL_HEADER), + "enable_signup": webui_app.state.config.ENABLE_SIGNUP, + "enable_image_generation": images_app.state.config.ENABLED, + "enable_admin_export": ENABLE_ADMIN_EXPORT, + "enable_community_sharing": webui_app.state.config.ENABLE_COMMUNITY_SHARING, + }, } @@ -416,6 +419,19 @@ async def update_webhook_url(form_data: UrlForm, user=Depends(get_admin_user)): } +@app.get("/api/community_sharing", response_model=bool) +async def get_community_sharing_status(request: Request, user=Depends(get_admin_user)): + return webui_app.state.config.ENABLE_COMMUNITY_SHARING + + +@app.get("/api/community_sharing/toggle", response_model=bool) +async def toggle_community_sharing(request: Request, user=Depends(get_admin_user)): + webui_app.state.config.ENABLE_COMMUNITY_SHARING = ( + not webui_app.state.config.ENABLE_COMMUNITY_SHARING + ) + return webui_app.state.config.ENABLE_COMMUNITY_SHARING + + @app.get("/api/version") async def get_app_config(): return { diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index 5d94e7678..dc51abd52 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -1,4 +1,4 @@ -import { WEBUI_BASE_URL } from '$lib/constants'; +import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants'; export const getModels = async (token: string = '') => { let error = null; @@ -246,6 +246,60 @@ export const updateWebhookUrl = async (token: string, url: string) => { return res.url; }; +export const getCommunitySharingEnabledStatus = async (token: string) => { + let error = null; + + const res = await fetch(`${WEBUI_BASE_URL}/api/community_sharing`, { + 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.log(err); + error = err; + return null; + }); + + if (error) { + throw error; + } + + return res; +}; + +export const toggleCommunitySharingEnabledStatus = async (token: string) => { + let error = null; + + const res = await fetch(`${WEBUI_BASE_URL}/api/community_sharing/toggle`, { + 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.log(err); + error = err.detail; + return null; + }); + + if (error) { + throw error; + } + + return res; +}; + export const getModelConfig = async (token: string): Promise => { let error = null; diff --git a/src/lib/components/admin/Settings/Database.svelte b/src/lib/components/admin/Settings/Database.svelte index 711c1254f..3ae01a668 100644 --- a/src/lib/components/admin/Settings/Database.svelte +++ b/src/lib/components/admin/Settings/Database.svelte @@ -34,7 +34,7 @@
{$i18n.t('Database')}
- {#if $config?.enable_admin_export ?? true} + {#if $config?.features.enable_admin_export ?? true}
diff --git a/src/lib/components/admin/Settings/General.svelte b/src/lib/components/admin/Settings/General.svelte index 5674916d6..572ff82ad 100644 --- a/src/lib/components/admin/Settings/General.svelte +++ b/src/lib/components/admin/Settings/General.svelte @@ -1,5 +1,10 @@ @@ -114,6 +137,47 @@
+
+
{$i18n.t('Enable Community Sharing')}
+ + +
+
diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 619bcbc07..c5d753b51 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -693,7 +693,7 @@ - {#if $config.enable_image_generation && !readOnly} + {#if $config?.features.enable_image_generation && !readOnly} + {#if $config?.features.enable_community_sharing} + + {/if}