mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 21:05:18 +02:00
fix
This commit is contained in:
parent
46ab64ba49
commit
1211fcf75d
@ -1,5 +1,6 @@
|
|||||||
import {createApp, ref} from 'vue';
|
import {createApp, ref} from 'vue';
|
||||||
import {toggleElem} from '../utils/dom.ts';
|
import {toggleElem} from '../utils/dom.ts';
|
||||||
|
import {pathEscapeSegments, pathUnescapeSegments} from '../utils/url.ts';
|
||||||
import {GET, PUT} from '../modules/fetch.ts';
|
import {GET, PUT} from '../modules/fetch.ts';
|
||||||
import ViewFileTree from '../components/ViewFileTree.vue';
|
import ViewFileTree from '../components/ViewFileTree.vue';
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ function childrenLoader(sidebarEl: HTMLElement) {
|
|||||||
const fileTree = sidebarEl.querySelector('#view-file-tree');
|
const fileTree = sidebarEl.querySelector('#view-file-tree');
|
||||||
const apiBaseUrl = fileTree.getAttribute('data-api-base-url');
|
const apiBaseUrl = fileTree.getAttribute('data-api-base-url');
|
||||||
const refTypeNameSubURL = fileTree.getAttribute('data-current-ref-type-name-sub-url');
|
const refTypeNameSubURL = fileTree.getAttribute('data-current-ref-type-name-sub-url');
|
||||||
const response = await GET(encodeURI(`${apiBaseUrl}/tree/${refTypeNameSubURL}/${path ?? ''}?recursive=${recursive ?? false}`));
|
const response = await GET(`${apiBaseUrl}/tree/${refTypeNameSubURL}/${pathEscapeSegments(path ?? '')}?recursive=${recursive ?? false}`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
if (json instanceof Array) {
|
if (json instanceof Array) {
|
||||||
return json.map((i) => ({
|
return json.map((i) => ({
|
||||||
@ -81,7 +82,7 @@ export async function initViewFileTreeSidebar() {
|
|||||||
|
|
||||||
fileTree.classList.remove('is-loading');
|
fileTree.classList.remove('is-loading');
|
||||||
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren: childrenLoader(sidebarEl), loadContent: (path: string) => {
|
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren: childrenLoader(sidebarEl), loadContent: (path: string) => {
|
||||||
window.history.pushState(null, null, encodeURI(`${baseUrl}/src${refString}/${path}`));
|
window.history.pushState(null, null, `${baseUrl}/src${refString}/${pathEscapeSegments(path)}`);
|
||||||
selectedItem.value = path;
|
selectedItem.value = path;
|
||||||
loadContent(sidebarEl);
|
loadContent(sidebarEl);
|
||||||
}});
|
}});
|
||||||
@ -94,6 +95,6 @@ export async function initViewFileTreeSidebar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedPath(ref: string) {
|
function getSelectedPath(ref: string) {
|
||||||
const path = decodeURI(new URL(window.location.href).pathname);
|
const path = pathUnescapeSegments(new URL(window.location.href).pathname);
|
||||||
return path.substring(path.indexOf(ref) + ref.length + 1);
|
return path.substring(path.indexOf(ref) + ref.length + 1);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,10 @@ export function pathEscapeSegments(s: string): string {
|
|||||||
return s.split('/').map(encodeURIComponent).join('/');
|
return s.split('/').map(encodeURIComponent).join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function pathUnescapeSegments(s: string): string {
|
||||||
|
return s.split('/').map(decodeURIComponent).join('/');
|
||||||
|
}
|
||||||
|
|
||||||
function stripSlash(url: string): string {
|
function stripSlash(url: string): string {
|
||||||
return url.endsWith('/') ? url.slice(0, -1) : url;
|
return url.endsWith('/') ? url.slice(0, -1) : url;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user