feat(backend):rewrite adoptedStyleSheet style messages

This commit is contained in:
Alex Kaminskii 2022-08-17 20:05:35 +02:00
parent c31f878ef6
commit fe11fb06dc
5 changed files with 393 additions and 50 deletions

View file

@ -134,6 +134,7 @@ func (e *Router) startSessionHandlerWeb(w http.ResponseWriter, r *http.Request)
UserUUID: userUUID,
SessionID: strconv.FormatUint(tokenData.ID, 10),
BeaconSizeLimit: e.cfg.BeaconSizeLimit,
Timestamp: e.services.Flaker.ExtractTimestamp(tokenData.ID),
})
}

View file

@ -57,8 +57,21 @@ func (e *AssetsCache) ParseAssets(sessID uint64, msg messages.Message) messages.
}
newMsg.SetMeta(msg.Meta())
return newMsg
case *messages.AdoptedSSReplaceURLBased:
newMsg := &messages.AdoptedSSReplace{
SheetID: m.SheetID,
Text: e.handleCSS(sessID, m.BaseURL, m.Text),
}
case *messages.AdoptedSSInsertRuleURLBased:
newMsg := &messages.AdoptedSSInsertRule{
SheetID: m.SheetID,
Index: m.Index,
Rule: e.handleCSS(sessID, m.BaseURL, m.Rule),
}
newMsg.SetMeta(msg.Meta())
return msg
}
return msg
}
func (e *AssetsCache) sendAssetForCache(sessionID uint64, baseURL string, relativeURL string) {

View file

@ -2,7 +2,7 @@
package messages
func IsReplayerType(id int) bool {
return 0 == id || 2 == id || 4 == id || 5 == id || 6 == id || 7 == id || 8 == id || 9 == id || 10 == id || 11 == id || 12 == id || 13 == id || 14 == id || 15 == id || 16 == id || 18 == id || 19 == id || 20 == id || 22 == id || 37 == id || 38 == id || 39 == id || 40 == id || 41 == id || 44 == id || 45 == id || 46 == id || 47 == id || 48 == id || 49 == id || 54 == id || 55 == id || 59 == id || 69 == id || 70 == id || 90 == id || 93 == id || 96 == id || 100 == id || 102 == id || 103 == id || 105 == id
return 0 == id || 4 == id || 5 == id || 6 == id || 7 == id || 8 == id || 9 == id || 10 == id || 11 == id || 12 == id || 13 == id || 14 == id || 15 == id || 16 == id || 18 == id || 19 == id || 20 == id || 22 == id || 37 == id || 38 == id || 39 == id || 40 == id || 41 == id || 44 == id || 45 == id || 46 == id || 47 == id || 48 == id || 49 == id || 54 == id || 55 == id || 59 == id || 60 == id || 61 == id || 67 == id || 69 == id || 70 == id || 71 == id || 72 == id || 73 == id || 74 == id || 75 == id || 76 == id || 77 == id || 90 == id || 93 == id || 96 == id || 100 == id || 102 == id || 103 == id || 105 == id
}
func IsIOSType(id int) bool {

View file

@ -1,8 +1,6 @@
// Auto-generated, do not edit
package messages
import "encoding/binary"
const (
MsgBatchMeta = 80
@ -14,8 +12,6 @@ const (
MsgSessionStart = 1
MsgSessionDisconnect = 2
MsgSessionEnd = 3
MsgSetPageLocation = 4
@ -144,6 +140,20 @@ const (
MsgCreateIFrameDocument = 70
MsgAdoptedSSReplaceURLBased = 71
MsgAdoptedSSReplace = 72
MsgAdoptedSSInsertRuleURLBased = 73
MsgAdoptedSSInsertRule = 74
MsgAdoptedSSDeleteRule = 75
MsgAdoptedSSAddOwner = 76
MsgAdoptedSSRemoveOwner = 77
MsgIOSBatchMeta = 107
MsgIOSSessionStart = 90
@ -387,38 +397,6 @@ func (msg *SessionStart) TypeID() int {
return 1
}
type SessionDisconnect struct {
message
Timestamp uint64
}
func (msg *SessionDisconnect) Encode() []byte {
buf := make([]byte, 11)
buf[0] = 2
p := 1
p = WriteUint(msg.Timestamp, buf, p)
return buf[:p]
}
func (msg *SessionDisconnect) EncodeWithIndex() []byte {
encoded := msg.Encode()
if IsIOSType(msg.TypeID()) {
return encoded
}
data := make([]byte, len(encoded)+8)
copy(data[8:], encoded[:])
binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index)
return data
}
func (msg *SessionDisconnect) Decode() Message {
return msg
}
func (msg *SessionDisconnect) TypeID() int {
return 2
}
type SessionEnd struct {
message
Timestamp uint64
@ -2812,6 +2790,252 @@ func (msg *CreateIFrameDocument) TypeID() int {
return 70
}
type AdoptedSSReplaceURLBased struct {
message
SheetID uint64
Text string
BaseURL string
}
func (msg *AdoptedSSReplaceURLBased) Encode() []byte {
buf := make([]byte, 31+len(msg.Text)+len(msg.BaseURL))
buf[0] = 71
p := 1
p = WriteUint(msg.SheetID, buf, p)
p = WriteString(msg.Text, buf, p)
p = WriteString(msg.BaseURL, buf, p)
return buf[:p]
}
func (msg *AdoptedSSReplaceURLBased) EncodeWithIndex() []byte {
encoded := msg.Encode()
if IsIOSType(msg.TypeID()) {
return encoded
}
data := make([]byte, len(encoded)+8)
copy(data[8:], encoded[:])
binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index)
return data
}
func (msg *AdoptedSSReplaceURLBased) Decode() Message {
return msg
}
func (msg *AdoptedSSReplaceURLBased) TypeID() int {
return 71
}
type AdoptedSSReplace struct {
message
SheetID uint64
Text string
}
func (msg *AdoptedSSReplace) Encode() []byte {
buf := make([]byte, 21+len(msg.Text))
buf[0] = 72
p := 1
p = WriteUint(msg.SheetID, buf, p)
p = WriteString(msg.Text, buf, p)
return buf[:p]
}
func (msg *AdoptedSSReplace) EncodeWithIndex() []byte {
encoded := msg.Encode()
if IsIOSType(msg.TypeID()) {
return encoded
}
data := make([]byte, len(encoded)+8)
copy(data[8:], encoded[:])
binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index)
return data
}
func (msg *AdoptedSSReplace) Decode() Message {
return msg
}
func (msg *AdoptedSSReplace) TypeID() int {
return 72
}
type AdoptedSSInsertRuleURLBased struct {
message
SheetID uint64
Rule string
Index uint64
BaseURL string
}
func (msg *AdoptedSSInsertRuleURLBased) Encode() []byte {
buf := make([]byte, 41+len(msg.Rule)+len(msg.BaseURL))
buf[0] = 73
p := 1
p = WriteUint(msg.SheetID, buf, p)
p = WriteString(msg.Rule, buf, p)
p = WriteUint(msg.Index, buf, p)
p = WriteString(msg.BaseURL, buf, p)
return buf[:p]
}
func (msg *AdoptedSSInsertRuleURLBased) EncodeWithIndex() []byte {
encoded := msg.Encode()
if IsIOSType(msg.TypeID()) {
return encoded
}
data := make([]byte, len(encoded)+8)
copy(data[8:], encoded[:])
binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index)
return data
}
func (msg *AdoptedSSInsertRuleURLBased) Decode() Message {
return msg
}
func (msg *AdoptedSSInsertRuleURLBased) TypeID() int {
return 73
}
type AdoptedSSInsertRule struct {
message
SheetID uint64
Rule string
Index uint64
}
func (msg *AdoptedSSInsertRule) Encode() []byte {
buf := make([]byte, 31+len(msg.Rule))
buf[0] = 74
p := 1
p = WriteUint(msg.SheetID, buf, p)
p = WriteString(msg.Rule, buf, p)
p = WriteUint(msg.Index, buf, p)
return buf[:p]
}
func (msg *AdoptedSSInsertRule) EncodeWithIndex() []byte {
encoded := msg.Encode()
if IsIOSType(msg.TypeID()) {
return encoded
}
data := make([]byte, len(encoded)+8)
copy(data[8:], encoded[:])
binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index)
return data
}
func (msg *AdoptedSSInsertRule) Decode() Message {
return msg
}
func (msg *AdoptedSSInsertRule) TypeID() int {
return 74
}
type AdoptedSSDeleteRule struct {
message
SheetID uint64
Index uint64
}
func (msg *AdoptedSSDeleteRule) Encode() []byte {
buf := make([]byte, 21)
buf[0] = 75
p := 1
p = WriteUint(msg.SheetID, buf, p)
p = WriteUint(msg.Index, buf, p)
return buf[:p]
}
func (msg *AdoptedSSDeleteRule) EncodeWithIndex() []byte {
encoded := msg.Encode()
if IsIOSType(msg.TypeID()) {
return encoded
}
data := make([]byte, len(encoded)+8)
copy(data[8:], encoded[:])
binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index)
return data
}
func (msg *AdoptedSSDeleteRule) Decode() Message {
return msg
}
func (msg *AdoptedSSDeleteRule) TypeID() int {
return 75
}
type AdoptedSSAddOwner struct {
message
SheetID uint64
ID uint64
}
func (msg *AdoptedSSAddOwner) Encode() []byte {
buf := make([]byte, 21)
buf[0] = 76
p := 1
p = WriteUint(msg.SheetID, buf, p)
p = WriteUint(msg.ID, buf, p)
return buf[:p]
}
func (msg *AdoptedSSAddOwner) EncodeWithIndex() []byte {
encoded := msg.Encode()
if IsIOSType(msg.TypeID()) {
return encoded
}
data := make([]byte, len(encoded)+8)
copy(data[8:], encoded[:])
binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index)
return data
}
func (msg *AdoptedSSAddOwner) Decode() Message {
return msg
}
func (msg *AdoptedSSAddOwner) TypeID() int {
return 76
}
type AdoptedSSRemoveOwner struct {
message
SheetID uint64
ID uint64
}
func (msg *AdoptedSSRemoveOwner) Encode() []byte {
buf := make([]byte, 21)
buf[0] = 77
p := 1
p = WriteUint(msg.SheetID, buf, p)
p = WriteUint(msg.ID, buf, p)
return buf[:p]
}
func (msg *AdoptedSSRemoveOwner) EncodeWithIndex() []byte {
encoded := msg.Encode()
if IsIOSType(msg.TypeID()) {
return encoded
}
data := make([]byte, len(encoded)+8)
copy(data[8:], encoded[:])
binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index)
return data
}
func (msg *AdoptedSSRemoveOwner) Decode() Message {
return msg
}
func (msg *AdoptedSSRemoveOwner) TypeID() int {
return 77
}
type IOSBatchMeta struct {
message
Timestamp uint64

View file

@ -117,15 +117,6 @@ func DecodeSessionStart(reader io.Reader) (Message, error) {
return msg, err
}
func DecodeSessionDisconnect(reader io.Reader) (Message, error) {
var err error = nil
msg := &SessionDisconnect{}
if msg.Timestamp, err = ReadUint(reader); err != nil {
return nil, err
}
return msg, err
}
func DecodeSessionEnd(reader io.Reader) (Message, error) {
var err error = nil
msg := &SessionEnd{}
@ -1219,6 +1210,102 @@ func DecodeCreateIFrameDocument(reader io.Reader) (Message, error) {
return msg, err
}
func DecodeAdoptedSSReplaceURLBased(reader io.Reader) (Message, error) {
var err error = nil
msg := &AdoptedSSReplaceURLBased{}
if msg.SheetID, err = ReadUint(reader); err != nil {
return nil, err
}
if msg.Text, err = ReadString(reader); err != nil {
return nil, err
}
if msg.BaseURL, err = ReadString(reader); err != nil {
return nil, err
}
return msg, err
}
func DecodeAdoptedSSReplace(reader io.Reader) (Message, error) {
var err error = nil
msg := &AdoptedSSReplace{}
if msg.SheetID, err = ReadUint(reader); err != nil {
return nil, err
}
if msg.Text, err = ReadString(reader); err != nil {
return nil, err
}
return msg, err
}
func DecodeAdoptedSSInsertRuleURLBased(reader io.Reader) (Message, error) {
var err error = nil
msg := &AdoptedSSInsertRuleURLBased{}
if msg.SheetID, err = ReadUint(reader); err != nil {
return nil, err
}
if msg.Rule, err = ReadString(reader); err != nil {
return nil, err
}
if msg.Index, err = ReadUint(reader); err != nil {
return nil, err
}
if msg.BaseURL, err = ReadString(reader); err != nil {
return nil, err
}
return msg, err
}
func DecodeAdoptedSSInsertRule(reader io.Reader) (Message, error) {
var err error = nil
msg := &AdoptedSSInsertRule{}
if msg.SheetID, err = ReadUint(reader); err != nil {
return nil, err
}
if msg.Rule, err = ReadString(reader); err != nil {
return nil, err
}
if msg.Index, err = ReadUint(reader); err != nil {
return nil, err
}
return msg, err
}
func DecodeAdoptedSSDeleteRule(reader io.Reader) (Message, error) {
var err error = nil
msg := &AdoptedSSDeleteRule{}
if msg.SheetID, err = ReadUint(reader); err != nil {
return nil, err
}
if msg.Index, err = ReadUint(reader); err != nil {
return nil, err
}
return msg, err
}
func DecodeAdoptedSSAddOwner(reader io.Reader) (Message, error) {
var err error = nil
msg := &AdoptedSSAddOwner{}
if msg.SheetID, err = ReadUint(reader); err != nil {
return nil, err
}
if msg.ID, err = ReadUint(reader); err != nil {
return nil, err
}
return msg, err
}
func DecodeAdoptedSSRemoveOwner(reader io.Reader) (Message, error) {
var err error = nil
msg := &AdoptedSSRemoveOwner{}
if msg.SheetID, err = ReadUint(reader); err != nil {
return nil, err
}
if msg.ID, err = ReadUint(reader); err != nil {
return nil, err
}
return msg, err
}
func DecodeIOSBatchMeta(reader io.Reader) (Message, error) {
var err error = nil
msg := &IOSBatchMeta{}
@ -1639,9 +1726,6 @@ func ReadMessage(t uint64, reader io.Reader) (Message, error) {
case 1:
return DecodeSessionStart(reader)
case 2:
return DecodeSessionDisconnect(reader)
case 3:
return DecodeSessionEnd(reader)
@ -1834,6 +1918,27 @@ func ReadMessage(t uint64, reader io.Reader) (Message, error) {
case 70:
return DecodeCreateIFrameDocument(reader)
case 71:
return DecodeAdoptedSSReplaceURLBased(reader)
case 72:
return DecodeAdoptedSSReplace(reader)
case 73:
return DecodeAdoptedSSInsertRuleURLBased(reader)
case 74:
return DecodeAdoptedSSInsertRule(reader)
case 75:
return DecodeAdoptedSSDeleteRule(reader)
case 76:
return DecodeAdoptedSSAddOwner(reader)
case 77:
return DecodeAdoptedSSRemoveOwner(reader)
case 107:
return DecodeIOSBatchMeta(reader)