Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(cloud): die Inhaltsrichtlinie auch im Desktop, ueber dieselbe Route

Davidff6ea1a49a8b
diff --git a/src/api/cloud/jobs.ts b/src/api/cloud/jobs.ts
index 809c47a0..5eb34ef6 100644
--- a/src/api/cloud/jobs.ts
+++ b/src/api/cloud/jobs.ts
@@ -222,3 +222,40 @@ export async function pollJob(
}
export { CloudJobError }
+
+// ── Kontoeinstellung: Inhaltsrichtlinie (Migration 0042) ─────────────
+
+export type ContentPolicy = 'strict' | 'soft' | 'off'
+
+export interface ContentPolicyState {
+ policy: ContentPolicy
+ ageConfirmedAt: string | null
+}
+
+/**
+ * Die Inhaltsrichtlinie dieses Kontos, gelesen und gesetzt ueber DIESELBE
+ * Route wie in der Webanwendung.
+ *
+ * Zwei Kopien derselben Einstellung waeren zwei Wahrheiten. Die Desktop-App
+ * bringt hier nichts Eigenes mit, sie zeigt und schickt nur, was der Server
+ * sagt. 'off' verlangt eine Altersbestaetigung in derselben Anfrage; den
+ * Zeitstempel setzt der Server selbst, ein mitgeschickter waere wertlos.
+ */
+export async function getContentPolicy(): Promise<ContentPolicyState> {
+ const res = await cloudFetch('/api/account/content-policy')
+ const data = await jsonOrError<{ policy?: string; ageConfirmedAt?: string | null }>(res)
+ return {
+ policy: data.policy === 'strict' || data.policy === 'off' ? data.policy : 'soft',
+ ageConfirmedAt: data.ageConfirmedAt ?? null,
+ }
+}
+
+export async function setContentPolicy(policy: ContentPolicy, ageConfirmed = false): Promise<ContentPolicy> {
+ const res = await cloudFetch('/api/account/content-policy', {
+ method: 'PUT',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ policy, ageConfirmed }),
+ })
+ const data = await jsonOrError<{ policy?: string }>(res)
+ return data.policy === 'strict' || data.policy === 'off' ? data.policy : 'soft'
+}
diff --git a/src/components/settings/ContentPolicySettings.tsx b/src/components/settings/ContentPolicySettings.tsx
new file mode 100644
index 00000000..4dc9ea6f
--- /dev/null
+++ b/src/components/settings/ContentPolicySettings.tsx
@@ -0,0 +1,128 @@
+import { useCallback, useEffect, useState } from 'react'
+import { HINWEIS_TEXT } from '../../lib/hinweis'
+import { getContentPolicy, setContentPolicy, type ContentPolicy } from '../../api/cloud/jobs'
+import { useCloudAuthStore } from '../../stores/cloudAuthStore'
+
+const OPTIONS: { value: ContentPolicy; label: string; hint: string }[] = [
+ { value: 'strict', label: 'Strict', hint: 'The tightest filter we have. Choose this if others use your screen.' },
+ { value: 'soft', label: 'Standard', hint: 'The default for every account.' },
+ { value: 'off', label: 'Off', hint: 'No filter beyond the legal limits below. Requires an age confirmation.' },
+]
+
+/**
+ * Die Inhaltsrichtlinie des Kontos, hier und in der Webanwendung dieselbe.
+ *
+ * Der Server entscheidet. Diese Steuerung schickt einen Wunsch und zeigt, was
+ * zurueckkommt; sie haelt keinen eigenen Zustand vor, den der Server nicht
+ * kennt. Wer sie faelscht, faelscht eine Beschriftung, keinen Zugang: die
+ * Auftragsroute liest die Datenbank bei jedem Auftrag neu.
+ *
+ * Die gesetzlichen Grenzen sind kein Teil der Wahl. Sie gelten bei jedem Wert.
+ */
+export function ContentPolicySettings() {
+ const signedIn = useCloudAuthStore((s) => s.status === 'signed-in')
+ const [policy, setPolicy] = useState<ContentPolicy>('soft')
+ const [confirmedAt, setConfirmedAt] = useState<string | null>(null)
+ const [pending, setPending] = useState<ContentPolicy | null>(null)
+ const [busy, setBusy] = useState(false)
+ const [error, setError] = useState('')
+
+ useEffect(() => {
+ if (!signedIn) return
+ let live = true
+ getContentPolicy()
+ .then((s) => { if (live) { setPolicy(s.policy); setConfirmedAt(s.ageConfirmedAt) } })
+ .catch(() => { /* signed out or offline: the default stands */ })
+ return () => { live = false }
+ }, [signedIn])
+
+ const save = useCallback(async (next: ContentPolicy, ageConfirmed: boolean) => {
+ setBusy(true)
+ setError('')
+ try {
+ const saved = await setContentPolicy(next, ageConfirmed)
+ setPolicy(saved)
+ setConfirmedAt(saved === 'off' ? new Date().toISOString() : null)
+ setPending(null)
+ } catch (err) {
+ setError(err instanceof Error ? err.message : 'Could not save the setting.')
+ } finally {
+ setBusy(false)
+ }
+ }, [])
+
+ if (!signedIn) {
+ return (
+ <p className="text-[0.6rem] text-gray-500 leading-relaxed" data-testid="content-policy-signed-out">
+ Sign in to your LU Cloud account to change this setting.
+ </p>
+ )
+ }
+
+ return (
+ <div className="space-y-2" data-testid="content-policy">
+ <p className="text-[0.6rem] text-gray-500 leading-relaxed">
+ Applies to images and video rendered in the cloud. Text is unaffected, and nothing on
+ your own machine is.
+ </p>
+
+ {OPTIONS.map((o) => (
+ <label key={o.value} className="flex cursor-pointer items-start gap-2">
+ <input
+ type="radio"
+ name="lu-content-policy"
+ className="mt-1"
+ value={o.value}
+ checked={policy === o.value}
+ disabled={busy}
+ onChange={() => { if (o.value === 'off') setPending('off'); else void save(o.value, false) }}
+ />
+ <span>
+ <span className="text-[0.7rem] text-gray-700 dark:text-gray-300">{o.label}</span>
+ <span className="block text-[0.6rem] text-gray-500 dark:text-gray-600 leading-snug">{o.hint}</span>
+ </span>
+ </label>
+ ))}
+
+ {pending === 'off' && (
+ <div className="space-y-2 rounded-md border border-gray-200 dark:border-white/10 p-2" data-testid="age-gate">
+ <p className="text-[0.6rem] text-gray-600 dark:text-gray-400">
+ Confirm that you are 18 or older and that you are turning this off for yourself.
+ </p>
+ <div className="flex gap-2">
+ <button
+ type="button"
+ className="rounded-md bg-violet-500/15 px-3 py-1 text-[0.65rem] font-medium text-violet-500 dark:text-violet-300 hover:bg-violet-500/25 disabled:opacity-50"
+ disabled={busy}
+ onClick={() => void save('off', true)}
+ >
+ I am 18 or older
+ </button>
+ <button
+ type="button"
+ className="rounded-md border border-gray-200 dark:border-white/10 px-3 py-1 text-[0.65rem]"
+ disabled={busy}
+ onClick={() => setPending(null)}
+ >
+ Cancel
+ </button>
+ </div>
+ </div>
+ )}
+
+ {policy === 'off' && confirmedAt && (
+ <p className="text-[0.6rem] text-gray-500">
+ Age confirmed on {new Date(confirmedAt).toLocaleDateString()}. Choosing another option
+ clears that confirmation.
+ </p>
+ )}
+
+ {error && <p className={`text-[0.6rem] ${HINWEIS_TEXT.fehler}`} role="alert">{error}</p>}
+
+ <p className="text-[0.6rem] text-gray-500 leading-relaxed">
+ Material involving minors, and photographs of real people uploaded without their consent,
+ are refused on every request whatever this is set to, and reported.
+ </p>
+ </div>
+ )
+}
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index d046abe4..b500e3d3 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -64,6 +64,7 @@ import {
import { CivitaiApiKeySetting } from './CivitaiApiKeySetting'
import { HfTokenSetting } from './HfTokenSetting'
import { HINWEIS_TEXT, PUNKT_FARBE } from '../../lib/hinweis'
+import { ContentPolicySettings } from './ContentPolicySettings'
// ── User profile picture (Appearance) ───────────────────────────
// Self-contained like HfDownloadPathSetting. Stores the picture as a
@@ -1747,6 +1748,11 @@ export function SettingsPage() {
</button>
</div>
</Section>
+ {/* Dieselbe Einstellung wie in der Webanwendung, ueber dieselbe
+ Route. Zwei Kopien waeren zwei Wahrheiten. */}
+ <Section title="Content policy">
+ <ContentPolicySettings />
+ </Section>
{/* Keys are minted and revoked on lu-labs.ai only; the desktop app
never sees the plaintext, so this section just points there. */}
<Section title="Cloud API Keys">
diff --git a/src/components/settings/__tests__/content-policy-settings.test.tsx b/src/components/settings/__tests__/content-policy-settings.test.tsx
new file mode 100644
index 00000000..025a1693
--- /dev/null
+++ b/src/components/settings/__tests__/content-policy-settings.test.tsx
@@ -0,0 +1,82 @@
+// @vitest-environment jsdom
+/**
+ * Die Inhaltsrichtlinie im Desktop: dieselbe Route, dieselbe Alterssperre,
+ * derselbe Wortlaut wie in der Webanwendung.
+ *
+ * Der Posten ist Mechanik. Es wird nichts erzeugt und nichts bewertet,
+ * geprueft werden Anfrage, Sperre und Beschriftung.
+ */
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+
+const api = vi.hoisted(() => ({
+ get: vi.fn(async () => ({ policy: 'soft' as const, ageConfirmedAt: null })),
+ set: vi.fn(async (p: string) => p),
+}))
+vi.mock('../../../api/cloud/jobs', () => ({
+ getContentPolicy: api.get,
+ setContentPolicy: api.set,
+}))
+
+import { ContentPolicySettings } from '../ContentPolicySettings'
+import { useCloudAuthStore } from '../../../stores/cloudAuthStore'
+
+const signIn = () => useCloudAuthStore.setState({ status: 'signed-in' })
+
+beforeEach(() => {
+ cleanup()
+ vi.clearAllMocks()
+ api.get.mockResolvedValue({ policy: 'soft', ageConfirmedAt: null })
+ signIn()
+})
+
+describe('ContentPolicySettings', () => {
+ it('asks the server instead of keeping its own copy', async () => {
+ api.get.mockResolvedValue({ policy: 'strict', ageConfirmedAt: null })
+ render(<ContentPolicySettings />)
+ await waitFor(() => expect((screen.getByDisplayValue('strict') as HTMLInputElement).checked).toBe(true))
+ })
+
+ it('says what to do instead of showing a dead control while signed out', () => {
+ useCloudAuthStore.setState({ status: 'signed-out' })
+ render(<ContentPolicySettings />)
+ expect(screen.getByTestId('content-policy-signed-out')).toBeTruthy()
+ expect(api.get).not.toHaveBeenCalled()
+ })
+
+ it('never sends off without an age confirmation in the same request', async () => {
+ render(<ContentPolicySettings />)
+ fireEvent.click(screen.getByDisplayValue('off'))
+ expect(api.set).not.toHaveBeenCalled()
+ expect(screen.getByTestId('age-gate')).toBeTruthy()
+ fireEvent.click(screen.getByRole('button', { name: 'I am 18 or older' }))
+ await waitFor(() => expect(api.set).toHaveBeenCalledWith('off', true))
+ })
+
+ it('lets the gate be cancelled without changing anything', () => {
+ render(<ContentPolicySettings />)
+ fireEvent.click(screen.getByDisplayValue('off'))
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
+ expect(screen.queryByTestId('age-gate')).toBeNull()
+ expect(api.set).not.toHaveBeenCalled()
+ })
+
+ it('sends the two harmless values straight through', async () => {
+ render(<ContentPolicySettings />)
+ fireEvent.click(screen.getByDisplayValue('strict'))
+ await waitFor(() => expect(api.set).toHaveBeenCalledWith('strict', false))
+ })
+
+ it('uses no adult vocabulary and states the floor that no setting moves', () => {
+ render(<ContentPolicySettings />)
+ const text = document.body.textContent ?? ''
+ expect(text).not.toMatch(/adult|nsfw|nude|nudity|porn|hardcore|explicit|uncensored/i)
+ expect(text).toMatch(/minors/i)
+ expect(text).toMatch(/consent/i)
+ })
+
+ it('says plainly that the local machine is not affected', () => {
+ render(<ContentPolicySettings />)
+ expect(document.body.textContent ?? '').toMatch(/nothing on\s+your own machine is/i)
+ })
+})
diff --git a/src/components/settings/settings-nav.ts b/src/components/settings/settings-nav.ts
index 38032a9b..d66a776a 100644
--- a/src/components/settings/settings-nav.ts
+++ b/src/components/settings/settings-nav.ts
@@ -75,6 +75,7 @@ export function sectionsFor(tab: SettingsTab, flags: SettingsSectionFlags): stri
case 'general':
return [
'LU Cloud Account',
+ 'Content policy',
'Cloud API Keys',
'Appearance',
'Generation',