Merge pull request #2863 from SillyTavern/unify-user-avatar Unify default user avatars
SignedBinary file
| @@ -510,6 +510,7 @@ let saveCharactersPage = 0; | ||
| 510 | 510 | export const default_avatar = 'img/ai4.png'; |
| 511 | 511 | export const system_avatar = 'img/five.png'; |
| 512 | 512 | export const comment_avatar = 'img/quill.png'; |
| 513 | +export const default_user_avatar = 'img/user-default.png'; | |
| 513 | 514 | export let CLIENT_VERSION = 'SillyTavern:UNKNOWN:Cohee#1207'; // For Horde header |
| 514 | 515 | let optionsPopper = Popper.createPopper(document.getElementById('options_button'), document.getElementById('options'), { |
| 515 | 516 | placement: 'top-start', |
| @@ -2,7 +2,7 @@ import { | ||
| 2 | 2 | characters, |
| 3 | 3 | chat, |
| 4 | 4 | chat_metadata, |
| 5 | 5 | default_avatardefault_user_avatar, |
| 6 | 6 | eventSource, |
| 7 | 7 | event_types, |
| 8 | 8 | getRequestHeaders, |
| @@ -357,7 +357,7 @@ async function createDummyPersona() { | ||
| 357 | 357 | // Date + name (only ASCII) to make it unique |
| 358 | 358 | const avatarId = `${Date.now()}-${personaName.replace(/[^a-zA-Z0-9]/g, '')}.png`; |
| 359 | 359 | initPersona(avatarId, personaName, ''); |
| 360 | 360 | await uploadUserAvatar(default_avatardefault_user_avatar, avatarId); |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
| @@ -944,7 +944,7 @@ async function onPersonasRestoreInput(e) { | ||
| 944 | 944 | // If the avatar is missing, upload it |
| 945 | 945 | if (!avatarsList.includes(key)) { |
| 946 | 946 | warnings.push(`Persona image "${key}" (${value}) is missing, uploading default avatar`); |
| 947 | 947 | await uploadUserAvatar(default_avatardefault_user_avatar, key); |
| 948 | 948 | } |
| 949 | 949 | } |
| 950 | 950 | |
| @@ -5,7 +5,6 @@ const PUBLIC_DIRECTORIES = { | ||
| 5 | 5 | extensions: 'public/scripts/extensions', |
| 6 | 6 | }; |
| 7 | 7 | |
| 8 | -const DEFAULT_AVATAR = '/img/ai4.png'; | |
| 9 | 8 | const SETTINGS_FILE = 'settings.json'; |
| 10 | 9 | |
| 11 | 10 | /** |
| @@ -422,7 +421,6 @@ const VLLM_KEYS = [ | ||
| 422 | 421 | |
| 423 | 422 | module.exports = { |
| 424 | 423 | DEFAULT_USER, |
| 425 | - DEFAULT_AVATAR, | |
| 426 | 424 | SETTINGS_FILE, |
| 427 | 425 | PUBLIC_DIRECTORIES, |
| 428 | 426 | USER_DIRECTORY_TEMPLATE, |
| @@ -726,13 +726,12 @@ router.post('/create', urlencodedParser, async function (request, response) { | ||
| 726 | 726 | const char = JSON.stringify(charaFormatData(request.body, request.user.directories)); |
| 727 | 727 | const internalName = getPngName(request.body.ch_name, request.user.directories); |
| 728 | 728 | const avatarName = `${internalName}.png`; |
| 729 | - const defaultAvatar = './public/img/ai4.png'; | |
| 730 | 729 | const chatsPath = path.join(request.user.directories.chats, internalName); |
| 731 | 730 | |
| 732 | 731 | if (!fs.existsSync(chatsPath)) fs.mkdirSync(chatsPath); |
| 733 | 732 | |
| 734 | 733 | if (!request.file) { |
| 735 | 734 | await writeCharacterData(defaultAvatardefaultAvatarPath, char, internalName, request); |
| 736 | 735 | return response.send(avatarName); |
| 737 | 736 | } else { |
| 738 | 737 | const crop = tryParse(request.query.crop); |
| @@ -10,7 +10,7 @@ const express = require('express'); | ||
| 10 | 10 | const mime = require('mime-types'); |
| 11 | 11 | const archiver = require('archiver'); |
| 12 | 12 | |
| 13 | 13 | const { USER_DIRECTORY_TEMPLATE, DEFAULT_USER, PUBLIC_DIRECTORIES, DEFAULT_AVATAR, SETTINGS_FILE } = require('./constants'); |
| 14 | 14 | const { getConfigValue, color, delay, setConfigValue, generateTimestamp } = require('./util'); |
| 15 | 15 | const { readSecret, writeSecret } = require('./endpoints/secrets'); |
| 16 | 16 | |
| @@ -24,6 +24,7 @@ const ANON_CSRF_SECRET = crypto.randomBytes(64).toString('base64'); | ||
| 24 | 24 | * @type {Map<string, UserDirectoryList>} |
| 25 | 25 | */ |
| 26 | 26 | const DIRECTORIES_CACHE = new Map(); |
| 27 | +const PUBLIC_USER_AVATAR = '/img/default-user.png'; | |
| 27 | 28 | |
| 28 | 29 | const STORAGE_KEYS = { |
| 29 | 30 | csrfSecret: 'csrfSecret', |
| @@ -478,11 +479,11 @@ async function getUserAvatar(handle) { | ||
| 478 | 479 | const settings = fs.existsSync(pathToSettings) ? JSON.parse(fs.readFileSync(pathToSettings, 'utf8')) : {}; |
| 479 | 480 | const avatarFile = settings?.power_user?.default_persona || settings?.user_avatar; |
| 480 | 481 | if (!avatarFile) { |
| 481 | 482 | return DEFAULT_AVATARPUBLIC_USER_AVATAR; |
| 482 | 483 | } |
| 483 | 484 | const avatarPath = path.join(directory.avatars, avatarFile); |
| 484 | 485 | if (!fs.existsSync(avatarPath)) { |
| 485 | 486 | return DEFAULT_AVATARPUBLIC_USER_AVATAR; |
| 486 | 487 | } |
| 487 | 488 | const mimeType = mime.lookup(avatarPath); |
| 488 | 489 | const base64Content = fs.readFileSync(avatarPath, 'base64'); |
| @@ -490,7 +491,7 @@ async function getUserAvatar(handle) { | ||
| 490 | 491 | } |
| 491 | 492 | catch { |
| 492 | 493 | // Ignore errors |
| 493 | 494 | return DEFAULT_AVATARPUBLIC_USER_AVATAR; |
| 494 | 495 | } |
| 495 | 496 | } |
| 496 | 497 | |