diff --git a/backend/main.py b/backend/main.py index 7a5bd8126..2dfbce802 100644 --- a/backend/main.py +++ b/backend/main.py @@ -417,6 +417,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/General.svelte b/src/lib/components/admin/Settings/General.svelte index 53246bf59..572ff82ad 100644 --- a/src/lib/components/admin/Settings/General.svelte +++ b/src/lib/components/admin/Settings/General.svelte @@ -1,5 +1,10 @@