@@ -69,10 +69,11 @@ function App() {
6969 layer_height : ! ! metadata . layer_height
7070 } ;
7171
72- // Decode share param if present OR load persisted state
72+ // Decode share param, direct query params, or load persisted state
7373 useEffect ( ( ) => {
7474 try {
7575 const params = new URLSearchParams ( window . location . search ) ;
76+ // 1. Packed card param (legacy/share)
7677 const packed = params . get ( 'card' ) ;
7778 if ( packed ) {
7879 const json = atob ( packed ) ;
@@ -82,25 +83,84 @@ function App() {
8283 setDescription ( parsed . description || '' ) ;
8384 setMetadata ( ( prev ) => ( { ...prev , ...( parsed . metadata || { } ) } ) ) ;
8485 // Intentionally do not load image from URL share (privacy / size)
85- } else {
86- const saved = localStorage . getItem ( 'printCardState' ) ;
87- if ( saved ) {
88- const parsed = JSON . parse ( saved ) ;
89- setTitle ( parsed . title || '' ) ;
90- setPrinter ( parsed . printer || '' ) ;
91- setDescription ( parsed . description || '' ) ;
92- setMetadata ( ( prev ) => ( { ...prev , ...( parsed . metadata || { } ) } ) ) ;
93- if ( parsed . imageUrl ) setImageUrl ( parsed . imageUrl ) ;
94- if ( parsed . accentColor ) setAccentColor ( parsed . accentColor ) ;
95- if ( parsed . layout ) setLayout ( parsed . layout ) ;
96- if ( parsed . aspectRatio ) setAspectRatio ( parsed . aspectRatio ) ;
97- if ( parsed . imageFit ) setImageFit ( parsed . imageFit ) ;
98- if ( Array . isArray ( parsed . galleryImages ) ) setGalleryImages ( parsed . galleryImages ) ;
99- if ( Array . isArray ( parsed . enabledFeatures ) ) setEnabledFeatures ( parsed . enabledFeatures ) ;
100- if ( typeof parsed . showAuthorCredit === 'boolean' ) setShowAuthorCredit ( parsed . showAuthorCredit ) ;
101- if ( parsed . modelingSoftware ) setModelingSoftware ( parsed . modelingSoftware ) ;
102- if ( parsed . modelSource ) setModelSource ( parsed . modelSource ) ;
103- }
86+ return ;
87+ }
88+ // 2. Direct query params (for Octoprint extension)
89+ let foundAny = false ;
90+ // Image: base64 string
91+ const imageParam = params . get ( 'image' ) ;
92+ if ( imageParam ) {
93+ // Accept raw base64 or full data URL
94+ const isDataUrl = imageParam . startsWith ( 'data:' ) ;
95+ setImageUrl ( isDataUrl ? imageParam : `data:image/png;base64,${ imageParam } ` ) ;
96+ foundAny = true ;
97+ }
98+ // Title, printer, description
99+ const titleParam = params . get ( 'title' ) ;
100+ if ( titleParam ) { setTitle ( titleParam ) ; foundAny = true ; }
101+ const printerParam = params . get ( 'printer' ) ;
102+ if ( printerParam ) { setPrinter ( printerParam ) ; foundAny = true ; }
103+ const descParam = params . get ( 'description' ) ;
104+ if ( descParam ) { setDescription ( descParam ) ; foundAny = true ; }
105+ // Metadata fields
106+ const metaKeys = [ 'speed' , 'layer_height' , 'progress' , 'estimated_time' , 'nozzle_temp' , 'bed_temp' , 'material' , 'print_mode' , 'slicer' , 'color' ] ;
107+ let metaObj : { [ key : string ] : string } = { } ;
108+ metaKeys . forEach ( key => {
109+ const val = params . get ( key ) ;
110+ if ( val !== null ) { metaObj [ key ] = val ; foundAny = true ; }
111+ } ) ;
112+ if ( Object . keys ( metaObj ) . length > 0 ) setMetadata ( prev => ( { ...prev , ...metaObj } ) ) ;
113+ // Accent color, layout, aspect, imageFit, features, etc.
114+ const accentParam = params . get ( 'accentColor' ) ;
115+ if ( accentParam ) { setAccentColor ( accentParam ) ; foundAny = true ; }
116+ const layoutParam = params . get ( 'layout' ) ;
117+ if ( layoutParam ) { setLayout ( layoutParam as any ) ; foundAny = true ; }
118+ const aspectParam = params . get ( 'aspectRatio' ) ;
119+ if ( aspectParam ) { setAspectRatio ( aspectParam ) ; foundAny = true ; }
120+ const imageFitParam = params . get ( 'imageFit' ) ;
121+ if ( imageFitParam ) { setImageFit ( imageFitParam as any ) ; foundAny = true ; }
122+ // Gallery images (comma separated base64)
123+ const galleryParam = params . get ( 'galleryImages' ) ;
124+ if ( galleryParam ) {
125+ const imgs = galleryParam . split ( ',' ) . map ( img => img . startsWith ( 'data:' ) ? img : `data:image/png;base64,${ img } ` ) ;
126+ setGalleryImages ( imgs ) ;
127+ foundAny = true ;
128+ }
129+ // Features (comma separated)
130+ const featuresParam = params . get ( 'enabledFeatures' ) ;
131+ if ( featuresParam ) {
132+ setEnabledFeatures ( featuresParam . split ( ',' ) ) ;
133+ foundAny = true ;
134+ }
135+ // Author credit
136+ const authorParam = params . get ( 'showAuthorCredit' ) ;
137+ if ( authorParam ) {
138+ setShowAuthorCredit ( authorParam === 'true' ) ;
139+ foundAny = true ;
140+ }
141+ const modelingParam = params . get ( 'modelingSoftware' ) ;
142+ if ( modelingParam ) { setModelingSoftware ( modelingParam ) ; foundAny = true ; }
143+ const sourceParam = params . get ( 'modelSource' ) ;
144+ if ( sourceParam ) { setModelSource ( sourceParam ) ; foundAny = true ; }
145+ if ( foundAny ) return ;
146+ // 3. Fallback: persisted state
147+ const saved = localStorage . getItem ( 'printCardState' ) ;
148+ if ( saved ) {
149+ const parsed = JSON . parse ( saved ) ;
150+ setTitle ( parsed . title || '' ) ;
151+ setPrinter ( parsed . printer || '' ) ;
152+ setDescription ( parsed . description || '' ) ;
153+ setMetadata ( ( prev ) => ( { ...prev , ...( parsed . metadata || { } ) } ) ) ;
154+ if ( parsed . imageUrl ) setImageUrl ( parsed . imageUrl ) ;
155+ if ( parsed . accentColor ) setAccentColor ( parsed . accentColor ) ;
156+ if ( parsed . layout ) setLayout ( parsed . layout ) ;
157+ if ( parsed . aspectRatio ) setAspectRatio ( parsed . aspectRatio ) ;
158+ if ( parsed . imageFit ) setImageFit ( parsed . imageFit ) ;
159+ if ( Array . isArray ( parsed . galleryImages ) ) setGalleryImages ( parsed . galleryImages ) ;
160+ if ( Array . isArray ( parsed . enabledFeatures ) ) setEnabledFeatures ( parsed . enabledFeatures ) ;
161+ if ( typeof parsed . showAuthorCredit === 'boolean' ) setShowAuthorCredit ( parsed . showAuthorCredit ) ;
162+ if ( parsed . modelingSoftware ) setModelingSoftware ( parsed . modelingSoftware ) ;
163+ if ( parsed . modelSource ) setModelSource ( parsed . modelSource ) ;
104164 }
105165 } catch { }
106166 } , [ ] ) ;
0 commit comments