aboutsummaryrefslogtreecommitdiff
path: root/weed/admin/view/app/file_browser.templ
blob: 83db7df0f175519de44a2910096315045d07588b (plain)
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
package app

import (
	"fmt"
	"path/filepath"
	"strings"
	"github.com/seaweedfs/seaweedfs/weed/admin/dash"
)

templ FileBrowser(data dash.FileBrowserData) {
	<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
		<h1 class="h2">
			if data.IsBucketPath && data.BucketName != "" {
				<i class="fas fa-cube me-2"></i>S3 Bucket: {data.BucketName}
			} else {
				<i class="fas fa-folder-open me-2"></i>File Browser
			}
		</h1>
		<div class="btn-toolbar mb-2 mb-md-0">
			<div class="btn-group me-2">
				if data.IsBucketPath && data.BucketName != "" {
					<a href="/object-store/buckets" class="btn btn-sm btn-outline-secondary">
						<i class="fas fa-arrow-left me-1"></i>Back to Buckets
					</a>
				}
				<button type="button" class="btn btn-sm btn-outline-primary" onclick="createFolder()">
					<i class="fas fa-folder-plus me-1"></i>New Folder
				</button>
				<button type="button" class="btn btn-sm btn-outline-secondary" onclick="uploadFile()">
					<i class="fas fa-upload me-1"></i>Upload
				</button>
				<button type="button" class="btn btn-sm btn-outline-danger" id="deleteSelectedBtn" onclick="confirmDeleteSelected()" style="display: none;">
					<i class="fas fa-trash me-1"></i>Delete Selected
				</button>
				<button type="button" class="btn btn-sm btn-outline-info" onclick="exportFileList()">
					<i class="fas fa-download me-1"></i>Export
				</button>
			</div>
		</div>
	</div>

	<!-- Breadcrumb Navigation -->
	<nav aria-label="breadcrumb" class="mb-3">
		<ol class="breadcrumb">
			for i, crumb := range data.Breadcrumbs {
				if i == len(data.Breadcrumbs)-1 {
					<li class="breadcrumb-item active" aria-current="page">
						<i class="fas fa-folder me-1"></i>{ crumb.Name }
					</li>
				} else {
					<li class="breadcrumb-item">
						<a href={ templ.SafeURL(fmt.Sprintf("/files?path=%s", crumb.Path)) } class="text-decoration-none">
							if crumb.Name == "Root" {
								<i class="fas fa-home me-1"></i>
							} else {
								<i class="fas fa-folder me-1"></i>
							}
							{ crumb.Name }
						</a>
					</li>
				}
			}
		</ol>
	</nav>

	<!-- Summary Cards -->
	<div class="row mb-4">
		<div class="col-xl-3 col-md-6 mb-4">
			<div class="card border-left-primary shadow h-100 py-2">
				<div class="card-body">
					<div class="row no-gutters align-items-center">
						<div class="col mr-2">
							<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
								Total Entries
							</div>
							<div class="h5 mb-0 font-weight-bold text-gray-800">
								{ fmt.Sprintf("%d", data.TotalEntries) }
							</div>
						</div>
						<div class="col-auto">
							<i class="fas fa-list fa-2x text-gray-300"></i>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="col-xl-3 col-md-6 mb-4">
			<div class="card border-left-success shadow h-100 py-2">
				<div class="card-body">
					<div class="row no-gutters align-items-center">
						<div class="col mr-2">
							<div class="text-xs font-weight-bold text-success text-uppercase mb-1">
								Directories
							</div>
							<div class="h5 mb-0 font-weight-bold text-gray-800">
								{ fmt.Sprintf("%d", countDirectories(data.Entries)) }
							</div>
						</div>
						<div class="col-auto">
							<i class="fas fa-folder fa-2x text-gray-300"></i>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="col-xl-3 col-md-6 mb-4">
			<div class="card border-left-info shadow h-100 py-2">
				<div class="card-body">
					<div class="row no-gutters align-items-center">
						<div class="col mr-2">
							<div class="text-xs font-weight-bold text-info text-uppercase mb-1">
								Files
							</div>
							<div class="h5 mb-0 font-weight-bold text-gray-800">
								{ fmt.Sprintf("%d", countFiles(data.Entries)) }
							</div>
						</div>
						<div class="col-auto">
							<i class="fas fa-file fa-2x text-gray-300"></i>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="col-xl-3 col-md-6 mb-4">
			<div class="card border-left-warning shadow h-100 py-2">
				<div class="card-body">
					<div class="row no-gutters align-items-center">
						<div class="col mr-2">
							<div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
								Total Size
							</div>
							<div class="h5 mb-0 font-weight-bold text-gray-800">
								{ formatBytes(data.TotalSize) }
							</div>
						</div>
						<div class="col-auto">
							<i class="fas fa-hdd fa-2x text-gray-300"></i>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- File Listing -->
	<div class="card shadow mb-4">
		<div class="card-header py-3 d-flex justify-content-between align-items-center">
			<h6 class="m-0 font-weight-bold text-primary">
				<i class="fas fa-folder-open me-2"></i>
							if data.CurrentPath == "/" {
				Root Directory
			} else if data.CurrentPath == "/buckets" {
										Object Store Buckets Directory
				<a href="/object-store/buckets" class="btn btn-sm btn-outline-primary ms-2">
					<i class="fas fa-cube me-1"></i>Manage Buckets
				</a>
			} else {
				{ filepath.Base(data.CurrentPath) }
			}
			</h6>
			if data.ParentPath != data.CurrentPath {
				<a href={ templ.SafeURL(fmt.Sprintf("/files?path=%s", data.ParentPath)) } class="btn btn-sm btn-outline-secondary">
					<i class="fas fa-arrow-up me-1"></i>Up
				</a>
			}
		</div>
		<div class="card-body">
			if len(data.Entries) > 0 {
				<div class="table-responsive">
					<table class="table table-hover" id="fileTable">
						<thead>
							<tr>
								<th width="40px">
									<input type="checkbox" id="selectAll" onchange="toggleSelectAll()">
								</th>
								<th>Name</th>
								<th>Size</th>
								<th>Type</th>
								<th>Modified</th>
								<th>Permissions</th>
								<th>Actions</th>
							</tr>
						</thead>
						<tbody>
							for _, entry := range data.Entries {
								<tr>
									<td>
										<input type="checkbox" class="file-checkbox" value={ entry.FullPath }>
									</td>
									<td>
										<div class="d-flex align-items-center">
											if entry.IsDirectory {
												<i class="fas fa-folder text-warning me-2"></i>
												<a href={ templ.SafeURL(fmt.Sprintf("/files?path=%s", entry.FullPath)) } class="text-decoration-none">
													{ entry.Name }
												</a>
											} else {
												<i class={ fmt.Sprintf("fas %s text-muted me-2", getFileIcon(entry.Mime)) }></i>
												<span>{ entry.Name }</span>
											}
										</div>
									</td>
									<td>
										if entry.IsDirectory {
											<span class="text-muted">—</span>
										} else {
											{ formatBytes(entry.Size) }
										}
									</td>
									<td>
										<span class="badge bg-light text-dark">
											if entry.IsDirectory {
												Directory
											} else {
												{ getMimeDisplayName(entry.Mime) }
											}
										</span>
									</td>
									<td>
										if !entry.ModTime.IsZero() {
											{ entry.ModTime.Format("2006-01-02 15:04") }
										} else {
											<span class="text-muted">—</span>
										}
									</td>
									<td>
										<code class="small permissions-display" data-mode={ entry.Mode } data-is-directory={ fmt.Sprintf("%t", entry.IsDirectory) }>{ entry.Mode }</code>
									</td>
									<td>
										<div class="btn-group btn-group-sm" role="group">
											if !entry.IsDirectory {
												<button type="button" class="btn btn-outline-primary btn-sm" title="Download" data-action="download" data-path={ entry.FullPath }>
													<i class="fas fa-download"></i>
												</button>
												<button type="button" class="btn btn-outline-info btn-sm" title="View" data-action="view" data-path={ entry.FullPath }>
													<i class="fas fa-eye"></i>
												</button>
											}
											<button type="button" class="btn btn-outline-secondary btn-sm" title="Properties" data-action="properties" data-path={ entry.FullPath }>
												<i class="fas fa-info-circle"></i>
											</button>
											<button type="button" class="btn btn-outline-danger btn-sm" title="Delete" data-action="delete" data-path={ entry.FullPath }>
												<i class="fas fa-trash"></i>
											</button>
										</div>
									</td>
								</tr>
							}
						</tbody>
					</table>
				</div>
			} else {
				<div class="text-center py-5">
					<i class="fas fa-folder-open fa-3x text-muted mb-3"></i>
					<h5 class="text-muted">Empty Directory</h5>
					<p class="text-muted">This directory contains no files or subdirectories.</p>
				</div>
			}
		</div>
	</div>

	<!-- Last Updated -->
	<div class="row">
		<div class="col-12">
			<small class="text-muted">
				<i class="fas fa-clock me-1"></i>
				Last updated: { data.LastUpdated.Format("2006-01-02 15:04:05") }
			</small>
		</div>
	</div>

	<!-- Create Folder Modal -->
	<div class="modal fade" id="createFolderModal" tabindex="-1" aria-labelledby="createFolderModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<h5 class="modal-title" id="createFolderModalLabel">
						<i class="fas fa-folder-plus me-2"></i>Create New Folder
					</h5>
					<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
				</div>
				<div class="modal-body">
					<form id="createFolderForm">
						<div class="mb-3">
							<label for="folderName" class="form-label">Folder Name</label>
							<input type="text" class="form-control" id="folderName" name="folderName" required 
								   placeholder="Enter folder name" maxlength="255">
							<div class="form-text">
								Folder names cannot contain / or \ characters.
							</div>
						</div>
						<input type="hidden" id="currentPath" name="currentPath" value={ data.CurrentPath }>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
					<button type="button" class="btn btn-primary" onclick="submitCreateFolder()">
						<i class="fas fa-folder-plus me-1"></i>Create Folder
					</button>
				</div>
			</div>
		</div>
	</div>

	<!-- Upload File Modal -->
	<div class="modal fade" id="uploadFileModal" tabindex="-1" aria-labelledby="uploadFileModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<h5 class="modal-title" id="uploadFileModalLabel">
						<i class="fas fa-upload me-2"></i>Upload Files
					</h5>
					<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
				</div>
				<div class="modal-body">
					<form id="uploadFileForm" enctype="multipart/form-data">
						<div class="mb-3">
							<label for="fileInput" class="form-label">Select Files</label>
							<input type="file" class="form-control" id="fileInput" name="files" multiple required>
							<div class="form-text">
								Choose one or more files to upload to the current directory. You can select multiple files by holding Ctrl (Cmd on Mac) while clicking.
							</div>
						</div>
						<input type="hidden" id="uploadPath" name="path" value={ data.CurrentPath }>
						
						<!-- File List Preview -->
						<div id="fileListPreview" class="mb-3" style="display: none;">
							<label class="form-label">Selected Files:</label>
							<div id="selectedFilesList" class="border rounded p-2 bg-light">
								<!-- Files will be listed here -->
							</div>
						</div>
						
						<!-- Upload Progress -->
						<div class="mb-3" id="uploadProgress" style="display: none;">
							<label class="form-label">Upload Progress:</label>
							<div class="progress mb-2">
								<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
							</div>
							<div id="uploadStatus" class="small text-muted">
								Preparing upload...
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
					<button type="button" class="btn btn-primary" onclick="submitUploadFile()">
						<i class="fas fa-upload me-1"></i>Upload Files
					</button>
				</div>
			</div>
		</div>
	</div>

	<!-- JavaScript for file browser functionality -->
	<script>
	document.addEventListener('DOMContentLoaded', function() {
		// Format permissions in the main table
		document.querySelectorAll('.permissions-display').forEach(element => {
			const mode = element.getAttribute('data-mode');
			const isDirectory = element.getAttribute('data-is-directory') === 'true';
			if (mode) {
				element.textContent = formatPermissions(mode, isDirectory);
			}
		});
		
		// Handle file browser action buttons (download, view, properties, delete)
		document.addEventListener('click', function(e) {
			const button = e.target.closest('[data-action]');
			if (!button) return;
			
			const action = button.getAttribute('data-action');
			const path = button.getAttribute('data-path');
			
			if (!path) return;
			
			switch(action) {
				case 'download':
					downloadFile(path);
					break;
				case 'view':
					viewFile(path);
					break;
				case 'properties':
					showFileProperties(path);
					break;
				case 'delete':
					if (confirm('Are you sure you want to delete "' + path + '"?')) {
						deleteFile(path);
					}
					break;
			}
		});
		
		// Initialize file manager event handlers from admin.js
		if (typeof setupFileManagerEventHandlers === 'function') {
			setupFileManagerEventHandlers();
		}
	});
	
	// File browser specific functions
	function downloadFile(path) {
		// Open download URL in new tab
		window.open('/api/files/download?path=' + encodeURIComponent(path), '_blank');
	}
	
	function viewFile(path) {
		// Open file viewer in new tab
		window.open('/api/files/view?path=' + encodeURIComponent(path), '_blank');
	}
	
	function showFileProperties(path) {
		// Fetch file properties and show in modal
		fetch('/api/files/properties?path=' + encodeURIComponent(path))
			.then(response => response.json())
			.then(data => {
				if (data.error) {
					alert('Error loading file properties: ' + data.error);
				} else {
					displayFileProperties(data);
				}
			})
			.catch(error => {
				console.error('Error fetching file properties:', error);
				alert('Error loading file properties: ' + error.message);
			});
	}
	
	function displayFileProperties(data) {
		// Create a comprehensive modal for file properties
		const modalHtml = '<div class="modal fade" id="filePropertiesModal" tabindex="-1">' +
			'<div class="modal-dialog modal-lg">' +
			'<div class="modal-content">' +
			'<div class="modal-header">' +
			'<h5 class="modal-title"><i class="fas fa-info-circle me-2"></i>Properties: ' + (data.name || 'Unknown') + '</h5>' +
			'<button type="button" class="btn-close" data-bs-dismiss="modal"></button>' +
			'</div>' +
			'<div class="modal-body">' +
			createFilePropertiesContent(data) +
			'</div>' +
			'<div class="modal-footer">' +
			'<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>' +
			'</div>' +
			'</div>' +
			'</div>' +
			'</div>';
		
		// Remove existing modal if present
		const existingModal = document.getElementById('filePropertiesModal');
		if (existingModal) {
			existingModal.remove();
		}
		
		// Add modal to body and show
		document.body.insertAdjacentHTML('beforeend', modalHtml);
		const modal = new bootstrap.Modal(document.getElementById('filePropertiesModal'));
		modal.show();
		
		// Remove modal when hidden
		document.getElementById('filePropertiesModal').addEventListener('hidden.bs.modal', function() {
			this.remove();
		});
	}
	
	function createFilePropertiesContent(data) {
		let html = '<div class="row">' +
			'<div class="col-12">' +
			'<h6 class="text-primary"><i class="fas fa-file me-1"></i>Basic Information</h6>' +
			'<table class="table table-sm">' +
			'<tr><td style="width: 120px;"><strong>Name:</strong></td><td>' + (data.name || 'N/A') + '</td></tr>' +
			'<tr><td><strong>Full Path:</strong></td><td><code class="text-break">' + (data.full_path || 'N/A') + '</code></td></tr>' +
			'<tr><td><strong>Type:</strong></td><td>' + (data.is_directory ? 'Directory' : 'File') + '</td></tr>';
		
		if (!data.is_directory) {
			html += '<tr><td><strong>Size:</strong></td><td>' + (data.size_formatted || (data.size ? formatBytes(data.size) : 'N/A')) + '</td></tr>' +
				'<tr><td><strong>MIME Type:</strong></td><td>' + (data.mime_type || 'N/A') + '</td></tr>';
		}
		
		html += '</table>' +
			'</div>' +
			'</div>' +
			'<div class="row">' +
			'<div class="col-md-6">' +
			'<h6 class="text-primary"><i class="fas fa-clock me-1"></i>Timestamps</h6>' +
			'<table class="table table-sm">';
		
		if (data.modified_time) {
			html += '<tr><td><strong>Modified:</strong></td><td>' + data.modified_time + '</td></tr>';
		}
		if (data.created_time) {
			html += '<tr><td><strong>Created:</strong></td><td>' + data.created_time + '</td></tr>';
		}
		
		html += '</table>' +
			'</div>' +
			'<div class="col-md-6">' +
			'<h6 class="text-primary"><i class="fas fa-shield-alt me-1"></i>Permissions</h6>' +
			'<table class="table table-sm">';
		
		if (data.file_mode) {
			const rwxPermissions = formatPermissions(data.file_mode, data.is_directory);
			html += '<tr><td><strong>Permissions:</strong></td><td><code>' + rwxPermissions + '</code></td></tr>';
		}
		if (data.uid !== undefined) {
			html += '<tr><td><strong>User ID:</strong></td><td>' + data.uid + '</td></tr>';
		}
		if (data.gid !== undefined) {
			html += '<tr><td><strong>Group ID:</strong></td><td>' + data.gid + '</td></tr>';
		}
		
		html += '</table>' +
			'</div>' +
			'</div>';
		
		// Add advanced info
		html += '<div class="row">' +
			'<div class="col-12">' +
			'<h6 class="text-primary"><i class="fas fa-cog me-1"></i>Advanced</h6>' +
			'<table class="table table-sm">';
		
		if (data.chunk_count) {
			html += '<tr><td style="width: 120px;"><strong>Chunks:</strong></td><td>' + data.chunk_count + '</td></tr>';
		}
		if (data.ttl_formatted) {
			html += '<tr><td><strong>TTL:</strong></td><td>' + data.ttl_formatted + '</td></tr>';
		}
		
		html += '</table>' +
			'</div>' +
			'</div>';
		
		// Add chunk details if available (show top 5)
		if (data.chunks && data.chunks.length > 0) {
			const chunksToShow = data.chunks.slice(0, 5);
			html += '<div class="row mt-3">' +
				'<div class="col-12">' +
				'<h6 class="text-primary"><i class="fas fa-puzzle-piece me-1"></i>Chunk Details' +
				(data.chunk_count > 5 ? ' (Top 5 of ' + data.chunk_count + ')' : ' (' + data.chunk_count + ')') +
				'</h6>' +
				'<div class="table-responsive" style="max-height: 200px; overflow-y: auto;">' +
				'<table class="table table-sm table-striped">' +
				'<thead>' +
				'<tr>' +
				'<th>File ID</th>' +
				'<th>Offset</th>' +
				'<th>Size</th>' +
				'<th>ETag</th>' +
				'</tr>' +
				'</thead>' +
				'<tbody>';
			
			chunksToShow.forEach(chunk => {
				html += '<tr>' +
					'<td><code class="small">' + (chunk.file_id || 'N/A') + '</code></td>' +
					'<td>' + formatBytes(chunk.offset || 0) + '</td>' +
					'<td>' + formatBytes(chunk.size || 0) + '</td>' +
					'<td><code class="small">' + (chunk.e_tag || 'N/A') + '</code></td>' +
					'</tr>';
			});
			
			html += '</tbody>' +
				'</table>' +
				'</div>' +
				'</div>' +
				'</div>';
		}
		
		// Add extended attributes if present
		if (data.extended && Object.keys(data.extended).length > 0) {
			html += '<div class="row">' +
				'<div class="col-12">' +
				'<h6 class="text-primary"><i class="fas fa-tags me-1"></i>Extended Attributes</h6>' +
				'<table class="table table-sm">';
			
			for (const [key, value] of Object.entries(data.extended)) {
				html += '<tr><td><strong>' + key + ':</strong></td><td>' + value + '</td></tr>';
			}
			
			html += '</table>' +
				'</div>' +
				'</div>';
		}
		
		return html;
	}
	
	function uploadFile() {
		const modal = new bootstrap.Modal(document.getElementById('uploadFileModal'));
		modal.show();
	}
	
	function toggleSelectAll() {
		const selectAllCheckbox = document.getElementById('selectAll');
		const checkboxes = document.querySelectorAll('.file-checkbox');
		
		checkboxes.forEach(checkbox => {
			checkbox.checked = selectAllCheckbox.checked;
		});
		
		updateDeleteSelectedButton();
	}
	
	function updateDeleteSelectedButton() {
		const checkboxes = document.querySelectorAll('.file-checkbox:checked');
		const deleteBtn = document.getElementById('deleteSelectedBtn');
		
		if (checkboxes.length > 0) {
			deleteBtn.style.display = 'inline-block';
		} else {
			deleteBtn.style.display = 'none';
		}
	}
	
	// Helper function to format bytes
	function formatBytes(bytes) {
		if (bytes === 0) return '0 Bytes';
		const k = 1024;
		const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
		const i = Math.floor(Math.log(bytes) / Math.log(k));
		return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
	}
	
	// Helper function to format permissions in rwxrwxrwx format
	function formatPermissions(mode, isDirectory) {
		// Check if mode is already in rwxrwxrwx format (e.g., "drwxr-xr-x" or "-rw-r--r--")
		if (mode && (mode.startsWith('d') || mode.startsWith('-') || mode.startsWith('l')) && mode.length === 10) {
			return mode; // Already formatted
		}
		
		// Convert to number - could be octal string or decimal
		let permissions;
		if (typeof mode === 'string') {
			// Try parsing as octal first, then decimal
			if (mode.startsWith('0') && mode.length <= 4) {
				permissions = parseInt(mode, 8);
			} else {
				permissions = parseInt(mode, 10);
			}
		} else {
			permissions = parseInt(mode, 10);
		}
		
		if (isNaN(permissions)) {
			return isDirectory ? 'drwxr-xr-x' : '-rw-r--r--'; // Default fallback
		}
		
		// Handle Go's os.ModeDir conversion
		// Go's os.ModeDir is 0x80000000 (2147483648), but Unix S_IFDIR is 0o40000 (16384)
		let fileType = '-';
		
		// Check for Go's os.ModeDir flag
		if (permissions & 0x80000000) {
			fileType = 'd';
		}
		// Check for standard Unix file type bits
		else if ((permissions & 0xF000) === 0x4000) { // S_IFDIR (0o40000)
			fileType = 'd';
		} else if ((permissions & 0xF000) === 0x8000) { // S_IFREG (0o100000)
			fileType = '-';
		} else if ((permissions & 0xF000) === 0xA000) { // S_IFLNK (0o120000)
			fileType = 'l';
		} else if ((permissions & 0xF000) === 0x2000) { // S_IFCHR (0o020000)
			fileType = 'c';
		} else if ((permissions & 0xF000) === 0x6000) { // S_IFBLK (0o060000)
			fileType = 'b';
		} else if ((permissions & 0xF000) === 0x1000) { // S_IFIFO (0o010000)
			fileType = 'p';
		} else if ((permissions & 0xF000) === 0xC000) { // S_IFSOCK (0o140000)
			fileType = 's';
		}
		// Fallback to isDirectory parameter if file type detection fails
		else if (isDirectory) {
			fileType = 'd';
		}
		
		// Permission bits (always use the lower 12 bits for permissions)
		const owner = (permissions >> 6) & 7;
		const group = (permissions >> 3) & 7;
		const others = permissions & 7;
		
		// Convert number to rwx format
		function numToRwx(num) {
			const r = (num & 4) ? 'r' : '-';
			const w = (num & 2) ? 'w' : '-';
			const x = (num & 1) ? 'x' : '-';
			return r + w + x;
		}
		
		return fileType + numToRwx(owner) + numToRwx(group) + numToRwx(others);
	}
	
	function exportFileList() {
		// Simple CSV export of file list
		const rows = Array.from(document.querySelectorAll('#fileTable tbody tr')).map(row => {
			const cells = row.querySelectorAll('td');
			if (cells.length > 1) {
				return {
					name: cells[1].textContent.trim(),
					size: cells[2].textContent.trim(),
					type: cells[3].textContent.trim(),
					modified: cells[4].textContent.trim(),
					permissions: cells[5].textContent.trim()
				};
			}
			return null;
		}).filter(row => row !== null);
		
		const csvContent = "data:text/csv;charset=utf-8," + 
			"Name,Size,Type,Modified,Permissions\n" +
			rows.map(r => '"' + r.name + '","' + r.size + '","' + r.type + '","' + r.modified + '","' + r.permissions + '"').join("\n");
		
		const encodedUri = encodeURI(csvContent);
		const link = document.createElement("a");
		link.setAttribute("href", encodedUri);
		link.setAttribute("download", "files.csv");
		document.body.appendChild(link);
		link.click();
		document.body.removeChild(link);
	}
	
	// Handle file checkbox changes
	document.addEventListener('change', function(e) {
		if (e.target.classList.contains('file-checkbox')) {
			updateDeleteSelectedButton();
		}
	});
	</script>
}

