-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
40 lines (33 loc) · 1.28 KB
/
script.js
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
// script.js
let currentPath = '.';
async function displayContents(dirPath = '.') {
currentPath = dirPath;
const table = document.getElementById('repo-table');
table.innerHTML = '';
// Add back button if not in root
if (dirPath !== '.') {
const parentPath = dirPath.split('/').slice(0, -1).join('/') || '.';
const backRow = table.insertRow();
const backCell = backRow.insertCell(0);
backCell.colSpan = 2;
backCell.innerHTML = `<a href="#" onclick="displayContents('${parentPath}'); return false">📁 ..</a>`;
}
try {
const response = await fetch(`/api/files/${dirPath}`);
const items = await response.json();
items.forEach((item, index) => {
const row = table.insertRow();
const cell1 = row.insertCell(0);
const cell2 = row.insertCell(1);
cell1.textContent = `${index + 1}.`;
if (item.isDirectory) {
cell2.innerHTML = `<a href="#" onclick="displayContents('${item.path}'); return false">📁 ${item.name}</a>`;
} else {
cell2.innerHTML = `<a href="${item.path}">📄 ${item.name}</a>`;
}
});
} catch (error) {
console.error('Error:', error);
}
}
displayContents();