Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion webui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"@connectrpc/connect": "^2.1.1",
"@connectrpc/connect-web": "^2.1.1",
"@solidjs/router": "^0.15.4",
"dompurify": "^3.2.0",
"fuse.js": "^7.1.0",
"marked": "^13.0.0",
"solid-js": "^1.9.5"
}
}
6 changes: 6 additions & 0 deletions webui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ChangeServerPasswordPage } from './page/ChangeServerPasswordPage'
import { SettingsPage } from './page/SettingsPage'
import { ServerSearchPage } from './page/ServerSearchPage'
import { ServerProfilePage } from './page/ServerProfilePage'
import { ServerMdPreviewPage } from './page/ServerMdPreviewPage'
import { UpdatePage } from './page/UpdatePage'
import { TransfersPage } from './page/TransfersPage'

Expand Down Expand Up @@ -66,6 +67,11 @@ const App: Component = () => {
component: ServerProfilePage,
},

{
path: '/server/:uuid/md/:username/*path',
component: ServerMdPreviewPage,
},

{
path: makeBrowsePath(':uuid', ':username', '*path'),
component: ServerBrowsePage,
Expand Down
84 changes: 66 additions & 18 deletions webui/src/page/ServerBrowsePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ import styles from './ServerBrowsePage.module.css'

import { useFileServerUrl, useGlobalState, useRpcClient } from '../ctx'
import { ConnectError } from '@connectrpc/connect'
import { A, useLocation, useParams } from '@solidjs/router'
import {
A,
useLocation,
useNavigate,
useParams,
useSearchParams,
} from '@solidjs/router'
import { FileMeta } from '../../pb/clientrpc/v1/rpc_pb'
import {
makeBrowsePath,
makeFileUrl,
makeMdPreviewPath,
normalizePath,
trimStrEllipsis,
} from '../util'
import { FileTable } from '../FileTable'
import { QueueButton } from '../QueueButton'
import { getAutoOpenReadme } from '../uiPrefs'

const Page: Component = () => {
const {
Expand All @@ -25,6 +33,8 @@ const Page: Component = () => {
const state = useGlobalState()
const client = useRpcClient()
const fsUrl = useFileServerUrl()
const navigate = useNavigate()
const [searchParams] = useSearchParams<{ noauto?: string }>()

const server = state.getServerByUuid(uuid)
if (!server) {
Expand All @@ -44,13 +54,33 @@ const Page: Component = () => {
try {
setLoading(true)

const shouldAutoOpen =
searchParams.noauto !== '1' && getAutoOpenReadme()

const stream = client.getDirFiles({
serverUuid: server.uuid,
username: username,
path: path,
})

for await (const msg of stream) {
if (shouldAutoOpen) {
const readme = msg.content.find(
(f) =>
!f.isDir &&
f.name.toLowerCase() === 'readme.md',
)
if (readme) {
const pth = path === '/' ? '' : path
const readmePath = pth + '/' + readme.name
navigate(
makeMdPreviewPath(uuid, username, readmePath),
{ replace: true },
)
return
}
}

const res = [...files(), ...msg.content]
res.sort((a, b) => {
if (a.isDir && !b.isDir) {
Expand Down Expand Up @@ -161,24 +191,42 @@ const Page: Component = () => {
filePath,
)

const lowerName = item.meta.name.toLowerCase()
const isMarkdown =
lowerName.endsWith('.md') ||
lowerName.endsWith('.markdown')

const actions = (
<>
<a
title="Open File"
href={nonDlUrl}
target="_blank"
>
🔗
</a>
<QueueButton
serverUuid={uuid}
peerUsername={username}
filePath={filePath}
title="Download File"
/>
</>
)

if (isMarkdown) {
return {
href: makeMdPreviewPath(
uuid,
username,
filePath,
),
actions,
}
}

return {
actions: (
<>
<a
title="Open File"
href={nonDlUrl}
target="_blank"
>
🔗
</a>
<QueueButton
serverUuid={uuid}
peerUsername={username}
filePath={filePath}
title="Download File"
/>
</>
),
actions,
onClick: () => {
state.previewFile(uuid, username, filePath)
},
Expand Down
Loading