fix rpc no-route errors, fix fileopen in preview (#313)

This commit is contained in:
Mike Sawka 2024-09-03 21:08:51 -07:00 committed by GitHub
parent 558fda1253
commit a7746bc5cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 63 additions and 9 deletions

View File

@ -103,6 +103,14 @@ function handleIncomingRpcMessage(msg: RpcMessage, eventHandlerFn: (event: WaveE
} }
return; 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); console.log("rpc command not supported", msg);
return; return;

View File

@ -107,6 +107,11 @@ class WshServerType {
return WOS.wshServerRpcHelper_call("remotefileinfo", data, opts); 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] // command "remotestreamcpudata" [responsestream]
RemoteStreamCpuDataCommand(opts?: RpcOpts): AsyncGenerator<TimeSeriesData, void, boolean> { RemoteStreamCpuDataCommand(opts?: RpcOpts): AsyncGenerator<TimeSeriesData, void, boolean> {
return WOS.wshServerRpcHelper_responsestream("remotestreamcpudata", null, opts); return WOS.wshServerRpcHelper_responsestream("remotestreamcpudata", null, opts);

View File

@ -4,6 +4,7 @@
import { TypeAheadModal } from "@/app/modals/typeaheadmodal"; import { TypeAheadModal } from "@/app/modals/typeaheadmodal";
import { ContextMenuModel } from "@/app/store/contextmenu"; import { ContextMenuModel } from "@/app/store/contextmenu";
import { tryReinjectKey } from "@/app/store/keymodel"; import { tryReinjectKey } from "@/app/store/keymodel";
import { WshServer } from "@/app/store/wshserver";
import { Markdown } from "@/element/markdown"; import { Markdown } from "@/element/markdown";
import { NodeModel } from "@/layout/index"; import { NodeModel } from "@/layout/index";
import { createBlock, globalStore, refocusNode } from "@/store/global"; import { createBlock, globalStore, refocusNode } from "@/store/global";
@ -42,6 +43,13 @@ const SpecializedViewMap: { [view: string]: ({ model }: SpecializedViewProps) =>
directory: DirectoryPreview, directory: DirectoryPreview,
}; };
function makeConnRoute(conn: string): string {
if (util.isBlank(conn)) {
return "conn:local";
}
return "conn:" + conn;
}
function isTextFile(mimeType: string): boolean { function isTextFile(mimeType: string): boolean {
if (mimeType == null) { if (mimeType == null) {
return false; return false;
@ -484,13 +492,18 @@ export class PreviewModel implements ViewModel {
this.updateOpenFileModalAndError(false); this.updateOpenFileModalAndError(false);
return true; return true;
} }
const newPath = fileInfo.dir + "/" + filePath; const conn = globalStore.get(this.connection);
const conn = globalStore.get(this.connection) ?? ""; try {
const newFileInfo = await services.FileService.StatFile(conn, newPath); const newFileInfo = await WshServer.RemoteFileJoinCommand([fileInfo.dir, filePath], {
route: makeConnRoute(conn),
});
this.updateOpenFileModalAndError(false); this.updateOpenFileModalAndError(false);
this.goHistory(newFileInfo.path); this.goHistory(newFileInfo.path);
refocusNode(this.blockId); refocusNode(this.blockId);
return true; } catch (e) {
globalStore.set(this.openFileError, e.message);
console.error("Error opening file", fileInfo.dir, filePath, e);
}
} }
isSpecializedView(sv: string): boolean { isSpecializedView(sv: string): boolean {

View File

@ -132,6 +132,12 @@ func RemoteFileInfoCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpts)
return resp, err 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 // command "remotestreamcpudata", wshserver.RemoteStreamCpuDataCommand
func RemoteStreamCpuDataCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) chan wshrpc.RespOrErrorUnion[wshrpc.TimeSeriesData] { func RemoteStreamCpuDataCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) chan wshrpc.RespOrErrorUnion[wshrpc.TimeSeriesData] {
return sendRpcRequestResponseStreamHelper[wshrpc.TimeSeriesData](w, "remotestreamcpudata", nil, opts) return sendRpcRequestResponseStreamHelper[wshrpc.TimeSeriesData](w, "remotestreamcpudata", nil, opts)

View File

@ -279,6 +279,27 @@ func (*ServerImpl) fileInfoInternal(path string, extended bool) (*wshrpc.FileInf
return rtn, nil 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) { func (impl *ServerImpl) RemoteFileInfoCommand(ctx context.Context, path string) (*wshrpc.FileInfo, error) {
return impl.fileInfoInternal(path, true) return impl.fileInfoInternal(path, true)
} }

View File

@ -62,6 +62,7 @@ const (
Command_RemoteFileInfo = "remotefileinfo" Command_RemoteFileInfo = "remotefileinfo"
Command_RemoteWriteFile = "remotewritefile" Command_RemoteWriteFile = "remotewritefile"
Command_RemoteFileDelete = "remotefiledelete" Command_RemoteFileDelete = "remotefiledelete"
Command_RemoteFileJoiin = "remotefilejoin"
) )
type RespOrErrorUnion[T any] struct { type RespOrErrorUnion[T any] struct {
@ -105,6 +106,7 @@ type WshRpcInterface interface {
RemoteFileInfoCommand(ctx context.Context, path string) (*FileInfo, error) RemoteFileInfoCommand(ctx context.Context, path string) (*FileInfo, error)
RemoteFileDeleteCommand(ctx context.Context, path string) error RemoteFileDeleteCommand(ctx context.Context, path string) error
RemoteWriteFileCommand(ctx context.Context, data CommandRemoteWriteFileData) error RemoteWriteFileCommand(ctx context.Context, data CommandRemoteWriteFileData) error
RemoteFileJoinCommand(ctx context.Context, paths []string) (*FileInfo, error)
RemoteStreamCpuDataCommand(ctx context.Context) chan RespOrErrorUnion[TimeSeriesData] RemoteStreamCpuDataCommand(ctx context.Context) chan RespOrErrorUnion[TimeSeriesData]
} }

View File

@ -111,12 +111,11 @@ func (router *WshRouter) handleNoRoute(msg RpcMessage) {
} }
// send error response // send error response
response := RpcMessage{ response := RpcMessage{
Route: msg.Source,
ResId: msg.ReqId, ResId: msg.ReqId,
Error: nrErr.Error(), Error: nrErr.Error(),
} }
respBytes, _ := json.Marshal(response) 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) { func (router *WshRouter) registerRouteInfo(rpcId string, sourceRouteId string, destRouteId string) {