{#if loaded} { const selected = backgroundInput.files?.[0]; backgroundInput.value = ''; if (!selected || readOnly || loading) return; loading = true; const candidate = URL.createObjectURL(selected); try { if (!['image/png', 'image/jpeg', 'image/webp', 'image/gif'].includes(selected.type)) { throw new Error($i18n.t('Background image must be PNG, JPEG, WebP, or GIF.')); } if (selected.size > 5 * 1024 * 1024) throw new Error($i18n.t('Background image must be at most 5 MiB.')); const image = new Image(); image.src = candidate; await image.decode(); if (image.naturalWidth * image.naturalHeight > 25_000_000) { throw new Error($i18n.t('Background image must be at most 25 megapixels.')); } clearBackgroundPreview(); backgroundPreview = candidate; backgroundFile = selected; } catch (error) { URL.revokeObjectURL(candidate); toast.error(error instanceof Error ? error.message : $i18n.t('Invalid background image.')); } finally { loading = false; } }} /> { allowNavigation = true; afterDiscard?.(); }} /> { if (edit && model?.id) { try { await updateModelAccessGrants(localStorage.token, model.id, model.name, accessGrants); model.access_grants = structuredClone(accessGrants); toast.success($i18n.t('Saved')); } catch (error) { accessGrants = structuredClone(model.access_grants ?? []); toast.error(`${error}`); } } }} />
{#if onBack} {/if} {#if edit && model?.version_id && !readOnly} {/if} {#if !historical && !readOnly}
{#if $user?.permissions?.sharing?.models || $user?.role === 'admin'} (showAccessControlModal = true)} /> {/if}
{/if}
{#if selectingVersion}
{:else if selectedVersion}
{#key selectedVersion.id} {/key}
{/if}
{ let reader = new FileReader(); reader.onload = (event) => { let originalImageUrl = `${event.target?.result}`; // For animated formats (gif, webp), skip resizing to preserve animation const fileType = (inputFiles[0] as any)?.['type']; if (fileType === 'image/gif' || fileType === 'image/webp') { info.meta.profile_image_url = originalImageUrl; inputFiles = null; filesInputElement.value = ''; return; } const img = new Image(); img.src = originalImageUrl; img.onload = function () { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); // Calculate the aspect ratio of the image const aspectRatio = img.width / img.height; // Calculate the new width and height to fit within 100x100 let newWidth, newHeight; if (aspectRatio > 1) { newWidth = 250 * aspectRatio; newHeight = 250; } else { newWidth = 250; newHeight = 250 / aspectRatio; } // Set the canvas size canvas.width = 250; canvas.height = 250; // Calculate the position to center the image const offsetX = (250 - newWidth) / 2; const offsetY = (250 - newHeight) / 2; // Draw the image on the canvas ctx.drawImage(img, offsetX, offsetY, newWidth, newHeight); // Get the base64 representation of the compressed image const compressedSrc = canvas.toDataURL('image/webp', 0.8); // Display the compressed image info.meta.profile_image_url = compressedSrc; inputFiles = null; filesInputElement.value = ''; }; }; if ( inputFiles && inputFiles.length > 0 && ['image/gif', 'image/webp', 'image/jpeg', 'image/png', 'image/svg+xml'].includes( (inputFiles[0] as any)?.['type'] ) ) { reader.readAsDataURL(inputFiles[0]); } else { console.log(`Unsupported File Type '${(inputFiles[0] as any)?.['type']}'.`); inputFiles = null; } }} /> {#if !edit || (edit && model)}
{ submitHandler(); }} >
{#if backgroundPreview || info.meta.background_image_url} {$i18n.t('Background {:else} {/if}
{#if info.meta.profile_image_url && info.meta.profile_image_url !== `${WEBUI_BASE_URL}/static/favicon.png`} {/if}
{#if editingLocale} setLocalizedField( 'name', (e.currentTarget as HTMLInputElement).value )} /> {:else} {/if} {#if !readOnly}
{#if loading}{/if} {#if backgroundPreview || info.meta.background_image_url} {:else} {/if}
{/if}
{#if editingLocale}
{#if localizedField('name')} {/if}
{/if}
{#if editingLocale}
{$i18n.t('Description ({{language}})', { language: editingLocaleLabel || editingLocale })}
{#if localizedField('description')} {/if}
{:else} {/if}
{#if editingLocale}