mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-03-11 13:23:06 +01:00
wsh view with an http url will open web
This commit is contained in:
parent
c192fe2663
commit
b057bd2078
@ -7,6 +7,7 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/wshrpc"
|
"github.com/wavetermdev/thenextwave/pkg/wshrpc"
|
||||||
@ -29,29 +30,41 @@ func init() {
|
|||||||
|
|
||||||
func viewRun(cmd *cobra.Command, args []string) {
|
func viewRun(cmd *cobra.Command, args []string) {
|
||||||
fileArg := args[0]
|
fileArg := args[0]
|
||||||
absFile, err := filepath.Abs(fileArg)
|
var wshCmd *wshrpc.CommandCreateBlockData
|
||||||
if err != nil {
|
if strings.HasPrefix(fileArg, "http://") || strings.HasPrefix(fileArg, "https://") {
|
||||||
WriteStderr("[error] getting absolute path: %v\n", err)
|
wshCmd = &wshrpc.CommandCreateBlockData{
|
||||||
return
|
BlockDef: &wstore.BlockDef{
|
||||||
}
|
Meta: map[string]interface{}{
|
||||||
_, err = os.Stat(absFile)
|
wstore.MetaKey_View: "web",
|
||||||
if err == fs.ErrNotExist {
|
wstore.MetaKey_Url: fileArg,
|
||||||
WriteStderr("[error] file does not exist: %q\n", absFile)
|
},
|
||||||
return
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
WriteStderr("[error] getting file info: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
viewWshCmd := &wshrpc.CommandCreateBlockData{
|
|
||||||
BlockDef: &wstore.BlockDef{
|
|
||||||
Meta: map[string]interface{}{
|
|
||||||
wstore.MetaKey_View: "preview",
|
|
||||||
wstore.MetaKey_File: absFile,
|
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
} else {
|
||||||
|
absFile, err := filepath.Abs(fileArg)
|
||||||
|
if err != nil {
|
||||||
|
WriteStderr("[error] getting absolute path: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = os.Stat(absFile)
|
||||||
|
if err == fs.ErrNotExist {
|
||||||
|
WriteStderr("[error] file does not exist: %q\n", absFile)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
WriteStderr("[error] getting file info: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wshCmd = &wshrpc.CommandCreateBlockData{
|
||||||
|
BlockDef: &wstore.BlockDef{
|
||||||
|
Meta: map[string]interface{}{
|
||||||
|
wstore.MetaKey_View: "preview",
|
||||||
|
wstore.MetaKey_File: absFile,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_, err = RpcClient.SendRpcRequest(wshrpc.Command_CreateBlock, viewWshCmd, 2000)
|
_, err := RpcClient.SendRpcRequest(wshrpc.Command_CreateBlock, wshCmd, 2000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
WriteStderr("[error] running view command: %v\r\n", err)
|
WriteStderr("[error] running view command: %v\r\n", err)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user