Update index.html
Browse files- index.html +94 -216
index.html
CHANGED
@@ -1,223 +1,101 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
display: flex;
|
20 |
-
align-items: center;
|
21 |
-
justify-content: center;
|
22 |
-
height: 100vh;
|
23 |
-
flex-direction: column;
|
24 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
25 |
-
color: white;
|
26 |
-
}
|
27 |
-
|
28 |
-
.loading-spinner {
|
29 |
-
width: 50px;
|
30 |
-
height: 50px;
|
31 |
-
border: 4px solid rgba(255,255,255,0.3);
|
32 |
-
border-top: 4px solid white;
|
33 |
-
border-radius: 50%;
|
34 |
-
animation: spin 1s linear infinite;
|
35 |
-
margin-bottom: 20px;
|
36 |
-
}
|
37 |
-
|
38 |
-
@keyframes spin {
|
39 |
-
0% { transform: rotate(0deg); }
|
40 |
-
100% { transform: rotate(360deg); }
|
41 |
-
}
|
42 |
-
|
43 |
-
.error {
|
44 |
-
display: flex;
|
45 |
-
align-items: center;
|
46 |
-
justify-content: center;
|
47 |
-
height: 100vh;
|
48 |
-
flex-direction: column;
|
49 |
-
background: #f8f9fa;
|
50 |
-
color: #dc3545;
|
51 |
-
text-align: center;
|
52 |
-
padding: 20px;
|
53 |
-
}
|
54 |
-
|
55 |
-
.app-container {
|
56 |
-
width: 100vw;
|
57 |
-
height: 100vh;
|
58 |
-
position: relative;
|
59 |
-
}
|
60 |
-
|
61 |
-
iframe {
|
62 |
-
width: 100%;
|
63 |
-
height: 100%;
|
64 |
-
border: none;
|
65 |
-
display: none;
|
66 |
-
}
|
67 |
-
|
68 |
-
iframe.visible {
|
69 |
-
display: block;
|
70 |
-
}
|
71 |
-
</style>
|
72 |
</head>
|
73 |
<body>
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
const [tokenUrl, signature] = data;
|
119 |
-
|
120 |
-
// Verify signature
|
121 |
-
const expectedSignature = CryptoJS.MD5(tokenUrl + REQ_TOKEN).toString();
|
122 |
-
if (expectedSignature !== signature) {
|
123 |
-
throw new Error('Invalid signature');
|
124 |
-
}
|
125 |
-
|
126 |
-
console.log('Signature verified');
|
127 |
-
|
128 |
-
// Sign the response
|
129 |
-
const responseSignature = CryptoJS.MD5(signature + RES_TOKEN).toString();
|
130 |
-
|
131 |
-
// Get user profile
|
132 |
-
const response = await fetch(tokenUrl, {
|
133 |
-
method: 'GET',
|
134 |
-
headers: {
|
135 |
-
'x-token': responseSignature,
|
136 |
-
'Content-Type': 'application/json'
|
137 |
-
}
|
138 |
-
});
|
139 |
-
|
140 |
-
if (!response.ok) {
|
141 |
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
142 |
-
}
|
143 |
-
|
144 |
-
userProfile = await response.json();
|
145 |
-
console.log('User profile loaded:', userProfile);
|
146 |
-
|
147 |
-
// Set iframe src and show it
|
148 |
-
const iframe = document.getElementById('gradio-app');
|
149 |
-
iframe.src = GRADIO_APP_URL;
|
150 |
-
|
151 |
-
// Hide loading, show app
|
152 |
-
document.getElementById('loading').style.display = 'none';
|
153 |
-
iframe.classList.add('visible');
|
154 |
-
|
155 |
-
// Store user info for the Gradio app
|
156 |
-
window.openplatformUser = userProfile;
|
157 |
-
|
158 |
-
} catch (error) {
|
159 |
-
console.error('OpenPlatform initialization error:', error);
|
160 |
-
document.getElementById('loading').style.display = 'none';
|
161 |
-
document.getElementById('error').style.display = 'flex';
|
162 |
-
document.getElementById('error-message').textContent = error.message;
|
163 |
-
}
|
164 |
-
}
|
165 |
-
|
166 |
-
// Send notification to OpenPlatform
|
167 |
-
async function sendNotification(message, icon = 'ti ti-code', color = '#667eea') {
|
168 |
-
if (!userProfile || !userProfile.notify) {
|
169 |
-
console.warn('No notification endpoint available');
|
170 |
-
return;
|
171 |
-
}
|
172 |
-
|
173 |
-
try {
|
174 |
-
const notifyUrl = userProfile.notify;
|
175 |
-
const signature = CryptoJS.MD5((notifyUrl + REQ_TOKEN) + RES_TOKEN).toString();
|
176 |
-
|
177 |
-
const notification = {
|
178 |
-
body: message,
|
179 |
-
icon: icon,
|
180 |
-
color: color,
|
181 |
-
path: window.location.pathname
|
182 |
-
};
|
183 |
-
|
184 |
-
const response = await fetch(notifyUrl, {
|
185 |
-
method: 'POST',
|
186 |
-
headers: {
|
187 |
-
'x-token': signature,
|
188 |
-
'Content-Type': 'application/json'
|
189 |
-
},
|
190 |
-
body: JSON.stringify(notification)
|
191 |
-
});
|
192 |
-
|
193 |
-
if (response.ok) {
|
194 |
-
console.log('Notification sent successfully');
|
195 |
-
} else {
|
196 |
-
console.warn('Failed to send notification:', response.status);
|
197 |
-
}
|
198 |
-
|
199 |
-
} catch (error) {
|
200 |
-
console.error('Error sending notification:', error);
|
201 |
-
}
|
202 |
-
}
|
203 |
-
|
204 |
-
// Make functions available globally
|
205 |
-
window.sendOpenPlatformNotification = sendNotification;
|
206 |
-
window.getOpenPlatformUser = () => userProfile;
|
207 |
-
|
208 |
-
// Initialize when DOM is ready
|
209 |
-
document.addEventListener('DOMContentLoaded', initOpenPlatform);
|
210 |
-
|
211 |
-
// Handle iframe communication
|
212 |
-
window.addEventListener('message', function(event) {
|
213 |
-
// Allow messages from the Gradio app domain
|
214 |
-
if (event.origin !== new URL(GRADIO_APP_URL).origin) return;
|
215 |
-
|
216 |
-
// Handle messages from the Gradio app
|
217 |
-
if (event.data.type === 'openplatform-notification') {
|
218 |
-
sendNotification(event.data.message, event.data.icon, event.data.color);
|
219 |
-
}
|
220 |
});
|
221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
</body>
|
223 |
-
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
+
<title>Dynamic Component Factory - OpenPlatform</title>
|
7 |
+
<script src="https://cdn.componentator.com/total4.js/4.0.0/total4.js"></script>
|
8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
|
9 |
+
<!-- Add Gradio embed script -->
|
10 |
+
<script type="module" src="https://gradio.s3-us-west-2.amazonaws.com/3.1.4/gradio.js"></script>
|
11 |
+
<style>
|
12 |
+
body { margin:0; padding:0; font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif; background:#f5f5f5; overflow:hidden; }
|
13 |
+
.loading { display:flex; align-items:center; justify-content:center; height:100vh; flex-direction:column; background:linear-gradient(135deg,#667eea 0%,#764ba2 100%); color:white; }
|
14 |
+
.loading-spinner { width:50px; height:50px; border:4px solid rgba(255,255,255,0.3); border-top:4px solid white; border-radius:50%; animation:spin 1s linear infinite; margin-bottom:20px; }
|
15 |
+
@keyframes spin { 0%{transform:rotate(0deg);} 100%{transform:rotate(360deg);} }
|
16 |
+
.error { display:flex; align-items:center; justify-content:center; height:100vh; flex-direction:column; background:#f8f9fa; color:#dc3545; text-align:center; padding:20px; }
|
17 |
+
.app-container { width:100vw; height:100vh; position:relative; display:none; }
|
18 |
+
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</head>
|
20 |
<body>
|
21 |
+
<div id="loading" class="loading">
|
22 |
+
<div class="loading-spinner"></div>
|
23 |
+
<h2>Dynamic Component Factory</h2>
|
24 |
+
<p>Loading OpenPlatform integration...</p>
|
25 |
+
</div>
|
26 |
+
|
27 |
+
<div id="error" class="error" style="display:none;">
|
28 |
+
<h2>Authentication Error</h2>
|
29 |
+
<p id="error-message">Unable to verify OpenPlatform credentials</p>
|
30 |
+
</div>
|
31 |
+
|
32 |
+
<div id="app-container" class="app-container">
|
33 |
+
<!-- Replace iframe with gradio-app -->
|
34 |
+
<gradio-app
|
35 |
+
id="gradio-app"
|
36 |
+
space="devmanmikey/dynamic-comp-factory"
|
37 |
+
theme="default"
|
38 |
+
style="width:100%; height:100vh;">
|
39 |
+
</gradio-app>
|
40 |
+
</div>
|
41 |
+
|
42 |
+
<script>
|
43 |
+
const REQ_TOKEN = '1n9bkxk4qcxdiu0frs4oqbfvk3ikkbaulmt1xp8hk';
|
44 |
+
const RES_TOKEN = '7nk3iw88wvj6hn95dxko1x4tl86pd8km801vp5p7v';
|
45 |
+
let userProfile = null;
|
46 |
+
|
47 |
+
async function initOpenPlatform() {
|
48 |
+
try {
|
49 |
+
const urlParams = new URLSearchParams(window.location.search);
|
50 |
+
const openplatform = urlParams.get('openplatform');
|
51 |
+
if (!openplatform) throw new Error('No OpenPlatform parameter found');
|
52 |
+
|
53 |
+
const data = openplatform.split('~');
|
54 |
+
if (data.length !== 2) throw new Error('Invalid OpenPlatform format');
|
55 |
+
const [tokenUrl, signature] = data;
|
56 |
+
|
57 |
+
const expectedSignature = CryptoJS.MD5(tokenUrl + REQ_TOKEN).toString();
|
58 |
+
if (expectedSignature !== signature) throw new Error('Invalid signature');
|
59 |
+
|
60 |
+
const responseSignature = CryptoJS.MD5(signature + RES_TOKEN).toString();
|
61 |
+
const response = await fetch(tokenUrl, {
|
62 |
+
method: 'GET',
|
63 |
+
headers: { 'x-token': responseSignature, 'Content-Type': 'application/json' }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
});
|
65 |
+
if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
66 |
+
|
67 |
+
userProfile = await response.json();
|
68 |
+
window.openplatformUser = userProfile;
|
69 |
+
|
70 |
+
// Show the app
|
71 |
+
document.getElementById('loading').style.display = 'none';
|
72 |
+
document.getElementById('app-container').style.display = 'block';
|
73 |
+
|
74 |
+
} catch (error) {
|
75 |
+
console.error('OpenPlatform initialization error:', error);
|
76 |
+
document.getElementById('loading').style.display = 'none';
|
77 |
+
document.getElementById('error').style.display = 'flex';
|
78 |
+
document.getElementById('error-message').textContent = error.message;
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
async function sendNotification(message, icon = 'ti ti-code', color = '#667eea') {
|
83 |
+
if (!userProfile || !userProfile.notify) return;
|
84 |
+
try {
|
85 |
+
const notifyUrl = userProfile.notify;
|
86 |
+
const signature = CryptoJS.MD5((notifyUrl + REQ_TOKEN) + RES_TOKEN).toString();
|
87 |
+
const notification = { body: message, icon, color, path: window.location.pathname };
|
88 |
+
await fetch(notifyUrl, {
|
89 |
+
method: 'POST',
|
90 |
+
headers: { 'x-token': signature, 'Content-Type': 'application/json' },
|
91 |
+
body: JSON.stringify(notification)
|
92 |
+
});
|
93 |
+
} catch (err) { console.error('Error sending notification:', err); }
|
94 |
+
}
|
95 |
+
|
96 |
+
window.sendOpenPlatformNotification = sendNotification;
|
97 |
+
window.getOpenPlatformUser = () => userProfile;
|
98 |
+
document.addEventListener('DOMContentLoaded', initOpenPlatform);
|
99 |
+
</script>
|
100 |
</body>
|
101 |
+
</html>
|