Load bg thumbnail config from backend
| @@ -27,6 +27,11 @@ const THUMBNAIL_STORAGE = localforage.createInstance({ name: 'SillyTavern_Thumbn | ||
| 27 | 27 | */ |
| 28 | 28 | const THUMBNAIL_BLOBS = new Map(); |
| 29 | 29 | |
| 30 | +const THUMBNAIL_CONFIG = { | |
| 31 | + width: 160, | |
| 32 | + height: 90, | |
| 33 | +}; | |
| 34 | + | |
| 30 | 35 | /** |
| 31 | 36 | * Global IntersectionObserver instance for lazy loading backgrounds |
| 32 | 37 | * @type {IntersectionObserver|null} |
| @@ -282,7 +287,7 @@ async function getThumbnailFromStorage(bg) { | ||
| 282 | 287 | } |
| 283 | 288 | const imageBlob = await response.blob(); |
| 284 | 289 | const imageBase64 = await getBase64Async(imageBlob); |
| 285 | 290 | const thumbnailBase64 = await createThumbnail(imageBase64, THUMBNAIL_CONFIG.width, THUMBNAIL_CONFIG.height); |
| 286 | 291 | const thumbnailBlob = await fetch(thumbnailBase64).then(res => res.blob()); |
| 287 | 292 | await THUMBNAIL_STORAGE.setItem(bg, thumbnailBlob); |
| 288 | 293 | const blobUrl = URL.createObjectURL(thumbnailBlob); |
| @@ -445,9 +450,10 @@ export async function getBackgrounds() { | ||
| 445 | 450 | body: JSON.stringify({}), |
| 446 | 451 | }); |
| 447 | 452 | if (response.ok) { |
| 448 | 453 | const getData{ images, config } = await response.json(); |
| 454 | + Object.assign(THUMBNAIL_CONFIG, config); | |
| 449 | 455 | $('#bg_menu_content').children('div').remove(); |
| 450 | 456 | for (const bg of getDataimages) { |
| 451 | 457 | const template = await getBackgroundFromTemplate(bg, false); |
| 452 | 458 | $('#bg_menu_content').append(template); |
| 453 | 459 | } |
| @@ -4,15 +4,16 @@ import path from 'node:path'; | ||
| 4 | 4 | import express from 'express'; |
| 5 | 5 | import sanitize from 'sanitize-filename'; |
| 6 | 6 | |
| 7 | 7 | import { dimensions, invalidateThumbnail } from './thumbnails.js'; |
| 8 | 8 | import { getImages } from '../util.js'; |
| 9 | 9 | import { getFileNameValidationFunction } from '../middleware/validateFileName.js'; |
| 10 | 10 | |
| 11 | 11 | export const router = express.Router(); |
| 12 | 12 | |
| 13 | 13 | router.post('/all', function (request, response) { |
| 14 | 14 | varconst images = getImages(request.user.directories.backgrounds); |
| 15 | - response.send(JSON.stringify(images)); | |
| 15 | + const config = { width: dimensions.bg[0], height: dimensions.bg[1] }; | |
| 16 | + response.json({ images, config }); | |
| 16 | 17 | }); |
| 17 | 18 | |
| 18 | 19 | router.post('/delete', getFileNameValidationFunction('bg'), function (request, response) { |
| @@ -15,7 +15,7 @@ const quality = Math.min(100, Math.max(1, parseInt(getConfigValue('thumbnails.qu | ||
| 15 | 15 | const pngFormat = String(getConfigValue('thumbnails.format', 'jpg')).toLowerCase().trim() === 'png'; |
| 16 | 16 | |
| 17 | 17 | /** @type {Record<string, number[]>} */ |
| 18 | 18 | export const dimensions = { |
| 19 | 19 | 'bg': getConfigValue('thumbnails.dimensions.bg', [160, 90]), |
| 20 | 20 | 'avatar': getConfigValue('thumbnails.dimensions.avatar', [96, 144]), |
| 21 | 21 | }; |