-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-client.html
More file actions
479 lines (405 loc) · 14.4 KB
/
test-client.html
File metadata and controls
479 lines (405 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Instagram Poster API - Test Client</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background: white;
border-radius: 12px;
padding: 40px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
h1 {
color: #333;
margin-bottom: 10px;
font-size: 28px;
}
.subtitle {
color: #666;
margin-bottom: 30px;
}
.section {
margin-bottom: 40px;
padding-bottom: 40px;
border-bottom: 2px solid #f0f0f0;
}
.section:last-child {
border-bottom: none;
}
h2 {
color: #667eea;
margin-bottom: 20px;
font-size: 20px;
}
label {
display: block;
margin-bottom: 8px;
color: #333;
font-weight: 500;
}
input, textarea {
width: 100%;
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 14px;
margin-bottom: 15px;
font-family: inherit;
transition: border-color 0.3s;
}
input:focus, textarea:focus {
outline: none;
border-color: #667eea;
}
textarea {
resize: vertical;
min-height: 100px;
}
button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 14px 28px;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: 600;
transition: transform 0.2s, box-shadow 0.2s;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}
button:active {
transform: translateY(0);
}
button:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.response {
margin-top: 20px;
padding: 15px;
border-radius: 8px;
display: none;
white-space: pre-wrap;
font-family: 'Courier New', monospace;
font-size: 13px;
}
.response.success {
background: #d4edda;
border: 2px solid #c3e6cb;
color: #155724;
display: block;
}
.response.error {
background: #f8d7da;
border: 2px solid #f5c6cb;
color: #721c24;
display: block;
}
.file-input-wrapper {
position: relative;
overflow: hidden;
display: inline-block;
width: 100%;
}
.file-input-wrapper input[type=file] {
position: absolute;
left: -9999px;
}
.file-input-label {
display: block;
padding: 12px;
background: #f8f9fa;
border: 2px dashed #667eea;
border-radius: 8px;
text-align: center;
cursor: pointer;
transition: background 0.3s;
margin-bottom: 15px;
}
.file-input-label:hover {
background: #e9ecef;
}
.file-name {
margin-top: 10px;
color: #667eea;
font-weight: 600;
}
.info-box {
background: #e7f3ff;
border-left: 4px solid #667eea;
padding: 15px;
margin-bottom: 20px;
border-radius: 4px;
}
.info-box p {
margin: 5px 0;
color: #333;
font-size: 14px;
}
</style>
</head>
<body>
<div class="container">
<h1>🚀 Social Poster API</h1>
<p class="subtitle">Test Client Interface - Instagram & Twitter</p>
<!-- Browser Configuration Section -->
<div class="section">
<h2>1. Configure Browser</h2>
<div class="info-box">
<p><strong>Windows Default Paths:</strong></p>
<p>📁 Executable: <code>C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe</code></p>
<p>👤 User Data: <code>C:\Users\YourUsername\AppData\Local\BraveSoftware\Brave-Browser\User Data</code></p>
</div>
<label for="executablePath">Browser Executable Path:</label>
<input type="text" id="executablePath"
value="C:\Users\dhuec\AppData\Local\BraveSoftware\Brave-Browser\Application\brave.exe"
placeholder="Path to brave.exe">
<label for="userDataDir">User Data Directory:</label>
<input type="text" id="userDataDir"
value="C:\Users\dhuec\AppData\Local\BraveSoftware\Brave-Browser\User Data"
placeholder="Path to User Data folder">
<button onclick="setConfig()">Set Configuration</button>
<div id="configResponse" class="response"></div>
</div>
<!-- Post to Instagram Section -->
<div class="section">
<h2>2. Post to Instagram</h2>
<div class="file-input-wrapper">
<input type="file" id="imageFile" accept="image/*" onchange="updateFileName('imageFile', 'fileName')">
<label for="imageFile" class="file-input-label">
📸 Click to select image (JPEG, PNG, WEBP)
</label>
</div>
<div id="fileName" class="file-name"></div>
<label for="caption">Caption:</label>
<textarea id="caption" placeholder="Enter your Instagram caption here... You can use emojis! 🎉"></textarea>
<button onclick="postToInstagram()">Post to Instagram</button>
<div id="postResponse" class="response"></div>
</div>
<!-- Post to Twitter Section -->
<div class="section">
<h2>3. Post to Twitter</h2>
<div class="file-input-wrapper">
<input type="file" id="twitterImageFile" accept="image/*" onchange="updateFileName('twitterImageFile', 'twitterFileName')">
<label for="twitterImageFile" class="file-input-label">
🖼️ Click to select image (Optional - JPEG, PNG, GIF, WEBP)
</label>
</div>
<div id="twitterFileName" class="file-name"></div>
<p style="text-align: center; color: #666; margin: 10px 0;">— OR —</p>
<label for="twitterImageUrl">Image URL (Optional):</label>
<input type="text" id="twitterImageUrl" placeholder="https://example.com/image.jpg">
<label for="tweetText">Tweet Text: <span id="charCount" style="color: #667eea; float: right;">0/∞</span></label>
<textarea id="tweetText" placeholder="What's happening? 🐦 (Auto-threads if >280 chars)" oninput="updateCharCount()"></textarea>
<p style="color: #666; font-size: 13px; margin-top: -10px; margin-bottom: 15px;">
💡 Tip: Text longer than 280 characters will automatically be split into a thread
</p>
<button onclick="postToTwitter()">Post to Twitter</button>
<div id="twitterPostResponse" class="response"></div>
</div>
<!-- Get Configuration Section -->
<div class="section">
<h2>4. View Current Configuration</h2>
<button onclick="getConfig()">Get Configuration</button>
<div id="getConfigResponse" class="response"></div>
</div>
</div>
<script>
const API_BASE_URL = 'http://localhost:5500/api';
function updateFileName(inputId, displayId) {
const fileInput = document.getElementById(inputId);
const fileNameDiv = document.getElementById(displayId);
if (fileInput.files.length > 0) {
const file = fileInput.files[0];
const sizeMB = (file.size / (1024 * 1024)).toFixed(2);
fileNameDiv.textContent = `Selected: ${file.name} (${sizeMB} MB)`;
} else {
fileNameDiv.textContent = '';
}
}
function updateCharCount() {
const tweetText = document.getElementById('tweetText').value;
const charCount = document.getElementById('charCount');
const length = tweetText.length;
if (length > 280) {
const estimatedTweets = Math.ceil(length / 270);
charCount.textContent = `${length} chars (~${estimatedTweets} tweets)`;
charCount.style.color = '#667eea';
} else if (length > 260) {
charCount.textContent = `${length}/280`;
charCount.style.color = '#ffc107';
} else {
charCount.textContent = `${length}/280`;
charCount.style.color = '#667eea';
}
}
async function setConfig() {
const responseDiv = document.getElementById('configResponse');
responseDiv.className = 'response';
responseDiv.textContent = 'Setting configuration...';
try {
const executablePath = document.getElementById('executablePath').value;
const userDataDir = document.getElementById('userDataDir').value;
const response = await fetch(`${API_BASE_URL}/browser/config`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
executablePath,
userDataDir
})
});
const data = await response.json();
if (data.success) {
responseDiv.className = 'response success';
responseDiv.textContent = '✅ ' + JSON.stringify(data, null, 2);
} else {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ ' + JSON.stringify(data, null, 2);
}
} catch (error) {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ Error: ' + error.message;
}
}
async function getConfig() {
const responseDiv = document.getElementById('getConfigResponse');
responseDiv.className = 'response';
responseDiv.textContent = 'Fetching configuration...';
try {
const response = await fetch(`${API_BASE_URL}/browser/config`);
const data = await response.json();
if (data.success) {
responseDiv.className = 'response success';
responseDiv.textContent = '✅ ' + JSON.stringify(data, null, 2);
} else {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ ' + JSON.stringify(data, null, 2);
}
} catch (error) {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ Error: ' + error.message;
}
}
async function postToInstagram() {
const responseDiv = document.getElementById('postResponse');
const fileInput = document.getElementById('imageFile');
const caption = document.getElementById('caption').value;
if (!fileInput.files.length) {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ Please select an image file';
return;
}
if (!caption) {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ Please enter a caption';
return;
}
responseDiv.className = 'response';
responseDiv.textContent = 'Posting to Instagram... This may take a minute...';
try {
const formData = new FormData();
formData.append('image', fileInput.files[0]);
formData.append('caption', caption);
const response = await fetch(`${API_BASE_URL}/instagram/post`, {
method: 'POST',
body: formData
});
const data = await response.json();
if (data.success) {
responseDiv.className = 'response success';
responseDiv.textContent = '✅ ' + JSON.stringify(data, null, 2);
} else {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ ' + JSON.stringify(data, null, 2);
}
} catch (error) {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ Error: ' + error.message;
}
}
async function postToTwitter() {
const responseDiv = document.getElementById('twitterPostResponse');
const fileInput = document.getElementById('twitterImageFile');
const imageUrlInput = document.getElementById('twitterImageUrl');
const tweetText = document.getElementById('tweetText').value;
if (!tweetText) {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ Please enter tweet text';
return;
}
const hasFile = fileInput.files.length > 0;
const hasUrl = imageUrlInput.value.trim() !== '';
if (hasFile && hasUrl) {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ Please choose either file upload OR image URL, not both';
return;
}
responseDiv.className = 'response';
const threadInfo = tweetText.length > 280 ? ' (creating thread...)' : '';
responseDiv.textContent = `Posting to Twitter${threadInfo}... This may take a minute...`;
try {
let response;
if (hasUrl) {
response = await fetch(`${API_BASE_URL}/twitter/post-with-url`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: tweetText,
imageUrl: imageUrlInput.value.trim()
})
});
} else {
const formData = new FormData();
formData.append('text', tweetText);
if (hasFile) {
formData.append('image', fileInput.files[0]);
}
response = await fetch(`${API_BASE_URL}/twitter/post`, {
method: 'POST',
body: formData
});
}
const data = await response.json();
if (data.success) {
responseDiv.className = 'response success';
responseDiv.textContent = '✅ ' + JSON.stringify(data, null, 2);
document.getElementById('tweetText').value = '';
document.getElementById('twitterImageFile').value = '';
document.getElementById('twitterImageUrl').value = '';
document.getElementById('twitterFileName').textContent = '';
updateCharCount();
} else {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ ' + JSON.stringify(data, null, 2);
}
} catch (error) {
responseDiv.className = 'response error';
responseDiv.textContent = '❌ Error: ' + error.message;
}
}
</script>
</body>
</html>