An atproto PDS written in Go

parse and validate record against atproto model (#5)

authored by juli.ee and committed by GitHub 573e83c0 3e890acb

Changed files
+29 -6
server
+29 -6
server/repo.go
··· 3 3 import ( 4 4 "bytes" 5 5 "context" 6 + "encoding/json" 6 7 "fmt" 7 8 "io" 8 9 "time" ··· 123 124 124 125 switch op.Type { 125 126 case OpTypeCreate: 126 - nc, err := r.PutRecord(context.TODO(), op.Collection+"/"+*op.Rkey, op.Record) 127 + j, err := json.Marshal(*op.Record) 128 + if err != nil { 129 + return nil, err 130 + } 131 + out, err := data.UnmarshalJSON(j) 132 + if err != nil { 133 + return nil, err 134 + } 135 + mm := MarshalableMap(out) 136 + nc, err := r.PutRecord(context.TODO(), op.Collection+"/"+*op.Rkey, &mm) 127 137 if err != nil { 128 138 return nil, err 129 139 } 130 - 131 - d, _ := data.MarshalCBOR(*op.Record) 140 + d, err := data.MarshalCBOR(mm) 141 + if err != nil { 142 + return nil, err 143 + } 132 144 entries = append(entries, models.Record{ 133 145 Did: urepo.Did, 134 146 CreatedAt: rm.clock.Next().String(), ··· 162 174 Type: to.StringPtr(OpTypeDelete.String()), 163 175 }) 164 176 case OpTypeUpdate: 165 - nc, err := r.UpdateRecord(context.TODO(), op.Collection+"/"+*op.Rkey, op.Record) 177 + j, err := json.Marshal(*op.Record) 178 + if err != nil { 179 + return nil, err 180 + } 181 + out, err := data.UnmarshalJSON(j) 182 + if err != nil { 183 + return nil, err 184 + } 185 + mm := MarshalableMap(out) 186 + nc, err := r.UpdateRecord(context.TODO(), op.Collection+"/"+*op.Rkey, &mm) 166 187 if err != nil { 167 188 return nil, err 168 189 } 169 - 170 - d, _ := data.MarshalCBOR(*op.Record) 190 + d, err := data.MarshalCBOR(mm) 191 + if err != nil { 192 + return nil, err 193 + } 171 194 entries = append(entries, models.Record{ 172 195 Did: urepo.Did, 173 196 CreatedAt: rm.clock.Next().String(),