func countDirectories(entries []dash.FileEntry) int {
	count := 0
	for _, entry := range entries {
		if entry.IsDirectory {
			count++
		}
	}
	return count
}

func countFiles(entries []dash.FileEntry) int {
	count := 0
	for _, entry := range entries {
		if !entry.IsDirectory {
			count++
		}
	}
	return count
}

func getFileIcon(mime string) string {
	switch {
	case strings.HasPrefix(mime, "image/"):
		return "fa-image"
	case strings.HasPrefix(mime, "video/"):
		return "fa-video"
	case strings.HasPrefix(mime, "audio/"):
		return "fa-music"
	case strings.HasPrefix(mime, "text/"):
		return "fa-file-text"
	case mime == "application/pdf":
		return "fa-file-pdf"
	case mime == "application/zip" || strings.Contains(mime, "archive"):
		return "fa-file-archive"
	case mime == "application/json":
		return "fa-file-code"
	case strings.Contains(mime, "script") || strings.Contains(mime, "javascript"):
		return "fa-file-code"
	default:
		return "fa-file"
	}
}

func getMimeDisplayName(mime string) string {
	switch mime {
	case "text/plain":
		return "Text"
	case "text/html":
		return "HTML"
	case "application/json":
		return "JSON"
	case "application/pdf":
		return "PDF"
	case "image/jpeg":
		return "JPEG"
	case "image/png":
		return "PNG"
	case "image/gif":
		return "GIF"
	case "video/mp4":
		return "MP4"
	case "audio/mpeg":
		return "MP3"
	case "application/zip":
		return "ZIP"
	default:
		if strings.HasPrefix(mime, "image/") {
			return "Image"
		} else if strings.HasPrefix(mime, "video/") {
			return "Video"
		} else if strings.HasPrefix(mime, "audio/") {
			return "Audio"
		} else if strings.HasPrefix(mime, "text/") {
			return "Text"
		}
		return "File"
	}
}