Reaperxxxx commited on
Commit
1e7d8bd
·
verified ·
1 Parent(s): 280f577

Update public/chat.html

Browse files
Files changed (1) hide show
  1. public/chat.html +38 -0
public/chat.html CHANGED
@@ -148,6 +148,44 @@
148
  }
149
  });
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  // Check if the user is already verified
152
  if (userKey) {
153
  verifyKey(userKey).then((isValid) => {
 
148
  }
149
  });
150
 
151
+ sendImageButton.addEventListener('click', () => {
152
+ imageInput.click(); // Open file picker when the camera button is clicked
153
+ });
154
+
155
+ imageInput.addEventListener('change', async () => {
156
+ const file = imageInput.files[0];
157
+ if (!file) return;
158
+
159
+ const formData = new FormData();
160
+ formData.append('image', file); // Append the selected image
161
+ formData.append('jid', jid); // Add recipient JID
162
+ formData.append('caption', messageInput.value.trim()); // Optional caption
163
+
164
+ try {
165
+ const res = await fetch('/upload-image', {
166
+ method: 'POST',
167
+ headers: {
168
+ Authorization: `Bearer ${userKey}`, // Include user key for authentication
169
+ },
170
+ body: formData,
171
+ });
172
+
173
+ if (res.ok) {
174
+ imageInput.value = ''; // Clear file input
175
+ messageInput.value = ''; // Clear caption input
176
+ replyTo = null;
177
+ replyPreview.style.display = 'none';
178
+ } else {
179
+ const errorText = await res.text();
180
+ console.error('Failed to send image:', errorText);
181
+ alert(`Error: ${errorText}`);
182
+ }
183
+ } catch (error) {
184
+ console.error('Failed to send image:', error);
185
+ alert('An error occurred while sending the image.');
186
+ }
187
+ });
188
+
189
  // Check if the user is already verified
190
  if (userKey) {
191
  verifyKey(userKey).then((isValid) => {