broadfield-dev commited on
Commit
d15735a
·
verified ·
1 Parent(s): 122c74c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +132 -31
index.html CHANGED
@@ -2,65 +2,166 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
- <title>Secure Decoder Client Demo</title>
 
6
  <style>
7
- body { font-family: sans-serif; max-width: 700px; margin: 2rem auto; }
8
- .container { display: flex; flex-direction: column; gap: 1rem; border: 1px solid #ccc; padding: 1.5rem; border-radius: 8px; }
9
- button { font-size: 1rem; padding: 0.5rem 1rem; cursor: pointer; }
10
- #result { background: #f0f0f0; padding: 1rem; border-radius: 5px; white-space: pre-wrap; font-family: monospace; }
11
- input[type="text"] { width: 100%; box-sizing: border-box; padding: 8px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  </style>
13
  </head>
14
  <body>
15
- <h1>Client for Secure Decoder Plugin</h1>
16
- <p>This demo sends an encrypted image to a secure backend API. The backend holds the private key and returns the decrypted data.</p>
17
 
18
- <div class="container">
19
- <div>
20
- <label for="api-url"><b>Your Deployed API Endpoint URL:</b></label>
21
- <input type="text" id="api-url" placeholder="e.g., https://your-plugin.vercel.app/api/decode">
22
- </div>
23
- <div>
24
- <label for="image-upload"><b>Upload Image (Encrypted with Plugin's Public Key):</b></label>
 
25
  <input type="file" id="image-upload" accept="image/png">
26
- </div>
 
27
  <button id="submit-button">Send to Plugin for Decoding</button>
28
- <div>
 
29
  <h3>Result from Server:</h3>
30
- <div id="result">...</div>
31
- </div>
32
- </div>
33
 
34
  <script>
35
  const apiUrlInput = document.getElementById('api-url');
36
  const imageInput = document.getElementById('image-upload');
37
  const submitButton = document.getElementById('submit-button');
38
- const resultDiv = document.getElementById('result');
39
 
40
  submitButton.addEventListener('click', async () => {
41
  const file = imageInput.files[0];
42
  const apiUrl = apiUrlInput.value.trim();
43
 
44
- if (!file) { resultDiv.textContent = 'Please select an image file.'; return; }
45
- if (!apiUrl) { resultDiv.textContent = 'Please provide the API endpoint URL.'; return; }
 
 
 
 
 
 
 
 
 
46
 
47
- resultDiv.textContent = 'Uploading and decoding...';
 
 
48
  submitButton.disabled = true;
 
49
 
 
50
  const formData = new FormData();
51
- formData.append('authImage', file);
52
 
53
  try {
54
- const response = await fetch(apiUrl, { method: 'POST', body: formData });
 
 
 
 
55
  const result = await response.json();
56
- if (!response.ok) throw new Error(result.error);
57
- resultDiv.style.color = 'green';
58
- resultDiv.textContent = JSON.stringify(result.data, null, 2);
 
 
 
 
 
 
 
59
  } catch (error) {
60
- resultDiv.style.color = 'red';
61
- resultDiv.textContent = `Error: ${error.message}`;
 
 
62
  } finally {
 
63
  submitButton.disabled = false;
 
64
  }
65
  });
66
  </script>
 
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>API Client for Secure Decoder Plugin</title>
7
  <style>
8
+ :root {
9
+ --primary-color: #3b82f6;
10
+ --primary-hover: #2563eb;
11
+ --border-color: #d1d5db;
12
+ --background-color: #f9fafb;
13
+ --text-color: #1f2937;
14
+ --error-color: #ef4444;
15
+ --success-color: #22c55e;
16
+ }
17
+ body {
18
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
19
+ line-height: 1.6;
20
+ max-width: 700px;
21
+ margin: 2rem auto;
22
+ padding: 0 1rem;
23
+ color: var(--text-color);
24
+ }
25
+ main {
26
+ display: flex;
27
+ flex-direction: column;
28
+ gap: 1.5rem;
29
+ border: 1px solid var(--border-color);
30
+ padding: 1.5rem;
31
+ border-radius: 0.5rem;
32
+ background-color: white;
33
+ }
34
+ h1 {
35
+ color: #111827;
36
+ text-align: center;
37
+ }
38
+ section {
39
+ display: flex;
40
+ flex-direction: column;
41
+ gap: 0.5rem;
42
+ }
43
+ label {
44
+ font-weight: 600;
45
+ }
46
+ input[type="text"], input[type="file"] {
47
+ font-size: 1rem;
48
+ padding: 0.5rem 0.75rem;
49
+ border: 1px solid var(--border-color);
50
+ border-radius: 0.375rem;
51
+ }
52
+ button {
53
+ font-size: 1rem;
54
+ font-weight: 600;
55
+ padding: 0.75rem 1rem;
56
+ cursor: pointer;
57
+ border: none;
58
+ border-radius: 0.375rem;
59
+ background-color: var(--primary-color);
60
+ color: white;
61
+ transition: background-color 0.2s;
62
+ }
63
+ button:hover:not(:disabled) {
64
+ background-color: var(--primary-hover);
65
+ }
66
+ button:disabled {
67
+ background-color: #9ca3af;
68
+ cursor: not-allowed;
69
+ }
70
+ #result-output {
71
+ background: var(--background-color);
72
+ padding: 1rem;
73
+ border-radius: 5px;
74
+ white-space: pre-wrap;
75
+ word-wrap: break-word;
76
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
77
+ min-height: 60px;
78
+ border: 1px solid var(--border-color);
79
+ }
80
+ .result-error { color: var(--error-color); }
81
+ .result-success { color: var(--success-color); }
82
  </style>
83
  </head>
84
  <body>
85
+ <h1>Secure Decoder Plugin Client</h1>
86
+ <p style="text-align: center;">Use this page to test your deployed Hugging Face API. It sends an encrypted image to your secure server endpoint for decoding.</p>
87
 
88
+ <main>
89
+ <section>
90
+ <label for="api-url">1. Your Deployed API Endpoint URL:</label>
91
+ <input type="text" id="api-url" placeholder="https://your-space-name.hf.space/api/decode">
92
+ </section>
93
+
94
+ <section>
95
+ <label for="image-upload">2. Upload Image (Encrypted with Plugin's Public Key):</label>
96
  <input type="file" id="image-upload" accept="image/png">
97
+ </section>
98
+
99
  <button id="submit-button">Send to Plugin for Decoding</button>
100
+
101
+ <section>
102
  <h3>Result from Server:</h3>
103
+ <div id="result-output">Awaiting input...</div>
104
+ </section>
105
+ </main>
106
 
107
  <script>
108
  const apiUrlInput = document.getElementById('api-url');
109
  const imageInput = document.getElementById('image-upload');
110
  const submitButton = document.getElementById('submit-button');
111
+ const resultOutput = document.getElementById('result-output');
112
 
113
  submitButton.addEventListener('click', async () => {
114
  const file = imageInput.files[0];
115
  const apiUrl = apiUrlInput.value.trim();
116
 
117
+ // --- Input Validation ---
118
+ if (!apiUrl) {
119
+ resultOutput.textContent = 'Error: Please provide the API endpoint URL.';
120
+ resultOutput.className = 'result-error';
121
+ return;
122
+ }
123
+ if (!file) {
124
+ resultOutput.textContent = 'Error: Please select an image file to upload.';
125
+ resultOutput.className = 'result-error';
126
+ return;
127
+ }
128
 
129
+ // --- UI Feedback for Loading State ---
130
+ resultOutput.textContent = 'Uploading and decoding...';
131
+ resultOutput.className = '';
132
  submitButton.disabled = true;
133
+ submitButton.textContent = 'Processing...';
134
 
135
+ // --- Prepare and Send the Request ---
136
  const formData = new FormData();
137
+ formData.append('authImage', file); // 'authImage' must match the server's expected field name
138
 
139
  try {
140
+ const response = await fetch(apiUrl, {
141
+ method: 'POST',
142
+ body: formData,
143
+ });
144
+
145
  const result = await response.json();
146
+
147
+ if (!response.ok) {
148
+ // If the server returns an error (like 400 or 500), throw it
149
+ throw new Error(result.error || `Server responded with status ${response.status}`);
150
+ }
151
+
152
+ // --- Handle Success ---
153
+ resultOutput.className = 'result-success';
154
+ resultOutput.textContent = `✅ Success! Decoded Data:\n\n${JSON.stringify(result.data, null, 2)}`;
155
+
156
  } catch (error) {
157
+ // --- Handle Failure (Network error or server error) ---
158
+ resultOutput.className = 'result-error';
159
+ resultOutput.textContent = `❌ API Request Failed:\n\n${error.message}`;
160
+ console.error('API Error:', error);
161
  } finally {
162
+ // --- Reset UI ---
163
  submitButton.disabled = false;
164
+ submitButton.textContent = 'Send to Plugin for Decoding';
165
  }
166
  });
167
  </script>