Skip to content

Commit 60d6185

Browse files
authored
fix: show directory listing instead of error when opening folder path (#15)
1 parent 8c6eca2 commit 60d6185

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

app/pages/package/code/[...path].vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,17 @@ const currentNode = computed(() => {
9696
9797
const parts = filePath.value.split('/')
9898
let current: PackageFileTree[] | undefined = fileTree.value.tree
99+
let lastFound: PackageFileTree | null = null
99100
100101
for (const part of parts) {
101102
const found: PackageFileTree | undefined = current?.find(n => n.name === part)
102103
if (!found) return null
104+
lastFound = found
103105
if (found.type === 'file') return found
104106
current = found.children
105107
}
106108
107-
return null
109+
return lastFound
108110
})
109111
110112
const isViewingFile = computed(() => currentNode.value?.type === 'file')
@@ -118,8 +120,8 @@ const isFileTooLarge = computed(() => {
118120
119121
// Fetch file content when a file is selected (and not too large)
120122
const fileContentUrl = computed(() => {
121-
// Don't fetch if no file path, file tree not loaded, or file is too large
122-
if (!filePath.value || !fileTree.value || isFileTooLarge.value) {
123+
// Don't fetch if no file path, file tree not loaded, file is too large, or it's a directory
124+
if (!filePath.value || !fileTree.value || isFileTooLarge.value || !isViewingFile.value) {
123125
return null
124126
}
125127
return `/api/registry/file/${packageName.value}/v/${version.value}/${filePath.value}`

0 commit comments

Comments
 (0)