0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-19 12:50:52 +02:00

debug new api /tree

This commit is contained in:
Kerwin Bryant 2024-12-25 08:55:43 +00:00
parent 76a56149d5
commit 158b79e40a

View File

@ -28,10 +28,10 @@ async function toggleSidebar(visibility) {
});
}
async function loadChildren(item?) {
async function loadChildren(item, recursive?: boolean) {
const el = document.querySelector('#view-file-tree');
const apiBaseUrl = el.getAttribute('data-api-base-url');
const response = await GET(`${apiBaseUrl}/contents/${item ? item.path : ''}`);
const response = await GET(`${apiBaseUrl}/tree/${item ? item.path : ''}?recursive=${recursive ?? false}`);
const json = await response.json();
if (json instanceof Array) {
return json.map((i) => ({
@ -44,26 +44,6 @@ async function loadChildren(item?) {
return null;
}
async function loadRecursive(treePath) {
let root = null;
let parent = null;
let parentPath = '';
for (const i of (`/${treePath}`).split('/')) {
const path = `${parentPath}${parentPath ? '/' : ''}${i}`;
const result = await loadChildren({path});
if (root === null) {
root = result;
parent = root;
} else {
parent = parent.find((item) => item.path === path);
parent.children = result;
parent = result;
}
parentPath = path;
}
return root;
}
async function loadContent(item) {
document.querySelector('.repo-home-filelist').innerHTML = `load content of ${item.path}`;
}
@ -84,7 +64,7 @@ export async function initViewFileTreeSidebar() {
const treePath = fileTree.getAttribute('data-tree-path');
const selectedItem = ref(treePath);
const files = await loadRecursive(treePath);
const files = await loadChildren({path: treePath}, true);
fileTree.classList.remove('center');
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren, loadContent: (item) => {