@@ -334,73 +334,37 @@ document.addEventListener("DOMContentLoaded", () => {
334334 showToast ( "Failed to download image: " + err . message ) ;
335335 } ) ;
336336 }
337- function refreshImage ( img , imageId ) {
338- console . log ( `Refreshing image with ID: ${ imageId } ` ) ;
339- if ( ! img . src ) {
340- showToast ( "No image source to refresh." ) ;
341- return ;
342- }
343- const urlObj = new URL ( img . src ) ;
344- if ( ! window . polliClient || ! window . polliClient . imageBase ) {
345- showToast ( "Image client not ready." ) ;
337+ function refreshImage ( img , imageId ) {
338+ console . log ( `Refreshing image with ID: ${ imageId } ` ) ;
339+ const { url : finalUrl , error } = window . refreshPolliImage ( img ?. src , {
340+ width : img . naturalWidth ,
341+ height : img . naturalHeight ,
342+ } ) ;
343+ if ( ! finalUrl ) {
344+ showToast ( error || "Failed to refresh image" ) ;
346345 return ;
347346 }
348- const baseOrigin = new URL ( window . polliClient . imageBase ) . origin ;
349- if ( urlObj . origin !== baseOrigin ) {
350- showToast ( "Can't refresh: not a polliLib image URL." ) ;
351- return ;
352- }
353- const newSeed = Math . floor ( Math . random ( ) * 1000000 ) ;
354- let prompt = '' ;
355- try {
356- const parts = urlObj . pathname . split ( '/' ) ;
357- const i = parts . indexOf ( 'prompt' ) ;
358- if ( i >= 0 && parts [ i + 1 ] ) prompt = decodeURIComponent ( parts [ i + 1 ] ) ;
359- } catch { }
360- const width = Number ( urlObj . searchParams . get ( 'width' ) ) || img . naturalWidth || 512 ;
361- const height = Number ( urlObj . searchParams . get ( 'height' ) ) || img . naturalHeight || 512 ;
362- const model = urlObj . searchParams . get ( 'model' ) || ( document . getElementById ( 'model-select' ) ?. value || undefined ) ;
363- let newUrl = img . src ;
364- try {
365- if ( window . polliLib && window . polliClient && prompt ) {
366- newUrl = window . polliLib . mcp . generateImageUrl ( window . polliClient , {
367- prompt, width, height, seed : newSeed , nologo : true , model
368- } ) ;
369- } else {
370- urlObj . searchParams . set ( 'seed' , String ( newSeed ) ) ;
371- newUrl = urlObj . toString ( ) ;
372- }
373- } catch ( e ) {
374- console . warn ( 'polliLib generateImageUrl failed; falling back to seed swap' , e ) ;
375- urlObj . searchParams . set ( 'seed' , String ( newSeed ) ) ;
376- newUrl = urlObj . toString ( ) ;
377- }
378- const newUrlObj = new URL ( newUrl ) ;
379- if ( ! newUrlObj . searchParams . has ( 'referrer' ) && window . polliClient ?. referrer ) {
380- newUrlObj . searchParams . set ( 'referrer' , window . polliClient . referrer ) ; // retain referrer for API tiering
381- }
382- const finalUrl = newUrlObj . toString ( ) ;
383- const loadingDiv = document . createElement ( "div" ) ;
384- loadingDiv . className = "ai-image-loading" ;
385- const spinner = document . createElement ( "div" ) ;
386- spinner . className = "loading-spinner" ;
387- loadingDiv . appendChild ( spinner ) ;
388- loadingDiv . style . width = img . width + "px" ;
389- loadingDiv . style . height = img . height + "px" ;
390- img . parentNode . insertBefore ( loadingDiv , img ) ;
391- img . style . display = "none" ;
392- img . onload = ( ) => {
393- loadingDiv . remove ( ) ;
394- img . style . display = "block" ;
395- showToast ( "Image refreshed with new seed" ) ;
396- } ;
397- img . onerror = ( ) => {
398- loadingDiv . innerHTML = "⚠️ Failed to refresh image" ;
399- loadingDiv . style . display = "flex" ;
400- loadingDiv . style . justifyContent = "center" ;
401- loadingDiv . style . alignItems = "center" ;
402- showToast ( "Failed to refresh image" ) ;
403- } ;
347+ const loadingDiv = document . createElement ( "div" ) ;
348+ loadingDiv . className = "ai-image-loading" ;
349+ const spinner = document . createElement ( "div" ) ;
350+ spinner . className = "loading-spinner" ;
351+ loadingDiv . appendChild ( spinner ) ;
352+ loadingDiv . style . width = img . width + "px" ;
353+ loadingDiv . style . height = img . height + "px" ;
354+ img . parentNode . insertBefore ( loadingDiv , img ) ;
355+ img . style . display = "none" ;
356+ img . onload = ( ) => {
357+ loadingDiv . remove ( ) ;
358+ img . style . display = "block" ;
359+ showToast ( "Image refreshed with new seed" ) ;
360+ } ;
361+ img . onerror = ( ) => {
362+ loadingDiv . innerHTML = "⚠️ Failed to refresh image" ;
363+ loadingDiv . style . display = "flex" ;
364+ loadingDiv . style . justifyContent = "center" ;
365+ loadingDiv . style . alignItems = "center" ;
366+ showToast ( "Failed to refresh image" ) ;
367+ } ;
404368 img . src = finalUrl ;
405369 }
406370 function openImageInNewTab ( img , imageId ) {
0 commit comments