update sharename

This commit is contained in:
sawka
2023-04-04 22:28:52 -07:00
parent f6c6a40aba
commit 0ee3af71bd
3 changed files with 22 additions and 4 deletions
+11 -1
View File
@@ -620,6 +620,16 @@ func ScreenSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ss
varsUpdated = append(varsUpdated, "name")
setNonAnchor = true
}
if pk.Kwargs["sharename"] != "" {
shareName := pk.Kwargs["sharename"]
err = validateShareName(shareName)
if err != nil {
return nil, err
}
updateMap[sstore.ScreenField_ShareName] = shareName
varsUpdated = append(varsUpdated, "sharename")
setNonAnchor = true
}
if pk.Kwargs["tabcolor"] != "" {
color := pk.Kwargs["tabcolor"]
err = validateColor(color, "screen tabcolor")
@@ -679,7 +689,7 @@ func ScreenSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ss
}
}
if len(varsUpdated) == 0 {
return nil, fmt.Errorf("/screen:set no updates, can set %s", formatStrs([]string{"name", "pos", "tabcolor", "focus", "anchor", "line"}, "or", false))
return nil, fmt.Errorf("/screen:set no updates, can set %s", formatStrs([]string{"name", "pos", "tabcolor", "focus", "anchor", "line", "sharename"}, "or", false))
}
screen, err := sstore.UpdateScreen(ctx, ids.ScreenId, updateMap)
if err != nil {
+9
View File
@@ -1707,6 +1707,7 @@ const (
ScreenField_TabColor = "tabcolor" // string
ScreenField_PTerm = "pterm" // string
ScreenField_Name = "name" // string
ScreenField_ShareName = "sharename" // string
)
func UpdateScreen(ctx context.Context, screenId string, editMap map[string]interface{}) (*ScreenType, error) {
@@ -1746,6 +1747,14 @@ func UpdateScreen(ctx context.Context, screenId string, editMap map[string]inter
query = `UPDATE screen SET name = ? WHERE screenid = ?`
tx.Exec(query, name, screenId)
}
if shareName, found := editMap[ScreenField_ShareName]; found {
if !isWebShare(tx, screenId) {
return fmt.Errorf("cannot set sharename, screen is not web-shared")
}
query = `UPDATE screen SET webshareopts = json_set(webshareopts, '$.sharename', ?) WHERE screenid = ?`
tx.Exec(query, shareName, screenId)
insertScreenUpdate(tx, screenId, UpdateType_ScreenName)
}
return nil
})
if txErr != nil {
+2 -3
View File
@@ -386,9 +386,8 @@ type ScreenLinesType struct {
func (ScreenLinesType) UseDBMap() {}
type ScreenWebShareOpts struct {
ShareName string `json:"sharename"`
ViewKey string `json:"viewkey"`
SharedRemotes []string `json:"sharedremotes"`
ShareName string `json:"sharename"`
ViewKey string `json:"viewkey"`
}
type ScreenType struct {