-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-user-flow.html
More file actions
375 lines (320 loc) · 12.2 KB
/
Copy pathadmin-user-flow.html
File metadata and controls
375 lines (320 loc) · 12.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin-User Split Workflow Demo</title>
<script src="artifact-client.js"></script>
<style>
:root {
--admin-bg: #1a1c23;
--user-bg: #f8fafc;
--accent: #6366f1;
--accent-hover: #4f46e5;
--text-light: #e2e8f0;
--text-dark: #1e293b;
--glass: rgba(255, 255, 255, 0.1);
--border: rgba(255, 255, 255, 0.2);
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
margin: 0;
min-height: 100vh;
display: grid;
grid-template-columns: 1fr 1fr;
}
/* Admin Side */
.admin-panel {
background-color: var(--admin-bg);
color: var(--text-light);
padding: 2rem;
border-right: 1px solid #334155;
}
/* User Side */
.user-panel {
background-color: var(--user-bg);
color: var(--text-dark);
padding: 2rem;
}
h2 {
font-weight: 700;
margin-bottom: 2rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.badge {
font-size: 0.8rem;
padding: 0.2rem 0.5rem;
border-radius: 4px;
text-transform: uppercase;
}
.admin-badge {
background: #ef4444;
color: white;
}
.user-badge {
background: #22c55e;
color: white;
}
.card {
background: var(--glass);
backdrop-filter: blur(10px);
border: 1px solid var(--border);
border-radius: 12px;
padding: 1.5rem;
margin-bottom: 2rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.user-panel .card {
background: white;
border: 1px solid #e2e8f0;
}
label {
display: block;
margin-bottom: 0.5rem;
font-size: 0.9rem;
opacity: 0.8;
}
input[type="text"],
input[type="number"] {
width: 100%;
padding: 0.75rem;
border-radius: 8px;
border: 1px solid;
margin-bottom: 1rem;
background: rgba(255, 255, 255, 0.05);
color: inherit;
box-sizing: border-box;
}
.user-panel input {
background: #fff;
border-color: #cbd5e1;
}
button {
background: var(--accent);
color: white;
border: none;
padding: 0.75rem 1.5rem;
border-radius: 8px;
cursor: pointer;
font-weight: 600;
transition: all 0.2s;
width: 100%;
}
button:hover {
background: var(--accent-hover);
transform: translateY(-1px);
}
.result-box {
background: rgba(0, 0, 0, 0.2);
padding: 1rem;
border-radius: 8px;
margin-top: 1rem;
font-family: monospace;
font-size: 0.85rem;
word-break: break-all;
display: none;
}
.user-panel .result-box {
background: #f1f5f9;
color: #334155;
}
.copy-btn {
background: transparent;
border: 1px solid currentColor;
padding: 0.2rem 0.5rem;
font-size: 0.7rem;
width: auto;
margin-top: 0.5rem;
}
.drop-zone {
border: 2px dashed #cbd5e1;
border-radius: 8px;
padding: 2rem;
text-align: center;
margin-bottom: 1rem;
transition: all 0.2s;
cursor: pointer;
}
.drop-zone:hover {
border-color: var(--accent);
background: #f8fafc;
}
.progress-bar {
height: 6px;
background: #e2e8f0;
border-radius: 3px;
margin-top: 1rem;
overflow: hidden;
display: none;
}
.progress-fill {
height: 100%;
background: var(--accent);
width: 0%;
transition: width 0.2s;
}
</style>
</head>
<body>
<!-- Admin Panel -->
<div class="admin-panel">
<h2><span class="badge admin-badge">Ca</span> Admin User</h2>
<p>Generates secure tokens for file access.</p>
<!-- Generate Upload Token -->
<div class="card">
<h3>🔑 Generate Upload Link</h3>
<label>Max Uploads</label>
<input type="number" id="maxUploads" value="1" min="1">
<button onclick="generateUploadLink()">Create Upload Link</button>
<div id="uploadTokenResult" class="result-box">
<div><strong>Token URL:</strong></div>
<div id="uploadUrlDisplay"></div>
<button class="copy-btn" onclick="copyToClipboard('uploadUrlDisplay')">Copy Link</button>
</div>
</div>
<!-- Generate Download Token -->
<div class="card">
<h3>🔑 Generate Download Link</h3>
<label>Artifact UUID</label>
<input type="text" id="artifactUuid" placeholder="Enter UUID (e.g., from successful upload)">
<label>Max Downloads</label>
<input type="number" id="maxDownloads" value="1" min="1">
<button onclick="generateDownloadLink()">Create Download Link</button>
<div id="downloadTokenResult" class="result-box">
<div><strong>Token URL:</strong></div>
<div id="downloadUrlDisplay"></div>
<button class="copy-btn" onclick="copyToClipboard('downloadUrlDisplay')">Copy Link</button>
</div>
</div>
</div>
<!-- User Panel -->
<div class="user-panel">
<h2><span class="badge user-badge">Ce</span> End User</h2>
<p>Uses tokens to upload or download files.</p>
<!-- Upload File -->
<div class="card">
<h3>📤 Upload File</h3>
<label>Paste Upload Token URL</label>
<input type="text" id="userUploadUrl" placeholder="http://10.188.157.24/artifacts/upload/...">
<div class="drop-zone" onclick="document.getElementById('fileInput').click()">
<p>Click to select file</p>
<input type="file" id="fileInput" style="display: none" onchange="handleFileSelect(this)">
<div id="fileName" style="font-weight: bold; margin-top: 0.5rem;"></div>
</div>
<div class="progress-bar" id="progressBar">
<div class="progress-fill" id="progressFill"></div>
</div>
<div style="display: flex; gap: 10px;">
<button id="uploadBtn" onclick="performUpload()">Upload Now</button>
<button id="cancelBtn" onclick="cancelUpload()"
style="background: #ef4444; display: none;">Cancel</button>
</div>
<div id="uploadResult" class="result-box" style="display:none; color: green;">
✅ Upload Successful!<br>
<strong>UUID:</strong> <span id="newUuid"></span>
</div>
</div>
<!-- Download File -->
<div class="card">
<h3>📥 Download File</h3>
<label>Paste Download Token URL</label>
<input type="text" id="userDownloadUrl" placeholder="http://10.188.157.24/artifacts/downloads/...">
<button onclick="performDownload()">Download Now</button>
</div>
</div>
<script>
const client = new ArtifactClient('http://10.188.157.24:8080');
// --- Admin Functions ---
async function generateUploadLink() {
const max = document.getElementById('maxUploads').value;
try {
const result = await client.createUploadToken({ maxUploads: parseInt(max) });
document.getElementById('uploadUrlDisplay').textContent = result.upload_url;
document.getElementById('uploadTokenResult').style.display = 'block';
} catch (err) {
alert('Error: ' + err.message);
}
}
async function generateDownloadLink() {
const uuid = document.getElementById('artifactUuid').value.trim();
const max = document.getElementById('maxDownloads').value;
if (!uuid) return alert('Please enter an Artifact UUID');
try {
const result = await client.createDownloadToken(uuid, { maxDownloads: parseInt(max) });
document.getElementById('downloadUrlDisplay').textContent = result.presigned_url; // Wait, genDownloadPresignedURL returns `presigned_url`?
// Actually the API returns { token, presigned_url }. The presigned_url IS the token access URL.
document.getElementById('downloadTokenResult').style.display = 'block';
} catch (err) {
alert('Error: ' + err.message);
}
}
function copyToClipboard(elementId) {
const text = document.getElementById(elementId).textContent;
navigator.clipboard.writeText(text);
alert('Copied to clipboard!');
}
// --- User Functions ---
let selectedFile = null;
let uploadController = null;
function handleFileSelect(input) {
if (input.files.length > 0) {
selectedFile = input.files[0];
document.getElementById('fileName').textContent = selectedFile.name;
}
}
async function performUpload() {
const tokenUrl = document.getElementById('userUploadUrl').value.trim();
if (!tokenUrl || !selectedFile) return alert('Please provide a Token URL and select a file');
const progressBar = document.getElementById('progressBar');
const progressFill = document.getElementById('progressFill');
const resultBox = document.getElementById('uploadResult');
const uploadBtn = document.getElementById('uploadBtn');
const cancelBtn = document.getElementById('cancelBtn');
progressBar.style.display = 'block';
resultBox.style.display = 'none';
uploadBtn.style.display = 'none';
cancelBtn.style.display = 'block';
// Create new AbortController
uploadController = new AbortController();
try {
const result = await client.uploadFileWithTokenUrl(tokenUrl, selectedFile, (percent) => {
progressFill.style.width = percent + '%';
progressFill.textContent = percent + '%';
}, { signal: uploadController.signal });
document.getElementById('newUuid').textContent = result.uuid;
resultBox.style.display = 'block';
// Auto-fill the admin uuid field for convenience
document.getElementById('artifactUuid').value = result.uuid;
} catch (err) {
if (err.name === 'AbortError') {
alert('Upload cancelled by user');
} else {
alert('Upload failed: ' + err.message);
}
progressFill.style.width = '0%';
progressFill.textContent = '';
} finally {
uploadBtn.style.display = 'block';
cancelBtn.style.display = 'none';
uploadController = null;
}
}
function cancelUpload() {
if (uploadController) {
uploadController.abort();
}
}
async function performDownload() {
const tokenUrl = document.getElementById('userDownloadUrl').value.trim();
if (!tokenUrl) return alert('Please provide a Token URL');
try {
await client.downloadFileWithTokenUrl(tokenUrl);
} catch (err) {
alert('Download failed: ' + err.message);
}
}
</script>
</body>
</html>