feat(backend-http): IOSBatchMeta + init s3 for image

This commit is contained in:
ShiKhu 2021-11-09 18:19:29 +01:00
parent 0c8f5e400a
commit d2b589bd01
4 changed files with 32 additions and 1 deletions

View file

@ -30,6 +30,14 @@ func ReadBatch(b []byte, callback func(Message)) error {
timestamp = m.Timestamp
isBatchMeta = true
// continue readLoop
case *IOSBatchMeta:
if index != 0 { // Might be several 0-0 BatchMeta in a row without a error though
return errors.New("Batch Meta found at the end of the batch")
}
index = m.FirstIndex
timestamp = int64(m.Timestamp)
isBatchMeta = true
// continue readLoop
case *Timestamp:
timestamp = int64(m.Timestamp) // TODO(?): replace timestamp type to int64 everywhere (including encoding part in tracker)
// No skipping here for making it easy to encode back the same sequence of message

View file

@ -1192,6 +1192,22 @@ p = WriteUint(msg.ID, buf, p)
return buf[:p]
}
type IOSBatchMeta struct {
*meta
Timestamp uint64
Length uint64
FirstIndex uint64
}
func (msg *IOSBatchMeta) Encode() []byte{
buf := make([]byte, 31 )
buf[0] = 107
p := 1
p = WriteUint(msg.Timestamp, buf, p)
p = WriteUint(msg.Length, buf, p)
p = WriteUint(msg.FirstIndex, buf, p)
return buf[:p]
}
type IOSSessionStart struct {
*meta
Timestamp uint64

View file

@ -532,6 +532,13 @@ if msg.Selector, err = ReadString(reader); err != nil { return nil, err }
if msg.ID, err = ReadUint(reader); err != nil { return nil, err }
return msg, nil
case 107:
msg := &IOSBatchMeta{ meta: &meta{ TypeID: 107} }
if msg.Timestamp, err = ReadUint(reader); err != nil { return nil, err }
if msg.Length, err = ReadUint(reader); err != nil { return nil, err }
if msg.FirstIndex, err = ReadUint(reader); err != nil { return nil, err }
return msg, nil
case 90:
msg := &IOSSessionStart{ meta: &meta{ TypeID: 90} }
if msg.Timestamp, err = ReadUint(reader); err != nil { return nil, err }

View file

@ -52,7 +52,7 @@ func main() {
rewriter = assets.NewRewriter(env.String("ASSETS_ORIGIN"))
pgconn = cache.NewPGCache(postgres.NewConn(env.String("POSTGRES_STRING")), 1000 * 60 * 20)
defer pgconn.Close()
//s3 = storage.NewS3(env.String("S3_BUCKET_IMAGES_IOS"), env.String("AWS_REGION"))
s3 = storage.NewS3(env.String("S3_BUCKET_IOS_IMAGES"), env.String("AWS_REGION"))
tokenizer = token.NewTokenizer(env.String("TOKEN_SECRET"))
uaParser = uaparser.NewUAParser(env.String("UAPARSER_FILE"))
geoIP = geoip.NewGeoIP(env.String("MAXMINDDB_FILE"))