Monorepo for Tangled tangled.org
2

Configure Feed

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

lexicons/string: use blob for string content

Signed-off-by: Seongmin Lee <git@boltless.me>

author
Seongmin Lee
date (Jun 16, 2026, 11:57 PM +0900) commit 8e9a5b4b parent 6b955521 change-id tywuzzoy
+656 -58
+580 -49
api/tangled/cbor_gen.go
··· 11324 11324 } 11325 11325 11326 11326 cw := cbg.NewCborWriter(w) 11327 + fieldCount := 7 11327 11328 11328 - if _, err := cw.Write([]byte{165}); err != nil { 11329 + if t.Contents == nil { 11330 + fieldCount-- 11331 + } 11332 + 11333 + if t.Description == nil { 11334 + fieldCount-- 11335 + } 11336 + 11337 + if t.Filename == nil { 11338 + fieldCount-- 11339 + } 11340 + 11341 + if t.Title == nil { 11342 + fieldCount-- 11343 + } 11344 + 11345 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 11329 11346 return err 11330 11347 } 11331 11348 ··· 11348 11365 return err 11349 11366 } 11350 11367 11351 - // t.Contents (string) (string) 11352 - if len("contents") > 1000000 { 11353 - return xerrors.Errorf("Value in field \"contents\" was too long") 11368 + // t.Files ([]*tangled.String_File) (slice) 11369 + if len("files") > 1000000 { 11370 + return xerrors.Errorf("Value in field \"files\" was too long") 11354 11371 } 11355 11372 11356 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("contents"))); err != nil { 11373 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("files"))); err != nil { 11357 11374 return err 11358 11375 } 11359 - if _, err := cw.WriteString(string("contents")); err != nil { 11376 + if _, err := cw.WriteString(string("files")); err != nil { 11360 11377 return err 11361 11378 } 11362 11379 11363 - if len(t.Contents) > 1000000 { 11364 - return xerrors.Errorf("Value in field t.Contents was too long") 11380 + if len(t.Files) > 8192 { 11381 + return xerrors.Errorf("Slice value in field t.Files was too long") 11365 11382 } 11366 11383 11367 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Contents))); err != nil { 11384 + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Files))); err != nil { 11368 11385 return err 11369 11386 } 11370 - if _, err := cw.WriteString(string(t.Contents)); err != nil { 11371 - return err 11387 + for _, v := range t.Files { 11388 + if err := v.MarshalCBOR(cw); err != nil { 11389 + return err 11390 + } 11391 + 11372 11392 } 11373 11393 11374 - // t.Filename (string) (string) 11375 - if len("filename") > 1000000 { 11376 - return xerrors.Errorf("Value in field \"filename\" was too long") 11377 - } 11394 + // t.Title (string) (string) 11395 + if t.Title != nil { 11378 11396 11379 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("filename"))); err != nil { 11380 - return err 11381 - } 11382 - if _, err := cw.WriteString(string("filename")); err != nil { 11383 - return err 11384 - } 11397 + if len("title") > 1000000 { 11398 + return xerrors.Errorf("Value in field \"title\" was too long") 11399 + } 11400 + 11401 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("title"))); err != nil { 11402 + return err 11403 + } 11404 + if _, err := cw.WriteString(string("title")); err != nil { 11405 + return err 11406 + } 11407 + 11408 + if t.Title == nil { 11409 + if _, err := cw.Write(cbg.CborNull); err != nil { 11410 + return err 11411 + } 11412 + } else { 11413 + if len(*t.Title) > 1000000 { 11414 + return xerrors.Errorf("Value in field t.Title was too long") 11415 + } 11385 11416 11386 - if len(t.Filename) > 1000000 { 11387 - return xerrors.Errorf("Value in field t.Filename was too long") 11417 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Title))); err != nil { 11418 + return err 11419 + } 11420 + if _, err := cw.WriteString(string(*t.Title)); err != nil { 11421 + return err 11422 + } 11423 + } 11388 11424 } 11389 11425 11390 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Filename))); err != nil { 11391 - return err 11426 + // t.Contents (string) (string) 11427 + if t.Contents != nil { 11428 + 11429 + if len("contents") > 1000000 { 11430 + return xerrors.Errorf("Value in field \"contents\" was too long") 11431 + } 11432 + 11433 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("contents"))); err != nil { 11434 + return err 11435 + } 11436 + if _, err := cw.WriteString(string("contents")); err != nil { 11437 + return err 11438 + } 11439 + 11440 + if t.Contents == nil { 11441 + if _, err := cw.Write(cbg.CborNull); err != nil { 11442 + return err 11443 + } 11444 + } else { 11445 + if len(*t.Contents) > 1000000 { 11446 + return xerrors.Errorf("Value in field t.Contents was too long") 11447 + } 11448 + 11449 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Contents))); err != nil { 11450 + return err 11451 + } 11452 + if _, err := cw.WriteString(string(*t.Contents)); err != nil { 11453 + return err 11454 + } 11455 + } 11392 11456 } 11393 - if _, err := cw.WriteString(string(t.Filename)); err != nil { 11394 - return err 11457 + 11458 + // t.Filename (string) (string) 11459 + if t.Filename != nil { 11460 + 11461 + if len("filename") > 1000000 { 11462 + return xerrors.Errorf("Value in field \"filename\" was too long") 11463 + } 11464 + 11465 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("filename"))); err != nil { 11466 + return err 11467 + } 11468 + if _, err := cw.WriteString(string("filename")); err != nil { 11469 + return err 11470 + } 11471 + 11472 + if t.Filename == nil { 11473 + if _, err := cw.Write(cbg.CborNull); err != nil { 11474 + return err 11475 + } 11476 + } else { 11477 + if len(*t.Filename) > 1000000 { 11478 + return xerrors.Errorf("Value in field t.Filename was too long") 11479 + } 11480 + 11481 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Filename))); err != nil { 11482 + return err 11483 + } 11484 + if _, err := cw.WriteString(string(*t.Filename)); err != nil { 11485 + return err 11486 + } 11487 + } 11395 11488 } 11396 11489 11397 11490 // t.CreatedAt (string) (string) ··· 11418 11511 } 11419 11512 11420 11513 // t.Description (string) (string) 11421 - if len("description") > 1000000 { 11422 - return xerrors.Errorf("Value in field \"description\" was too long") 11423 - } 11514 + if t.Description != nil { 11515 + 11516 + if len("description") > 1000000 { 11517 + return xerrors.Errorf("Value in field \"description\" was too long") 11518 + } 11424 11519 11425 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { 11426 - return err 11427 - } 11428 - if _, err := cw.WriteString(string("description")); err != nil { 11429 - return err 11430 - } 11520 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { 11521 + return err 11522 + } 11523 + if _, err := cw.WriteString(string("description")); err != nil { 11524 + return err 11525 + } 11431 11526 11432 - if len(t.Description) > 1000000 { 11433 - return xerrors.Errorf("Value in field t.Description was too long") 11434 - } 11527 + if t.Description == nil { 11528 + if _, err := cw.Write(cbg.CborNull); err != nil { 11529 + return err 11530 + } 11531 + } else { 11532 + if len(*t.Description) > 1000000 { 11533 + return xerrors.Errorf("Value in field t.Description was too long") 11534 + } 11435 11535 11436 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Description))); err != nil { 11437 - return err 11438 - } 11439 - if _, err := cw.WriteString(string(t.Description)); err != nil { 11440 - return err 11536 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Description))); err != nil { 11537 + return err 11538 + } 11539 + if _, err := cw.WriteString(string(*t.Description)); err != nil { 11540 + return err 11541 + } 11542 + } 11441 11543 } 11442 11544 return nil 11443 11545 } ··· 11494 11596 11495 11597 t.LexiconTypeID = string(sval) 11496 11598 } 11599 + // t.Files ([]*tangled.String_File) (slice) 11600 + case "files": 11601 + 11602 + maj, extra, err = cr.ReadHeader() 11603 + if err != nil { 11604 + return err 11605 + } 11606 + 11607 + if extra > 8192 { 11608 + return fmt.Errorf("t.Files: array too large (%d)", extra) 11609 + } 11610 + 11611 + if maj != cbg.MajArray { 11612 + return fmt.Errorf("expected cbor array") 11613 + } 11614 + 11615 + if extra > 0 { 11616 + t.Files = make([]*String_File, extra) 11617 + } 11618 + 11619 + for i := 0; i < int(extra); i++ { 11620 + { 11621 + var maj byte 11622 + var extra uint64 11623 + var err error 11624 + _ = maj 11625 + _ = extra 11626 + _ = err 11627 + 11628 + { 11629 + 11630 + b, err := cr.ReadByte() 11631 + if err != nil { 11632 + return err 11633 + } 11634 + if b != cbg.CborNull[0] { 11635 + if err := cr.UnreadByte(); err != nil { 11636 + return err 11637 + } 11638 + t.Files[i] = new(String_File) 11639 + if err := t.Files[i].UnmarshalCBOR(cr); err != nil { 11640 + return xerrors.Errorf("unmarshaling t.Files[i] pointer: %w", err) 11641 + } 11642 + } 11643 + 11644 + } 11645 + 11646 + } 11647 + } 11648 + // t.Title (string) (string) 11649 + case "title": 11650 + 11651 + { 11652 + b, err := cr.ReadByte() 11653 + if err != nil { 11654 + return err 11655 + } 11656 + if b != cbg.CborNull[0] { 11657 + if err := cr.UnreadByte(); err != nil { 11658 + return err 11659 + } 11660 + 11661 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 11662 + if err != nil { 11663 + return err 11664 + } 11665 + 11666 + t.Title = (*string)(&sval) 11667 + } 11668 + } 11497 11669 // t.Contents (string) (string) 11498 11670 case "contents": 11499 11671 11500 11672 { 11501 - sval, err := cbg.ReadStringWithMax(cr, 1000000) 11673 + b, err := cr.ReadByte() 11502 11674 if err != nil { 11503 11675 return err 11504 11676 } 11677 + if b != cbg.CborNull[0] { 11678 + if err := cr.UnreadByte(); err != nil { 11679 + return err 11680 + } 11505 11681 11506 - t.Contents = string(sval) 11682 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 11683 + if err != nil { 11684 + return err 11685 + } 11686 + 11687 + t.Contents = (*string)(&sval) 11688 + } 11507 11689 } 11508 11690 // t.Filename (string) (string) 11509 11691 case "filename": 11510 11692 11511 11693 { 11512 - sval, err := cbg.ReadStringWithMax(cr, 1000000) 11694 + b, err := cr.ReadByte() 11513 11695 if err != nil { 11514 11696 return err 11515 11697 } 11698 + if b != cbg.CborNull[0] { 11699 + if err := cr.UnreadByte(); err != nil { 11700 + return err 11701 + } 11516 11702 11517 - t.Filename = string(sval) 11703 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 11704 + if err != nil { 11705 + return err 11706 + } 11707 + 11708 + t.Filename = (*string)(&sval) 11709 + } 11518 11710 } 11519 11711 // t.CreatedAt (string) (string) 11520 11712 case "createdAt": ··· 11531 11723 case "description": 11532 11724 11533 11725 { 11726 + b, err := cr.ReadByte() 11727 + if err != nil { 11728 + return err 11729 + } 11730 + if b != cbg.CborNull[0] { 11731 + if err := cr.UnreadByte(); err != nil { 11732 + return err 11733 + } 11734 + 11735 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 11736 + if err != nil { 11737 + return err 11738 + } 11739 + 11740 + t.Description = (*string)(&sval) 11741 + } 11742 + } 11743 + 11744 + default: 11745 + // Field doesn't exist on this type, so ignore it 11746 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 11747 + return err 11748 + } 11749 + } 11750 + } 11751 + 11752 + return nil 11753 + } 11754 + func (t *String_File) MarshalCBOR(w io.Writer) error { 11755 + if t == nil { 11756 + _, err := w.Write(cbg.CborNull) 11757 + return err 11758 + } 11759 + 11760 + cw := cbg.NewCborWriter(w) 11761 + fieldCount := 3 11762 + 11763 + if t.Gzip == nil { 11764 + fieldCount-- 11765 + } 11766 + 11767 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 11768 + return err 11769 + } 11770 + 11771 + // t.Gzip (tangled.String_File_Gzip) (struct) 11772 + if t.Gzip != nil { 11773 + 11774 + if len("gzip") > 1000000 { 11775 + return xerrors.Errorf("Value in field \"gzip\" was too long") 11776 + } 11777 + 11778 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("gzip"))); err != nil { 11779 + return err 11780 + } 11781 + if _, err := cw.WriteString(string("gzip")); err != nil { 11782 + return err 11783 + } 11784 + 11785 + if err := t.Gzip.MarshalCBOR(cw); err != nil { 11786 + return err 11787 + } 11788 + } 11789 + 11790 + // t.Name (string) (string) 11791 + if len("name") > 1000000 { 11792 + return xerrors.Errorf("Value in field \"name\" was too long") 11793 + } 11794 + 11795 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("name"))); err != nil { 11796 + return err 11797 + } 11798 + if _, err := cw.WriteString(string("name")); err != nil { 11799 + return err 11800 + } 11801 + 11802 + if len(t.Name) > 1000000 { 11803 + return xerrors.Errorf("Value in field t.Name was too long") 11804 + } 11805 + 11806 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Name))); err != nil { 11807 + return err 11808 + } 11809 + if _, err := cw.WriteString(string(t.Name)); err != nil { 11810 + return err 11811 + } 11812 + 11813 + // t.Content (util.LexBlob) (struct) 11814 + if len("content") > 1000000 { 11815 + return xerrors.Errorf("Value in field \"content\" was too long") 11816 + } 11817 + 11818 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("content"))); err != nil { 11819 + return err 11820 + } 11821 + if _, err := cw.WriteString(string("content")); err != nil { 11822 + return err 11823 + } 11824 + 11825 + if err := t.Content.MarshalCBOR(cw); err != nil { 11826 + return err 11827 + } 11828 + return nil 11829 + } 11830 + 11831 + func (t *String_File) UnmarshalCBOR(r io.Reader) (err error) { 11832 + *t = String_File{} 11833 + 11834 + cr := cbg.NewCborReader(r) 11835 + 11836 + maj, extra, err := cr.ReadHeader() 11837 + if err != nil { 11838 + return err 11839 + } 11840 + defer func() { 11841 + if err == io.EOF { 11842 + err = io.ErrUnexpectedEOF 11843 + } 11844 + }() 11845 + 11846 + if maj != cbg.MajMap { 11847 + return fmt.Errorf("cbor input should be of type map") 11848 + } 11849 + 11850 + if extra > cbg.MaxLength { 11851 + return fmt.Errorf("String_File: map struct too large (%d)", extra) 11852 + } 11853 + 11854 + n := extra 11855 + 11856 + nameBuf := make([]byte, 7) 11857 + for i := uint64(0); i < n; i++ { 11858 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) 11859 + if err != nil { 11860 + return err 11861 + } 11862 + 11863 + if !ok { 11864 + // Field doesn't exist on this type, so ignore it 11865 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 11866 + return err 11867 + } 11868 + continue 11869 + } 11870 + 11871 + switch string(nameBuf[:nameLen]) { 11872 + // t.Gzip (tangled.String_File_Gzip) (struct) 11873 + case "gzip": 11874 + 11875 + { 11876 + 11877 + b, err := cr.ReadByte() 11878 + if err != nil { 11879 + return err 11880 + } 11881 + if b != cbg.CborNull[0] { 11882 + if err := cr.UnreadByte(); err != nil { 11883 + return err 11884 + } 11885 + t.Gzip = new(String_File_Gzip) 11886 + if err := t.Gzip.UnmarshalCBOR(cr); err != nil { 11887 + return xerrors.Errorf("unmarshaling t.Gzip pointer: %w", err) 11888 + } 11889 + } 11890 + 11891 + } 11892 + // t.Name (string) (string) 11893 + case "name": 11894 + 11895 + { 11534 11896 sval, err := cbg.ReadStringWithMax(cr, 1000000) 11535 11897 if err != nil { 11536 11898 return err 11537 11899 } 11538 11900 11539 - t.Description = string(sval) 11901 + t.Name = string(sval) 11902 + } 11903 + // t.Content (util.LexBlob) (struct) 11904 + case "content": 11905 + 11906 + { 11907 + 11908 + b, err := cr.ReadByte() 11909 + if err != nil { 11910 + return err 11911 + } 11912 + if b != cbg.CborNull[0] { 11913 + if err := cr.UnreadByte(); err != nil { 11914 + return err 11915 + } 11916 + t.Content = new(util.LexBlob) 11917 + if err := t.Content.UnmarshalCBOR(cr); err != nil { 11918 + return xerrors.Errorf("unmarshaling t.Content pointer: %w", err) 11919 + } 11920 + } 11921 + 11922 + } 11923 + 11924 + default: 11925 + // Field doesn't exist on this type, so ignore it 11926 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 11927 + return err 11928 + } 11929 + } 11930 + } 11931 + 11932 + return nil 11933 + } 11934 + func (t *String_File_Gzip) MarshalCBOR(w io.Writer) error { 11935 + if t == nil { 11936 + _, err := w.Write(cbg.CborNull) 11937 + return err 11938 + } 11939 + 11940 + cw := cbg.NewCborWriter(w) 11941 + 11942 + if _, err := cw.Write([]byte{162}); err != nil { 11943 + return err 11944 + } 11945 + 11946 + // t.RealMime (string) (string) 11947 + if len("realMime") > 1000000 { 11948 + return xerrors.Errorf("Value in field \"realMime\" was too long") 11949 + } 11950 + 11951 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("realMime"))); err != nil { 11952 + return err 11953 + } 11954 + if _, err := cw.WriteString(string("realMime")); err != nil { 11955 + return err 11956 + } 11957 + 11958 + if len(t.RealMime) > 1000000 { 11959 + return xerrors.Errorf("Value in field t.RealMime was too long") 11960 + } 11961 + 11962 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.RealMime))); err != nil { 11963 + return err 11964 + } 11965 + if _, err := cw.WriteString(string(t.RealMime)); err != nil { 11966 + return err 11967 + } 11968 + 11969 + // t.RealSize (int64) (int64) 11970 + if len("realSize") > 1000000 { 11971 + return xerrors.Errorf("Value in field \"realSize\" was too long") 11972 + } 11973 + 11974 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("realSize"))); err != nil { 11975 + return err 11976 + } 11977 + if _, err := cw.WriteString(string("realSize")); err != nil { 11978 + return err 11979 + } 11980 + 11981 + if t.RealSize >= 0 { 11982 + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.RealSize)); err != nil { 11983 + return err 11984 + } 11985 + } else { 11986 + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.RealSize-1)); err != nil { 11987 + return err 11988 + } 11989 + } 11990 + 11991 + return nil 11992 + } 11993 + 11994 + func (t *String_File_Gzip) UnmarshalCBOR(r io.Reader) (err error) { 11995 + *t = String_File_Gzip{} 11996 + 11997 + cr := cbg.NewCborReader(r) 11998 + 11999 + maj, extra, err := cr.ReadHeader() 12000 + if err != nil { 12001 + return err 12002 + } 12003 + defer func() { 12004 + if err == io.EOF { 12005 + err = io.ErrUnexpectedEOF 12006 + } 12007 + }() 12008 + 12009 + if maj != cbg.MajMap { 12010 + return fmt.Errorf("cbor input should be of type map") 12011 + } 12012 + 12013 + if extra > cbg.MaxLength { 12014 + return fmt.Errorf("String_File_Gzip: map struct too large (%d)", extra) 12015 + } 12016 + 12017 + n := extra 12018 + 12019 + nameBuf := make([]byte, 8) 12020 + for i := uint64(0); i < n; i++ { 12021 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) 12022 + if err != nil { 12023 + return err 12024 + } 12025 + 12026 + if !ok { 12027 + // Field doesn't exist on this type, so ignore it 12028 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 12029 + return err 12030 + } 12031 + continue 12032 + } 12033 + 12034 + switch string(nameBuf[:nameLen]) { 12035 + // t.RealMime (string) (string) 12036 + case "realMime": 12037 + 12038 + { 12039 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 12040 + if err != nil { 12041 + return err 12042 + } 12043 + 12044 + t.RealMime = string(sval) 12045 + } 12046 + // t.RealSize (int64) (int64) 12047 + case "realSize": 12048 + { 12049 + maj, extra, err := cr.ReadHeader() 12050 + if err != nil { 12051 + return err 12052 + } 12053 + var extraI int64 12054 + switch maj { 12055 + case cbg.MajUnsignedInt: 12056 + extraI = int64(extra) 12057 + if extraI < 0 { 12058 + return fmt.Errorf("int64 positive overflow") 12059 + } 12060 + case cbg.MajNegativeInt: 12061 + extraI = int64(extra) 12062 + if extraI < 0 { 12063 + return fmt.Errorf("int64 negative overflow") 12064 + } 12065 + extraI = -1 - extraI 12066 + default: 12067 + return fmt.Errorf("wrong type for int64 field: %d", maj) 12068 + } 12069 + 12070 + t.RealSize = int64(extraI) 11540 12071 } 11541 12072 11542 12073 default:
+24 -4
api/tangled/tangledstring.go
··· 18 18 // RECORDTYPE: String 19 19 type String struct { 20 20 LexiconTypeID string `json:"$type,const=sh.tangled.string" cborgen:"$type,const=sh.tangled.string"` 21 - Contents string `json:"contents" cborgen:"contents"` 22 - CreatedAt string `json:"createdAt" cborgen:"createdAt"` 23 - Description string `json:"description" cborgen:"description"` 24 - Filename string `json:"filename" cborgen:"filename"` 21 + // contents: DEPRECATED - use files[0].content instead 22 + Contents *string `json:"contents,omitempty" cborgen:"contents,omitempty"` 23 + CreatedAt string `json:"createdAt" cborgen:"createdAt"` 24 + Description *string `json:"description,omitempty" cborgen:"description,omitempty"` 25 + // filename: DEPRECATED - use title instead 26 + Filename *string `json:"filename,omitempty" cborgen:"filename,omitempty"` 27 + Files []*String_File `json:"files" cborgen:"files"` 28 + Title *string `json:"title,omitempty" cborgen:"title,omitempty"` 29 + } 30 + 31 + // String_File is a "file" in the sh.tangled.string schema. 32 + type String_File struct { 33 + // content: file content 34 + Content *util.LexBlob `json:"content" cborgen:"content"` 35 + // gzip: underlying blob metadata. provided when we are using gzip hack for text/* mimetype 36 + Gzip *String_File_Gzip `json:"gzip,omitempty" cborgen:"gzip,omitempty"` 37 + // name: filename including extension 38 + Name string `json:"name" cborgen:"name"` 39 + } 40 + 41 + // underlying blob metadata. provided when we are using gzip hack for text/* mimetype 42 + type String_File_Gzip struct { 43 + RealMime string `json:"realMime" cborgen:"realMime"` 44 + RealSize int64 `json:"realSize" cborgen:"realSize"` 25 45 }
+2
cmd/cborgen/cborgen.go
··· 61 61 tangled.Spindle{}, 62 62 tangled.SpindleMember{}, 63 63 tangled.String{}, 64 + tangled.String_File{}, 65 + tangled.String_File_Gzip{}, 64 66 ); err != nil { 65 67 panic(err) 66 68 }
+50 -5
lexicons/string/string.json
··· 10 10 "record": { 11 11 "type": "object", 12 12 "required": [ 13 - "filename", 14 - "description", 15 13 "createdAt", 16 - "contents" 14 + "files" 17 15 ], 18 16 "properties": { 19 17 "filename": { 20 18 "type": "string", 21 19 "maxGraphemes": 140, 20 + "minGraphemes": 1, 21 + "description": "DEPRECATED - use title instead" 22 + }, 23 + "title": { 24 + "type": "string", 25 + "maxGraphemes": 140, 22 26 "minGraphemes": 1 23 27 }, 24 28 "description": { 25 29 "type": "string", 26 - "maxGraphemes": 280 30 + "maxGraphemes": 280, 31 + "minGraphemes": 1 27 32 }, 28 33 "createdAt": { 29 34 "type": "string", ··· 31 36 }, 32 37 "contents": { 33 38 "type": "string", 34 - "minGraphemes": 1 39 + "minGraphemes": 1, 40 + "description": "DEPRECATED - use files[0].content instead" 41 + }, 42 + "files": { 43 + "type": "array", 44 + "minLength": 1, 45 + "maxLength": 50, 46 + "items": { 47 + "type": "ref", 48 + "ref": "#file" 49 + } 35 50 } 51 + } 52 + } 53 + }, 54 + "file": { 55 + "type": "object", 56 + "required": [ 57 + "name", 58 + "content" 59 + ], 60 + "properties": { 61 + "name": { 62 + "type": "string", 63 + "maxGraphemes": 140, 64 + "minGraphemes": 1, 65 + "description": "filename including extension" 66 + }, 67 + "content": { 68 + "type": "blob", 69 + "accept": ["text/plain", "application/gzip"], 70 + "maxSize": 8388608, 71 + "description": "file content" 72 + }, 73 + "gzip": { 74 + "type": "object", 75 + "required": ["realSize", "realMime"], 76 + "properties": { 77 + "realSize": { "type": "integer" }, 78 + "realMime": { "type": "string" } 79 + }, 80 + "description": "underlying blob metadata. provided when we are using gzip hack for text/* mimetype" 36 81 } 37 82 } 38 83 }