mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
remove websharing backend, migrate db to stop websharing any screens that are currently shared
This commit is contained in:
parent
0df800a390
commit
54c2087ad6
1
db/migrations/000022_endwebshare.down.sql
Normal file
1
db/migrations/000022_endwebshare.down.sql
Normal file
@ -0,0 +1 @@
|
||||
-- no down migration
|
1
db/migrations/000022_endwebshare.up.sql
Normal file
1
db/migrations/000022_endwebshare.up.sql
Normal file
@ -0,0 +1 @@
|
||||
UPDATE screen SET sharemode = 'local' AND webshareopts = 'null';
|
@ -3,8 +3,6 @@ package cmdrunner
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
@ -1956,83 +1954,7 @@ func makeExternLink(urlStr string) string {
|
||||
}
|
||||
|
||||
func ScreenWebShareCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
|
||||
ids, err := resolveUiIds(ctx, pk, R_Screen)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
shouldShare := true
|
||||
if len(pk.Args) > 0 {
|
||||
shouldShare = resolveBool(pk.Args[0], true)
|
||||
}
|
||||
shareName := pk.Kwargs["sharename"]
|
||||
if err := validateShareName(shareName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var infoMsg string
|
||||
var infoWebShareLink bool
|
||||
if shouldShare {
|
||||
viewKeyBytes := make([]byte, 9)
|
||||
_, err = rand.Read(viewKeyBytes)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create viewkey: %v", err)
|
||||
}
|
||||
screen, err := sstore.GetScreenById(ctx, ids.ScreenId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get screen: %v", err)
|
||||
}
|
||||
if shareName == "" {
|
||||
shareName = screen.Name
|
||||
}
|
||||
viewKey := base64.RawURLEncoding.EncodeToString(viewKeyBytes)
|
||||
webShareOpts := sstore.ScreenWebShareOpts{ShareName: shareName, ViewKey: viewKey}
|
||||
err = sstore.CanScreenWebShare(ctx, screen)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
webUpdate := pcloud.MakeScreenNewUpdate(screen, webShareOpts)
|
||||
err = pcloud.DoSyncWebUpdate(webUpdate)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error starting webshare, error contacting prompt cloud server: %v", err)
|
||||
}
|
||||
err = sstore.ScreenWebShareStart(ctx, ids.ScreenId, webShareOpts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot webshare screen, error updating: %v", err)
|
||||
}
|
||||
infoWebShareLink = true
|
||||
} else {
|
||||
screen, err := sstore.GetScreenById(ctx, ids.ScreenId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get screen: %v", err)
|
||||
}
|
||||
if screen == nil {
|
||||
return nil, fmt.Errorf("screen not found")
|
||||
}
|
||||
if screen.ShareMode != sstore.ShareModeWeb {
|
||||
return nil, fmt.Errorf("screen is not currently shared")
|
||||
}
|
||||
webUpdate := pcloud.MakeScreenDelUpdate(screen, ids.ScreenId)
|
||||
err = pcloud.DoSyncWebUpdate(webUpdate)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error stopping webshare, error contacting prompt cloud server: %v", err)
|
||||
}
|
||||
err = sstore.ScreenWebShareStop(ctx, ids.ScreenId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot stop web-sharing screen: %v", err)
|
||||
}
|
||||
infoMsg = fmt.Sprintf("screen websharing stopped")
|
||||
}
|
||||
screen, err := sstore.GetScreenById(ctx, ids.ScreenId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get updated screen: %v", err)
|
||||
}
|
||||
update := &sstore.ModelUpdate{
|
||||
Screens: []*sstore.ScreenType{screen},
|
||||
Info: &sstore.InfoMsgType{
|
||||
InfoMsg: infoMsg,
|
||||
WebShareLink: infoWebShareLink,
|
||||
},
|
||||
}
|
||||
return update, nil
|
||||
return nil, fmt.Errorf("websharing is no longer available")
|
||||
}
|
||||
|
||||
func SessionDeleteCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
)
|
||||
|
||||
const MaxMigration = 21
|
||||
const MaxMigration = 22
|
||||
const MigratePrimaryScreenVersion = 9
|
||||
const CmdScreenSpecialMigration = 13
|
||||
const CmdLineSpecialMigration = 20
|
||||
|
Loading…
Reference in New Issue
Block a user