Skip to content

Commit 937e277

Browse files
committed
Añadir columna "Última Modificación" en la tabla y mejorar el enlace de carpeta con nombre escapado
1 parent 53d5e12 commit 937e277

4 files changed

Lines changed: 65 additions & 41 deletions

File tree

internal/statics/css/styles.css

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@ body {
55
padding: 20px;
66
color: #333;
77
}
8-
.tab-content > div:first-child {
9-
.action-btn.download:hover {
10-
color: #2980b9;
11-
}
128

13-
.action-btn.search:hover {
14-
color: #3498db;
15-
}
16-
17-
/* Button Styles */dth: 100%;
9+
.tab-content > div:first-child {
10+
width: 100%;
1811
display: block;
1912
}
13+
2014
.styled-table {
2115
width: 100%;
2216
margin: 0 auto;
@@ -191,6 +185,12 @@ body {
191185

192186
.styled-table td {
193187
padding: 12px 20px;
188+
/* Last Modified column: allow enough width for date/time */
189+
&:nth-child(4) {
190+
min-width: 140px;
191+
max-width: 180px;
192+
white-space: nowrap;
193+
}
194194
text-align: center;
195195
border-bottom: 1px solid #dddddd;
196196
}
@@ -277,6 +277,10 @@ td a:hover {
277277
color: #009879;
278278
}
279279

280+
.action-btn.search:hover {
281+
color: #3498db;
282+
}
283+
280284
/* Button Styles */
281285
.btn {
282286
display: inline-block;

internal/statics/js/main.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,19 @@ function sortTable(n, type = 'string') {
605605
const cellA = rowA.cells[n].innerText.trim();
606606
const cellB = rowB.cells[n].innerText.trim();
607607

608+
// Last Modified column (date sorting)
609+
if (n === 3) {
610+
// Try to parse as ISO date, fallback to string
611+
const dateA = Date.parse(cellA);
612+
const dateB = Date.parse(cellB);
613+
if (!isNaN(dateA) && !isNaN(dateB)) {
614+
return sortOrder === 'asc' ? dateA - dateB : dateB - dateA;
615+
}
616+
// Fallback to string compare if not valid date
617+
if (cellA < cellB) return sortOrder === 'asc' ? -1 : 1;
618+
if (cellA > cellB) return sortOrder === 'asc' ? 1 : -1;
619+
return 0;
620+
}
608621
if (type === 'number') {
609622
const numA = parseFloat(cellA) || 0;
610623
const numB = parseFloat(cellB) || 0;
@@ -619,10 +632,11 @@ function sortTable(n, type = 'string') {
619632
table.innerHTML = "";
620633
rows.forEach(row => table.appendChild(row));
621634

622-
document.querySelectorAll("th i").forEach(icon => icon.className = 'fa');
623-
const iconId = n === 0 ? 'name-icon' :
624-
n === 2 ? 'size-icon' :
625-
n === 3 ? 'custom-path-icon' : '';
635+
document.querySelectorAll("th i").forEach(icon => icon.className = 'fa');
636+
const iconId = n === 0 ? 'name-icon' :
637+
n === 2 ? 'size-icon' :
638+
n === 3 ? 'modified-icon' :
639+
n === 4 ? 'custom-path-icon' : '';
626640
if (iconId) {
627641
const icon = document.getElementById(iconId);
628642
icon.className = "fa fa-sort-" + (sortOrder === 'asc' ? 'asc' : 'desc');

internal/statics/templates/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
<th onclick="sortTable(0)">Name <i id="name-icon" class="fa"></i></th>
3636
<th>Permissions</th>
3737
<th onclick="sortTable(2, 'number')">Size <i id="size-icon" class="fa"></i></th>
38-
<th onclick="sortTable(3)">Custom Path <i id="custom-path-icon" class="fa"></i></th>
38+
<th onclick="sortTable(3)">Last Modified <i id="modified-icon" class="fa"></i></th>
39+
<th onclick="sortTable(4)">Custom Path <i id="custom-path-icon" class="fa"></i></th>
3940
<th>Actions</th>
4041
</tr>
4142
</thead>
@@ -44,7 +45,7 @@
4445
</tbody>
4546
<tfoot>
4647
<tr>
47-
<td colspan="5">
48+
<td colspan="6">
4849
<div style="{{ .HiddenDisplay }} justify-content: space-between; align-items: center;">
4950
<label class="checkbox-container" for="showAlertCheckbox">
5051
Show Hidden Files

upgopher.go

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -623,20 +623,23 @@ func createFolderRow(file fs.DirEntry, currentPath string, fileInfo os.FileInfo)
623623
encodedPath := createEncodedPath(currentPath, file.Name())
624624
escapedencodedFilePath := html.EscapeString(encodedPath)
625625

626-
folderLink := fmt.Sprintf(`<a href="/?path=%s">%s</a>`, escapedencodedFilePath, file.Name())
626+
escapedFolderName := html.EscapeString(file.Name())
627+
folderLink := fmt.Sprintf(`<a href="/?path=%s">%s</a>`, escapedencodedFilePath, escapedFolderName)
628+
lastModified := fileInfo.ModTime().Format("2006-01-02 15:04:05")
627629
return fmt.Sprintf(`
628-
<tr>
629-
<td>%s</td>
630-
<td>%s</td>
631-
<td>-</td>
632-
<td>-</td>
633-
<td>
634-
<div class="action-buttons">
635-
<span>-</span>
636-
</div>
637-
</td>
638-
</tr>
639-
`, folderLink, fileInfo.Mode())
630+
<tr>
631+
<td>%s</td>
632+
<td>%s</td>
633+
<td>-</td>
634+
<td>%s</td>
635+
<td>-</td>
636+
<td>
637+
<div class="action-buttons">
638+
<span>-</span>
639+
</div>
640+
</td>
641+
</tr>
642+
`, folderLink, fileInfo.Mode(), lastModified)
640643
}
641644

642645
func createFileRow(file fs.DirEntry, currentPath string, fileInfo os.FileInfo) string {
@@ -654,7 +657,7 @@ func createFileRow(file fs.DirEntry, currentPath string, fileInfo os.FileInfo) s
654657
customPath, exists := customPaths[filePath]
655658
fmt.Println(currentPath)
656659
if exists {
657-
customPathDisplay = customPath
660+
customPathDisplay = html.EscapeString(customPath)
658661
}
659662
// Determinar si el archivo es legible (texto)
660663
isReadableFile := isTextFile(file.Name())
@@ -671,20 +674,22 @@ func createFileRow(file fs.DirEntry, currentPath string, fileInfo os.FileInfo) s
671674
}
672675

673676
fileSize, units := formatFileSize(fileInfo.Size())
677+
lastModified := fileInfo.ModTime().Format("2006-01-02 15:04:05")
674678

675679
return fmt.Sprintf(`
676-
<tr>
677-
<td>%s</td>
678-
<td>%s</td>
679-
<td>%.2f %s</td>
680-
<td>%s</td>
681-
<td>
682-
<div class="action-buttons">
683-
%s%s%s%s%s
684-
</div>
685-
</td>
686-
</tr>
687-
`, escapedFileName, fileInfo.Mode(), fileSize, units, customPathDisplay,
680+
<tr>
681+
<td>%s</td>
682+
<td>%s</td>
683+
<td>%.2f %s</td>
684+
<td>%s</td>
685+
<td>%s</td>
686+
<td>
687+
<div class="action-buttons">
688+
%s%s%s%s%s
689+
</div>
690+
</td>
691+
</tr>
692+
`, escapedFileName, fileInfo.Mode(), fileSize, units, lastModified, customPathDisplay,
688693
downloadLink, copyURLButton, customPathButton, searchButton, deleteLink)
689694
}
690695

0 commit comments

Comments
 (0)