mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
fix rpc no-route errors, fix fileopen in preview (#313)
This commit is contained in:
parent
558fda1253
commit
a7746bc5cc
@ -103,6 +103,14 @@ function handleIncomingRpcMessage(msg: RpcMessage, eventHandlerFn: (event: WaveE
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (msg.command == "message") {
|
||||
if (msg.data?.oref != null) {
|
||||
console.log("rpc:message", msg.data?.oref, msg.data?.message);
|
||||
} else {
|
||||
console.log("rpc:message", msg.data?.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("rpc command not supported", msg);
|
||||
return;
|
||||
|
@ -107,6 +107,11 @@ class WshServerType {
|
||||
return WOS.wshServerRpcHelper_call("remotefileinfo", data, opts);
|
||||
}
|
||||
|
||||
// command "remotefilejoin" [call]
|
||||
RemoteFileJoinCommand(data: string[], opts?: RpcOpts): Promise<FileInfo> {
|
||||
return WOS.wshServerRpcHelper_call("remotefilejoin", data, opts);
|
||||
}
|
||||
|
||||
// command "remotestreamcpudata" [responsestream]
|
||||
RemoteStreamCpuDataCommand(opts?: RpcOpts): AsyncGenerator<TimeSeriesData, void, boolean> {
|
||||
return WOS.wshServerRpcHelper_responsestream("remotestreamcpudata", null, opts);
|
||||
|
@ -4,6 +4,7 @@
|
||||
import { TypeAheadModal } from "@/app/modals/typeaheadmodal";
|
||||
import { ContextMenuModel } from "@/app/store/contextmenu";
|
||||
import { tryReinjectKey } from "@/app/store/keymodel";
|
||||
import { WshServer } from "@/app/store/wshserver";
|
||||
import { Markdown } from "@/element/markdown";
|
||||
import { NodeModel } from "@/layout/index";
|
||||
import { createBlock, globalStore, refocusNode } from "@/store/global";
|
||||
@ -42,6 +43,13 @@ const SpecializedViewMap: { [view: string]: ({ model }: SpecializedViewProps) =>
|
||||
directory: DirectoryPreview,
|
||||
};
|
||||
|
||||
function makeConnRoute(conn: string): string {
|
||||
if (util.isBlank(conn)) {
|
||||
return "conn:local";
|
||||
}
|
||||
return "conn:" + conn;
|
||||
}
|
||||
|
||||
function isTextFile(mimeType: string): boolean {
|
||||
if (mimeType == null) {
|
||||
return false;
|
||||
@ -484,13 +492,18 @@ export class PreviewModel implements ViewModel {
|
||||
this.updateOpenFileModalAndError(false);
|
||||
return true;
|
||||
}
|
||||
const newPath = fileInfo.dir + "/" + filePath;
|
||||
const conn = globalStore.get(this.connection) ?? "";
|
||||
const newFileInfo = await services.FileService.StatFile(conn, newPath);
|
||||
this.updateOpenFileModalAndError(false);
|
||||
this.goHistory(newFileInfo.path);
|
||||
refocusNode(this.blockId);
|
||||
return true;
|
||||
const conn = globalStore.get(this.connection);
|
||||
try {
|
||||
const newFileInfo = await WshServer.RemoteFileJoinCommand([fileInfo.dir, filePath], {
|
||||
route: makeConnRoute(conn),
|
||||
});
|
||||
this.updateOpenFileModalAndError(false);
|
||||
this.goHistory(newFileInfo.path);
|
||||
refocusNode(this.blockId);
|
||||
} catch (e) {
|
||||
globalStore.set(this.openFileError, e.message);
|
||||
console.error("Error opening file", fileInfo.dir, filePath, e);
|
||||
}
|
||||
}
|
||||
|
||||
isSpecializedView(sv: string): boolean {
|
||||
|
@ -132,6 +132,12 @@ func RemoteFileInfoCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpts)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// command "remotefilejoin", wshserver.RemoteFileJoinCommand
|
||||
func RemoteFileJoinCommand(w *wshutil.WshRpc, data []string, opts *wshrpc.RpcOpts) (*wshrpc.FileInfo, error) {
|
||||
resp, err := sendRpcRequestCallHelper[*wshrpc.FileInfo](w, "remotefilejoin", data, opts)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// command "remotestreamcpudata", wshserver.RemoteStreamCpuDataCommand
|
||||
func RemoteStreamCpuDataCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) chan wshrpc.RespOrErrorUnion[wshrpc.TimeSeriesData] {
|
||||
return sendRpcRequestResponseStreamHelper[wshrpc.TimeSeriesData](w, "remotestreamcpudata", nil, opts)
|
||||
|
@ -279,6 +279,27 @@ func (*ServerImpl) fileInfoInternal(path string, extended bool) (*wshrpc.FileInf
|
||||
return rtn, nil
|
||||
}
|
||||
|
||||
func resolvePaths(paths []string) string {
|
||||
if len(paths) == 0 {
|
||||
return wavebase.ExpandHomeDir("~")
|
||||
}
|
||||
var rtnPath = wavebase.ExpandHomeDir(paths[0])
|
||||
for _, path := range paths[1:] {
|
||||
path = wavebase.ExpandHomeDir(path)
|
||||
if filepath.IsAbs(path) {
|
||||
rtnPath = path
|
||||
continue
|
||||
}
|
||||
rtnPath = filepath.Join(rtnPath, path)
|
||||
}
|
||||
return rtnPath
|
||||
}
|
||||
|
||||
func (impl *ServerImpl) RemoteFileJoinCommand(ctx context.Context, paths []string) (*wshrpc.FileInfo, error) {
|
||||
rtnPath := resolvePaths(paths)
|
||||
return impl.fileInfoInternal(rtnPath, true)
|
||||
}
|
||||
|
||||
func (impl *ServerImpl) RemoteFileInfoCommand(ctx context.Context, path string) (*wshrpc.FileInfo, error) {
|
||||
return impl.fileInfoInternal(path, true)
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ const (
|
||||
Command_RemoteFileInfo = "remotefileinfo"
|
||||
Command_RemoteWriteFile = "remotewritefile"
|
||||
Command_RemoteFileDelete = "remotefiledelete"
|
||||
Command_RemoteFileJoiin = "remotefilejoin"
|
||||
)
|
||||
|
||||
type RespOrErrorUnion[T any] struct {
|
||||
@ -105,6 +106,7 @@ type WshRpcInterface interface {
|
||||
RemoteFileInfoCommand(ctx context.Context, path string) (*FileInfo, error)
|
||||
RemoteFileDeleteCommand(ctx context.Context, path string) error
|
||||
RemoteWriteFileCommand(ctx context.Context, data CommandRemoteWriteFileData) error
|
||||
RemoteFileJoinCommand(ctx context.Context, paths []string) (*FileInfo, error)
|
||||
RemoteStreamCpuDataCommand(ctx context.Context) chan RespOrErrorUnion[TimeSeriesData]
|
||||
}
|
||||
|
||||
|
@ -111,12 +111,11 @@ func (router *WshRouter) handleNoRoute(msg RpcMessage) {
|
||||
}
|
||||
// send error response
|
||||
response := RpcMessage{
|
||||
Route: msg.Source,
|
||||
ResId: msg.ReqId,
|
||||
Error: nrErr.Error(),
|
||||
}
|
||||
respBytes, _ := json.Marshal(response)
|
||||
router.InputCh <- msgAndRoute{msgBytes: respBytes, fromRouteId: SysRoute}
|
||||
router.sendRoutedMessage(respBytes, msg.Source)
|
||||
}
|
||||
|
||||
func (router *WshRouter) registerRouteInfo(rpcId string, sourceRouteId string, destRouteId string) {
|
||||
|
Loading…
Reference in New Issue
Block a user