From e15d38a7952ca09724d37c355675f5e1079f4df3 Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Mon, 17 Feb 2025 17:55:57 -0800 Subject: [PATCH] fix stream-file urls to use new remoteuri (#1984) --- emain/emain-util.ts | 5 ++- emain/emain.ts | 4 +- frontend/app/block/blockframe.tsx | 5 +-- frontend/app/element/markdown-util.ts | 18 +++------ frontend/app/modals/conntypeahead.tsx | 20 ++++++---- .../app/view/preview/directorypreview.tsx | 6 ++- frontend/app/view/preview/preview.tsx | 24 ++++-------- frontend/app/view/term/termsticker.tsx | 3 +- frontend/types/custom.d.ts | 3 ++ frontend/util/waveutil.ts | 16 +++++++- pkg/remote/fileshare/s3fs/s3fs.go | 13 ++----- pkg/web/web.go | 39 ++++++++++++++----- 12 files changed, 92 insertions(+), 64 deletions(-) diff --git a/emain/emain-util.ts b/emain/emain-util.ts index 4395d22af..d263d3e3e 100644 --- a/emain/emain-util.ts +++ b/emain/emain-util.ts @@ -87,7 +87,10 @@ export function shFrameNavHandler(event: Electron.Event { - const streamingUrl = getWebServerEndpoint() + "/wave/stream-file?path=" + encodeURIComponent(payload.filePath); + const baseName = encodeURIComponent(path.basename(payload.filePath)); + const streamingUrl = + getWebServerEndpoint() + "/wave/stream-file/" + baseName + "?path=" + encodeURIComponent(payload.filePath); event.sender.downloadURL(streamingUrl); }); diff --git a/frontend/app/block/blockframe.tsx b/frontend/app/block/blockframe.tsx index c5722b992..06c255836 100644 --- a/frontend/app/block/blockframe.tsx +++ b/frontend/app/block/blockframe.tsx @@ -241,6 +241,7 @@ const BlockFrame_Header = ({ icon: "link-slash", title: "wsh is not installed for this connection", }; + const showNoWshButton = manageConnection && wshProblem && !util.isBlank(connName) && !connName.startsWith("aws:"); return (
)} - {manageConnection && wshProblem && ( - - )} + {showNoWshButton && }
{headerTextElems}
{endIconsElem}
diff --git a/frontend/app/element/markdown-util.ts b/frontend/app/element/markdown-util.ts index c99e69829..01cb0241f 100644 --- a/frontend/app/element/markdown-util.ts +++ b/frontend/app/element/markdown-util.ts @@ -4,7 +4,7 @@ import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; import { getWebServerEndpoint } from "@/util/endpoints"; -import { isBlank, makeConnRoute } from "@/util/util"; +import { formatRemoteUri } from "@/util/waveutil"; import parseSrcSet from "parse-srcset"; export type MarkdownContentBlockType = { @@ -158,19 +158,13 @@ export const resolveRemoteFile = async (filepath: string, resolveOpts: MarkdownR if (!filepath || filepath.startsWith("http://") || filepath.startsWith("https://")) { return filepath; } - try { - const route = makeConnRoute(resolveOpts.connName); - const fileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [resolveOpts.baseDir, filepath], { - route: route, - }); - + const baseDirUri = formatRemoteUri(resolveOpts.baseDir, resolveOpts.connName); + const fileInfo = await RpcApi.FileJoinCommand(TabRpcClient, [baseDirUri, filepath]); + const remoteUri = formatRemoteUri(fileInfo.path, resolveOpts.connName); + console.log("markdown resolve", resolveOpts, filepath, "=>", baseDirUri, remoteUri); const usp = new URLSearchParams(); - usp.set("path", fileInfo.path); - if (!isBlank(resolveOpts.connName)) { - usp.set("connection", resolveOpts.connName); - } - + usp.set("path", remoteUri); return getWebServerEndpoint() + "/wave/stream-file?" + usp.toString(); } catch (err) { console.warn("Failed to resolve remote file:", filepath, err); diff --git a/frontend/app/modals/conntypeahead.tsx b/frontend/app/modals/conntypeahead.tsx index 77df02443..632a9685c 100644 --- a/frontend/app/modals/conntypeahead.tsx +++ b/frontend/app/modals/conntypeahead.tsx @@ -348,6 +348,7 @@ const ChangeConnectionBlockModal = React.memo( const connStatusMap = new Map(); const fullConfig = jotai.useAtomValue(atoms.fullConfigAtom); let filterOutNowsh = util.useAtomValueSafe(viewModel.filterOutNowsh) ?? true; + const showS3 = util.useAtomValueSafe(viewModel.showS3) ?? false; let maxActiveConnNum = 1; for (const conn of allConnStatus) { @@ -436,14 +437,17 @@ const ChangeConnectionBlockModal = React.memo( fullConfig, filterOutNowsh ); - const s3Suggestions = getS3Suggestions( - s3List, - connection, - connSelected, - connStatusMap, - fullConfig, - filterOutNowsh - ); + let s3Suggestions: SuggestionConnectionScope = null; + if (showS3) { + s3Suggestions = getS3Suggestions( + s3List, + connection, + connSelected, + connStatusMap, + fullConfig, + filterOutNowsh + ); + } const connectionsEditItem = getConnectionsEditItem(changeConnModalAtom, connSelected); const disconnectItem = getDisconnectItem(connection, connStatusMap); const newConnectionSuggestionItem = getNewConnectionSuggestionItem( diff --git a/frontend/app/view/preview/directorypreview.tsx b/frontend/app/view/preview/directorypreview.tsx index 4c8b57add..6670c217b 100644 --- a/frontend/app/view/preview/directorypreview.tsx +++ b/frontend/app/view/preview/directorypreview.tsx @@ -9,9 +9,10 @@ import { ContextMenuModel } from "@/app/store/contextmenu"; import { PLATFORM, atoms, createBlock, getApi, globalStore } from "@/app/store/global"; import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; -import { formatRemoteUri, type PreviewModel } from "@/app/view/preview/preview"; +import { type PreviewModel } from "@/app/view/preview/preview"; import { checkKeyPressed, isCharacterKeyEvent } from "@/util/keyutil"; import { fireAndForget, isBlank, makeNativeLabel } from "@/util/util"; +import { formatRemoteUri } from "@/util/waveutil"; import { offset, useDismiss, useFloating, useInteractions } from "@floating-ui/react"; import { Column, @@ -575,7 +576,8 @@ function TableBody({ { label: "Download File", click: () => { - getApi().downloadFile(normPath); + const remoteUri = formatRemoteUri(finfo.path, conn); + getApi().downloadFile(remoteUri); }, }, { diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index a723bb917..09b961fae 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -38,6 +38,7 @@ import { makeNativeLabel, stringToBase64, } from "@/util/util"; +import { formatRemoteUri } from "@/util/waveutil"; import { Monaco } from "@monaco-editor/react"; import clsx from "clsx"; import { Atom, atom, Getter, PrimitiveAtom, useAtom, useAtomValue, useSetAtom, WritableAtom } from "jotai"; @@ -180,6 +181,8 @@ export class PreviewModel implements ViewModel { directoryKeyDownHandler: (waveEvent: WaveKeyboardEvent) => boolean; codeEditKeyDownHandler: (waveEvent: WaveKeyboardEvent) => boolean; + showS3 = atom(true); + constructor(blockId: string, nodeModel: BlockNodeModel) { this.viewType = "preview"; this.blockId = blockId; @@ -936,13 +939,14 @@ function StreamingPreview({ model }: SpecializedViewProps) { const conn = useAtomValue(model.connection); const fileInfo = useAtomValue(model.statFile); const filePath = fileInfo.path; + const remotePath = formatRemoteUri(filePath, conn); const usp = new URLSearchParams(); - usp.set("path", filePath); + usp.set("path", remotePath); if (conn != null) { usp.set("connection", conn); } - const streamingUrl = getWebServerEndpoint() + "/wave/stream-file?" + usp.toString(); - if (fileInfo.mimetype == "application/pdf") { + const streamingUrl = `${getWebServerEndpoint()}/wave/stream-file?${usp.toString()}`; + if (fileInfo.mimetype === "application/pdf") { return (