Update app.py
Browse files
app.py
CHANGED
@@ -154,29 +154,38 @@ window.postMessageToParent = function(prompt, event, source, value) {
|
|
154 |
}
|
155 |
}
|
156 |
}
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
console.log("post finish");
|
160 |
return prompt;
|
161 |
}
|
162 |
function uploadImage(prompt, images, event, source, value) {
|
163 |
// Ensure we're in an iframe
|
164 |
console.log("uploadImage", prompt, images && images.length > 0 ? images[0].image.url : null, event, source, value);
|
|
|
|
|
|
|
165 |
if (window.self !== window.top) {
|
166 |
-
//
|
167 |
-
let imageUrl = images && images.length > 0 ? images[0].image.url : null;
|
168 |
-
|
169 |
// Prepare the data to send
|
170 |
let data = {
|
171 |
event: event,
|
172 |
source: source,
|
173 |
-
|
174 |
-
|
|
|
|
|
175 |
};
|
176 |
-
|
177 |
-
// Post the message to the parent window
|
178 |
window.parent.postMessage(JSON.stringify(data), '*');
|
179 |
-
} else {
|
|
|
|
|
180 |
console.log("Not in an iframe, can't post to parent");
|
181 |
}
|
182 |
return ""
|
|
|
154 |
}
|
155 |
}
|
156 |
}
|
157 |
+
if (window.self !== window.top) {
|
158 |
+
// Post the message to the parent window
|
159 |
+
window.parent.postMessage(message, '*');
|
160 |
+
}else if(isValidEnv()){
|
161 |
+
sendCustomEventToDataLayer({},event,source,value)
|
162 |
+
}else
|
163 |
+
console.log("Not in an iframe, can't post to parent");
|
164 |
+
}
|
165 |
console.log("post finish");
|
166 |
return prompt;
|
167 |
}
|
168 |
function uploadImage(prompt, images, event, source, value) {
|
169 |
// Ensure we're in an iframe
|
170 |
console.log("uploadImage", prompt, images && images.length > 0 ? images[0].image.url : null, event, source, value);
|
171 |
+
// Get the first image from the gallery (assuming it's an array)
|
172 |
+
let imageUrl = images && images.length > 0 ? images[0].image.url : null;
|
173 |
+
|
174 |
if (window.self !== window.top) {
|
175 |
+
// Post the message to the parent window
|
|
|
|
|
176 |
// Prepare the data to send
|
177 |
let data = {
|
178 |
event: event,
|
179 |
source: source,
|
180 |
+
value:{
|
181 |
+
prompt: prompt,
|
182 |
+
image: imageUrl
|
183 |
+
}
|
184 |
};
|
|
|
|
|
185 |
window.parent.postMessage(JSON.stringify(data), '*');
|
186 |
+
} else if (isValidEnv()){
|
187 |
+
sendCustomEventToDataLayer({},event,source,{"prompt": prompt, "image":imageUrl})
|
188 |
+
}else
|
189 |
console.log("Not in an iframe, can't post to parent");
|
190 |
}
|
191 |
return ""
|