this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

update lexutil.Blob struct

+85 -38
+3 -3
cmd/fakermaker/main.go
··· 423 423 return err 424 424 } 425 425 avatar = &lexutil.Blob{ 426 - Cid: resp.Blob.Cid, 426 + Ref: resp.Blob.Ref, 427 427 MimeType: "image/png", 428 428 } 429 429 } ··· 435 435 return err 436 436 } 437 437 avatar = &lexutil.Blob{ 438 - Cid: resp.Blob.Cid, 438 + Ref: resp.Blob.Ref, 439 439 MimeType: "image/jpeg", 440 440 } 441 441 } ··· 541 541 images = append(images, &appbsky.EmbedImages_Image{ 542 542 Alt: gofakeit.Lunch(), 543 543 Image: &lexutil.Blob{ 544 - Cid: resp.Blob.Cid, 544 + Ref: resp.Blob.Ref, 545 545 MimeType: "image/jpeg", 546 546 }, 547 547 })
+4 -4
labeling/hiveai.go
··· 100 100 101 101 func (hal *HiveAILabeler) LabelBlob(ctx context.Context, blob lexutil.Blob, blobBytes []byte) ([]string, error) { 102 102 103 - log.Infof("sending blob to thehive.ai cid=%s mimetype=%s size=%d", blob.Cid, blob.MimeType, len(blobBytes)) 103 + log.Infof("sending blob to thehive.ai cid=%s mimetype=%s size=%d", blob.Ref, blob.MimeType, len(blobBytes)) 104 104 105 105 // generic HTTP form file upload, then parse the response JSON 106 106 body := &bytes.Buffer{} 107 107 writer := multipart.NewWriter(body) 108 - part, err := writer.CreateFormFile("media", blob.Cid) 108 + part, err := writer.CreateFormFile("media", blob.Ref.String()) 109 109 if err != nil { 110 110 return nil, err 111 111 } ··· 142 142 return nil, fmt.Errorf("failed to read HiveAI resp body: %v", err) 143 143 } 144 144 145 - log.Debugf("HiveAI raw result cid=%s body=%v", blob.Cid, string(respBytes)) 145 + log.Debugf("HiveAI raw result cid=%s body=%v", blob.Ref, string(respBytes)) 146 146 147 147 var respObj HiveAIResp 148 148 if err := json.Unmarshal(respBytes, &respObj); err != nil { 149 149 return nil, fmt.Errorf("failed to parse HiveAI resp JSON: %v", err) 150 150 } 151 151 respJson, _ := json.Marshal(respObj.Status[0].Response.Output[0]) 152 - log.Infof("HiveAI result cid=%s json=%v", blob.Cid, string(respJson)) 152 + log.Infof("HiveAI result cid=%s json=%v", blob.Ref, string(respJson)) 153 153 return respObj.SummarizeLabels(), nil 154 154 }
+3 -3
labeling/micro_nsfw_img.go
··· 61 61 62 62 func (mnil *MicroNSFWImgLabeler) LabelBlob(ctx context.Context, blob lexutil.Blob, blobBytes []byte) ([]string, error) { 63 63 64 - log.Infof("sending blob to micro-NSFW-img cid=%s mimetype=%s size=%d", blob.Cid, blob.MimeType, len(blobBytes)) 64 + log.Infof("sending blob to micro-NSFW-img cid=%s mimetype=%s size=%d", blob.Ref, blob.MimeType, len(blobBytes)) 65 65 66 66 // generic HTTP form file upload, then parse the response JSON 67 67 body := &bytes.Buffer{} 68 68 writer := multipart.NewWriter(body) 69 - part, err := writer.CreateFormFile("file", blob.Cid) 69 + part, err := writer.CreateFormFile("file", blob.Ref.String()) 70 70 if err != nil { 71 71 return nil, err 72 72 } ··· 105 105 return nil, fmt.Errorf("failed to parse micro-NSFW-img resp JSON: %v", err) 106 106 } 107 107 scoreJson, _ := json.Marshal(nsfwScore) 108 - log.Infof("micro-NSFW-img result cid=%s scores=%v", blob.Cid, string(scoreJson)) 108 + log.Infof("micro-NSFW-img result cid=%s scores=%v", blob.Ref, string(scoreJson)) 109 109 return nsfwScore.SummarizeLabels(), nil 110 110 }
+8 -8
labeling/service.go
··· 159 159 return false 160 160 } 161 161 162 - func (s *Server) labelRecord(ctx context.Context, did, nsid, uri, cid string, rec cbg.CBORMarshaler) ([]string, error) { 162 + func (s *Server) labelRecord(ctx context.Context, did, nsid, uri, cidStr string, rec cbg.CBORMarshaler) ([]string, error) { 163 163 log.Infof("labeling record: %v", uri) 164 164 var labelVals []string 165 165 var blobs []lexutil.Blob ··· 223 223 224 224 log.Infof("will process %d blobs", len(blobs)) 225 225 for _, blob := range blobs { 226 - if blob.Cid == "" { 226 + if blob.Ref == cid.Undef { 227 227 return nil, fmt.Errorf("received stub blob (CID undefined)") 228 228 } 229 229 230 230 if !s.wantBlob(ctx, &blob) { 231 - log.Infof("skipping blob: cid=%s", blob.Cid) 231 + log.Infof("skipping blob: cid=%s", blob.Ref.String()) 232 232 continue 233 233 } 234 234 // download image for process ··· 251 251 func (s *Server) downloadRepoBlob(ctx context.Context, did string, blob *lexutil.Blob) ([]byte, error) { 252 252 var blobBytes []byte 253 253 254 - if blob.Cid == "" { 254 + if blob.Ref == cid.Undef { 255 255 return nil, fmt.Errorf("invalid blob to download (CID undefined)") 256 256 } 257 257 258 - log.Infof("downloading blob pds=%s did=%s cid=%s", s.blobPdsURL, did, blob.Cid) 258 + log.Infof("downloading blob pds=%s did=%s cid=%s", s.blobPdsURL, did, blob.Ref.String()) 259 259 260 260 // TODO(bnewbold): more robust blob fetch code, by constructing query param 261 261 // properly; looking up DID doc; using xrpc.Client (with persistend HTTP 262 262 // client); etc. 263 263 // blocked on getBlob atproto branch landing, with new Lexicon. 264 264 // for now, just fetching from configured PDS (aka our single PDS) 265 - xrpcURL := fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", s.blobPdsURL, did, blob.Cid) 265 + xrpcURL := fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", s.blobPdsURL, did, blob.Ref.String()) 266 266 267 267 resp, err := http.Get(xrpcURL) 268 268 if err != nil { ··· 271 271 defer resp.Body.Close() 272 272 273 273 if resp.StatusCode != 200 { 274 - return nil, fmt.Errorf("failed to fetch blob from PDS. did=%s cid=%s statusCode=%d", did, blob.Cid, resp.StatusCode) 274 + return nil, fmt.Errorf("failed to fetch blob from PDS. did=%s cid=%s statusCode=%d", did, blob.Ref.String(), resp.StatusCode) 275 275 } 276 276 277 277 blobBytes, err = io.ReadAll(resp.Body) ··· 286 286 287 287 var labelVals []string 288 288 289 - if blob.Cid == "" { 289 + if blob.Ref == cid.Undef { 290 290 return nil, fmt.Errorf("invalid blob to label (CID undefined)") 291 291 } 292 292
+57 -14
lex/util/cbor_gen.go
··· 121 121 122 122 cw := cbg.NewCborWriter(w) 123 123 124 - if _, err := cw.Write([]byte{162}); err != nil { 124 + if _, err := cw.Write([]byte{163}); err != nil { 125 125 return err 126 126 } 127 127 128 - // t.Cid (string) (string) 129 - if len("cid") > cbg.MaxLength { 130 - return xerrors.Errorf("Value in field \"cid\" was too long") 128 + // t.Ref (cid.Cid) (struct) 129 + if len("ref") > cbg.MaxLength { 130 + return xerrors.Errorf("Value in field \"ref\" was too long") 131 131 } 132 132 133 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("cid"))); err != nil { 133 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ref"))); err != nil { 134 134 return err 135 135 } 136 - if _, err := io.WriteString(w, string("cid")); err != nil { 136 + if _, err := io.WriteString(w, string("ref")); err != nil { 137 137 return err 138 138 } 139 139 140 - if len(t.Cid) > cbg.MaxLength { 141 - return xerrors.Errorf("Value in field t.Cid was too long") 140 + if err := cbg.WriteCid(cw, t.Ref); err != nil { 141 + return xerrors.Errorf("failed to write cid field t.Ref: %w", err) 142 + } 143 + 144 + // t.Size (int64) (int64) 145 + if len("size") > cbg.MaxLength { 146 + return xerrors.Errorf("Value in field \"size\" was too long") 142 147 } 143 148 144 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Cid))); err != nil { 149 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("size"))); err != nil { 145 150 return err 146 151 } 147 - if _, err := io.WriteString(w, string(t.Cid)); err != nil { 152 + if _, err := io.WriteString(w, string("size")); err != nil { 148 153 return err 154 + } 155 + 156 + if t.Size >= 0 { 157 + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Size)); err != nil { 158 + return err 159 + } 160 + } else { 161 + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Size-1)); err != nil { 162 + return err 163 + } 149 164 } 150 165 151 166 // t.MimeType (string) (string) ··· 211 226 } 212 227 213 228 switch name { 214 - // t.Cid (string) (string) 215 - case "cid": 229 + // t.Ref (cid.Cid) (struct) 230 + case "ref": 216 231 217 232 { 218 - sval, err := cbg.ReadString(cr) 233 + 234 + c, err := cbg.ReadCid(cr) 235 + if err != nil { 236 + return xerrors.Errorf("failed to read cid field t.Ref: %w", err) 237 + } 238 + 239 + t.Ref = c 240 + 241 + } 242 + // t.Size (int64) (int64) 243 + case "size": 244 + { 245 + maj, extra, err := cr.ReadHeader() 246 + var extraI int64 219 247 if err != nil { 220 248 return err 221 249 } 250 + switch maj { 251 + case cbg.MajUnsignedInt: 252 + extraI = int64(extra) 253 + if extraI < 0 { 254 + return fmt.Errorf("int64 positive overflow") 255 + } 256 + case cbg.MajNegativeInt: 257 + extraI = int64(extra) 258 + if extraI < 0 { 259 + return fmt.Errorf("int64 negative overflow") 260 + } 261 + extraI = -1 - extraI 262 + default: 263 + return fmt.Errorf("wrong type for int64 field: %d", maj) 264 + } 222 265 223 - t.Cid = string(sval) 266 + t.Size = int64(extraI) 224 267 } 225 268 // t.MimeType (string) (string) 226 269 case "mimeType":
+5 -2
lex/util/util.go
··· 5 5 "encoding/json" 6 6 "fmt" 7 7 "io" 8 + 9 + "github.com/ipfs/go-cid" 8 10 ) 9 11 10 12 type typeExtractor struct { ··· 21 23 } 22 24 23 25 type Blob struct { 24 - Cid string `json:"cid" cborgen:"cid"` 25 - MimeType string `json:"mimeType" cborgen:"mimeType"` 26 + Ref cid.Cid `json:"ref" cborgen:"ref"` 27 + MimeType string `json:"mimeType" cborgen:"mimeType"` 28 + Size int64 `json:"size" cborgen:"size"` 26 29 } 27 30 28 31 type CborChecker struct {
+5 -4
testing/repo_slice_test.go
··· 9 9 10 10 appbsky "github.com/bluesky-social/indigo/api/bsky" 11 11 "github.com/bluesky-social/indigo/repo" 12 + "github.com/ipfs/go-cid" 12 13 ) 13 14 14 15 // ipfs dag import testing/repo_slice.car ··· 47 48 t.Fatal("didn't get expected Alt text") 48 49 } 49 50 50 - if img.Image.Cid == "" { 51 - t.Fatal("got nil Cid on image") 51 + if img.Image.Ref == cid.Undef { 52 + t.Fatal("got nil CID on image") 52 53 } 53 - if img.Image.Cid != "bafkreiblkobl6arfg3j7eft3akdhn2hmr2qmzfkefcgu4agnswvssg4a6a" { 54 - t.Fatal("didn't get expected image blob Cid") 54 + if img.Image.Ref.String() != "bafkreiblkobl6arfg3j7eft3akdhn2hmr2qmzfkefcgu4agnswvssg4a6a" { 55 + t.Fatal("didn't get expected image blob CID") 55 56 } 56 57 if img.Image.MimeType != "image/jpeg" { 57 58 t.Fatal("didn't get expected image blob mimetype")